UNPKG

json-schema-walker

Version:

A system that visits all schema objects in a JSON Schema document and makes callbacks before visiting all of the current schema object's subschemas.

42 lines (41 loc) 1.66 kB
import type { JSONSchema } from "@apidevtools/json-schema-ref-parser/dist/lib/types"; import type { ParserOptions } from "@apidevtools/json-schema-ref-parser/dist/lib/options"; export type InputSchema = JSONSchema; export type ProcessorFunction<T> = (schema: T) => void; export type ProcessorFunctionInternal = (schema: ISubSchema, keyword: string | number) => void; export type IVocabulary = Record<string, any>; export type ISubSchema = Record<string, any>; export interface Options { cloneSchema?: boolean; dereference?: boolean; dereferenceOptions?: ParserOptions | undefined; } export interface OptionsSync { cloneSchema?: boolean; } export declare class Walker<T extends InputSchema = InputSchema> { rootSchema: T; vocabulary: IVocabulary; vocabularies: Record<string, IVocabulary>; walker: ProcessorFunction<T>; private visitedSchemas; constructor(); loadSchema: (schema: T, options?: Options) => Promise<void>; loadSchemaSync: (schema: T, options?: OptionsSync) => void; walk: (processor: ProcessorFunction<T>, vocabulary: IVocabulary) => Promise<void>; walkSync: (processor: ProcessorFunction<T>, vocabulary: IVocabulary) => void; private isValidSubSchema; private applyUserProcessor; private subschemaWalk; private processSchemaKey; private processObjectOfSchemas; private processArrayOfSchemas; private processSingleOrArrayOfSchemas; private processSingleSchema; /** * Loop over the links and apply the callbacks, while * handling LDO keyword deletions by catching NEXT_LDO_KEYWORD. */ private getProcessLinks; private initVocabulary; }