import { ZodSchema } from "zod" ; import { JsonSchema7Type , parseDef } from "./parseDef" ; import { $refStrategy , EffectStrategy , Target , References } from "./References" ; const $schema = "http://json-schema.org/draft-07/schema#" ; param schema param name function zodToJsonSchema < Name extends string | undefined = undefined > ( schema , name ? ) ; param schema param options param options . name param options . $refStrategy param options . basePath param options . effectStrategy param options . definitionPath param options . target function zodToJsonSchema < Name extends string | undefined = undefined , Strategy extends "root" | "relative" | "none" | undefined = undefined , BasePath extends string [ ] | undefined = undefined , DefinitionPath extends "definitions" | "$defs" = "definitions" , Target extends "jsonSchema7" | "openApi3" | undefined = undefined > ( schema , options ? ) ; function zodToJsonSchema ( schema , options ? ) { if ( typeof options === "object" ) { return options . name === undefined ? options . target === "openApi3" ? parseDef ( schema . _def , new References ( options . basePath ?? [ "#" ] , [ ] , options . $refStrategy ?? "root" , options . effectStrategy , options . target ) ) : { $schema , ... parseDef ( schema . _def , new References ( options . basePath ?? [ "#" ] , [ ] , options . $refStrategy ?? "root" , options . effectStrategy , options . target ) ) , } : options . target === "openApi3" ? { $ref : options . $refStrategy === "relative" ? `0/${ options . definitionPath ?? "definitions" }/${ options . name }` : `#/${ options . definitionPath ?? "definitions" }/${ options . name }` , [ options . definitionPath ?? "definitions" ] : { [ options . name ] : parseDef ( schema . _def , new References ( [ ... ( options . basePath ?? [ "#" ] ) , options . definitionPath ?? "definitions" , options . name , ] , [ ] , options . $refStrategy ?? "root" , options . effectStrategy , options . target ) ) || { } , } , } : { $schema , $ref : options . $refStrategy === "relative" ? `0/${ options . definitionPath ?? "definitions" }/${ options . name }` : `#/${ options . definitionPath ?? "definitions" }/${ options . name }` , [ options . definitionPath ?? "definitions" ] : { [ options . name ] : parseDef ( schema . _def , new References ( [ ... ( options . basePath ?? [ "#" ] ) , options . definitionPath ?? "definitions" , options . name , ] , [ ] , options . $refStrategy ?? "root" , options . effectStrategy , options . target ) ) || { } , } , } ; } else if ( typeof options === "string" ) { const name = options ; return { $schema , $ref : `#/definitions/${ name }` , definitions : { [ name ] : parseDef ( schema . _def , new References ( ) ) || { } , } , } ; } else { return { $schema , ... parseDef ( schema . _def , new References ( ) ) , } ; } } export { zodToJsonSchema } ;