MCPcopy
hub / github.com/colinhacks/zod / detectVersion

Function detectVersion

packages/zod/src/v4/classic/from-json-schema.ts:104–119  ·  view source on GitHub ↗
(schema: JSONSchema.JSONSchema, defaultTarget?: JSONSchemaVersion)

Source from the content-addressed store, hash-verified

102]);
103
104function detectVersion(schema: JSONSchema.JSONSchema, defaultTarget?: JSONSchemaVersion): JSONSchemaVersion {
105 const $schema = schema.$schema;
106
107 if ($schema === "https://json-schema.org/draft/2020-12/schema") {
108 return "draft-2020-12";
109 }
110 if ($schema === "http://json-schema.org/draft-07/schema#") {
111 return "draft-7";
112 }
113 if ($schema === "http://json-schema.org/draft-04/schema#") {
114 return "draft-4";
115 }
116
117 // Use defaultTarget if provided, otherwise default to draft-2020-12
118 return defaultTarget ?? "draft-2020-12";
119}
120
121function resolveRef(ref: string, ctx: ConversionContext): JSONSchema.JSONSchema {
122 if (!ref.startsWith("#")) {

Callers 1

fromJSONSchemaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected