json-schema-to-zod
Version:
Converts JSON schema objects or files into Zod schemas
539 lines (538 loc) • 22.6 kB
TypeScript
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?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
type: "object";
};
array: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
type: "array";
};
anyOf: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
anyOf: JsonSchema[];
};
allOf: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
allOf: JsonSchema[];
};
enum: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
enum: Serializable | Serializable[];
};
};
a: {
nullable: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
nullable: true;
};
multipleType: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
type: string[];
};
not: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
not: JsonSchema;
};
const: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
const: Serializable;
};
primitive: <T extends "string" | "number" | "boolean" | "null" | "integer">(x: JsonSchemaObject, p: T) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
type: T;
};
conditional: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
if: JsonSchema;
then: JsonSchema;
else: JsonSchema;
};
oneOf: (x: JsonSchemaObject) => x is {
type?: string | string[] | undefined;
properties?: {
[ ]: JsonSchema;
} | undefined;
additionalProperties?: JsonSchema | undefined;
unevaluatedProperties?: JsonSchema | undefined;
patternProperties?: {
[ ]: 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?: {
[ ]: string | undefined;
} | undefined;
} & {
[ ]: any;
} & {
oneOf: JsonSchema[];
};
};
};