json-schema-describes-subset
Version:
Tools for static JSON schema analysis, including functions to determine if one schema describes a subset of another or if a schema describes the empty set or to convert a schema to its disjunctive normal form (DNF).
27 lines • 848 B
JavaScript
import { AllOfSchema } from '../atomic-schema.js';
import { toRawDNF } from '../to-raw-dnf/index.js';
/**
* Converts the provided schema to an `allOf`-schema containing only logical
* combinations of atomic subschemas.
*
*/
export function split({ schema, options, }) {
if (typeof schema === 'boolean') {
return schema;
}
const extractionArguments = {
schema,
split: (schema) => split({ schema, options }),
};
const subschemas = options.plugins.extractions
.map(({ extract }) => extract(extractionArguments))
.filter((schema) => schema !== true);
if (subschemas.length === 0) {
return true;
}
return new AllOfSchema(subschemas);
}
export function splitToRawDNF(schema, options) {
return toRawDNF(split({ schema, options }));
}
//# sourceMappingURL=split.js.map