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

48 lines 1.17 kB
export class AtomicSchemaObject { } export function isAtomicSchema(schema) { return typeof schema === 'boolean' || schema instanceof AtomicSchemaObject; } export function isLogicLiteral(schema) { return (isAtomicSchema(schema) || (schema instanceof NotSchema && isAtomicSchema(schema.not))); } export function toJSONSchema(schema) { if (typeof schema === 'boolean') return schema; return schema.toJSONSchema(); } export function negateAtomicSchema(schema) { if (typeof schema === 'boolean') { return !schema; } return schema.negate(); } export class NotSchema { not; constructor(not) { this.not = not; } toJSONSchema() { return { not: toJSONSchema(this.not) }; } } export class AllOfSchema { allOf; constructor(allOf) { this.allOf = [...allOf]; } toJSONSchema() { return { allOf: this.allOf.map(toJSONSchema) }; } } export class AnyOfSchema { anyOf; constructor(anyOf) { this.anyOf = [...anyOf]; } toJSONSchema() { return { anyOf: this.anyOf.map(toJSONSchema) }; } } //# sourceMappingURL=atomic-schema.js.map