zod icon indicating copy to clipboard operation
zod copied to clipboard

Incorrect default $schema identifier for JSON Schema draft-07

Open jeremyfiel opened this issue 11 months ago • 5 comments

This was clarified in the linked issue by @relequestual

https://github.com/colinhacks/zod/blob/2381dafe7bb47a0354881567c8d8fbeb493e031f/packages/zod/src/v4/core/to-json-schema.ts#L725

https://github.com/microsoft/vscode-json-languageservice/issues/194

related #4390

jeremyfiel avatar May 19 '25 15:05 jeremyfiel

Sorry, but what should it actually be?

colinhacks avatar May 19 '25 15:05 colinhacks

including the hash

http://json-schema.org/draft-07/schema#

jeremyfiel avatar May 19 '25 15:05 jeremyfiel

Damn, I missed that. Thank you good sir @jeremyfiel!

Relequestual avatar May 20 '25 08:05 Relequestual

+ for some reason, the schema url uses https (when I tested in fastify, it doesn't work), it is incorrect as it doesn't match with ajv : https://github.com/colinhacks/zod/blob/e7f75d69389fa308ea49177dc53a4913fefe75d3/packages/zod/src/v4/core/to-json-schema.ts#L725

see https://stackoverflow.com/a/71943876/18644204, https://github.com/ajv-validator/ajv/issues/1104 and especially https://github.com/ajv-validator/ajv/issues/1966#issuecomment-1108485711

EDM115 avatar May 20 '25 13:05 EDM115

@colinhacks seems you updated the uri yesterday, but it's not matching the correct value I indicated above.

no https and the hash is missing.

it should be http://json-schema.org/draft-07/schema#

jeremyfiel avatar May 20 '25 14:05 jeremyfiel

also @colinhacks (sorry for the ping), https://zod.dev/json-schema?id=configuration#configuration here both targets are marked as default in the docs, while from what I understand it's draft-2020-12 which is the real default

EDM115 avatar May 21 '25 07:05 EDM115

The $schema for draft-2020-12 is also incorrect. The correct value is: https://json-schema.org/draft/2020-12/schema.

rktyt avatar May 22 '25 04:05 rktyt