UNPKG

json-schema-to-zod

Version:

Converts JSON schema objects or files into Zod schemas

539 lines (538 loc) 22.6 kB
import { Refs, JsonSchemaObject, JsonSchema, Serializable } from "../Types.js"; export declare const parseSchema: (schema: JsonSchema, refs?: Refs, blockMeta?: boolean) => string; export declare const its: { an: { object: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { type: "object"; }; array: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { type: "array"; }; anyOf: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { anyOf: JsonSchema[]; }; allOf: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { allOf: JsonSchema[]; }; enum: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { enum: Serializable | Serializable[]; }; }; a: { nullable: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { nullable: true; }; multipleType: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { type: string[]; }; not: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { not: JsonSchema; }; const: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { const: Serializable; }; primitive: <T extends "string" | "number" | "boolean" | "null" | "integer">(x: JsonSchemaObject, p: T) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { type: T; }; conditional: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { if: JsonSchema; then: JsonSchema; else: JsonSchema; }; oneOf: (x: JsonSchemaObject) => x is { type?: string | string[] | undefined; properties?: { [key: string]: JsonSchema; } | undefined; additionalProperties?: JsonSchema | undefined; unevaluatedProperties?: JsonSchema | undefined; patternProperties?: { [key: string]: JsonSchema; } | undefined; minProperties?: number | undefined; maxProperties?: number | undefined; required?: boolean | string[] | undefined; propertyNames?: JsonSchema | undefined; items?: JsonSchema | JsonSchema[] | undefined; additionalItems?: JsonSchema | undefined; minItems?: number | undefined; maxItems?: number | undefined; uniqueItems?: boolean | undefined; minLength?: number | undefined; maxLength?: number | undefined; pattern?: string | undefined; format?: string | undefined; minimum?: number | undefined; maximum?: number | undefined; exclusiveMinimum?: number | boolean | undefined; exclusiveMaximum?: number | boolean | undefined; multipleOf?: number | undefined; anyOf?: JsonSchema[] | undefined; allOf?: JsonSchema[] | undefined; oneOf?: JsonSchema[] | undefined; if?: JsonSchema | undefined; then?: JsonSchema | undefined; else?: JsonSchema | undefined; const?: Serializable | undefined; enum?: Serializable[] | undefined; errorMessage?: { [key: string]: string | undefined; } | undefined; } & { [key: string]: any; } & { oneOf: JsonSchema[]; }; }; };