unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
29 lines • 1.09 kB
JavaScript
// this function simplifies simple schemas and return allOf schema if it
// doesn't know how to simplify it. It's a proof of concept but it can be extended
export function mergeAllOf(a, b) {
if (typeof a !== 'boolean' && typeof b !== 'boolean') {
const { required: aRequired, properties: aProperties, type: aType, ...aRest } = a;
const { required: bRequired, properties: bProperties, type: bType, ...bRest } = b;
if (Object.keys(aRest).length === 0 &&
Object.keys(bRest).length === 0 &&
aType === 'object' &&
bType === 'object') {
return {
required: [...(aRequired ?? []), ...(bRequired ?? [])],
type: 'object',
properties: { ...aProperties, ...bProperties },
};
}
}
return {
allOf: [a, b],
};
}
export function mergeAllOfs(schemas) {
if (schemas.length === 1) {
return schemas[0];
}
const [a, b, ...rest] = schemas;
return mergeAllOfs([mergeAllOf(a, b), ...rest]);
}
//# sourceMappingURL=all-of.js.map