UNPKG

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).

18 lines 745 B
import { AllOfSchema, AnyOfSchema, NotSchema, } from '../atomic-schema/index.js'; import { isJSONSchema } from '../json-schema/index.js'; import { isArrayOf } from '../utils/type-guards/index.js'; export const oneOfExtraction = { extract: ({ schema: { oneOf }, split }) => { if (!isArrayOf(isJSONSchema)(oneOf)) return true; const anyOf = []; for (let i = 0; i < oneOf.length; i++) { anyOf.push(new AllOfSchema(oneOf.map((subschema, j) => { const atomicSubschema = split(subschema); return i === j ? atomicSubschema : new NotSchema(atomicSubschema); }))); } return new AnyOfSchema(anyOf); }, }; //# sourceMappingURL=one-of.js.map