StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
917 stars 76 forks source link

Add json schema readonly attribute #148

Open hpgmiskin opened 3 weeks ago

hpgmiskin commented 3 weeks ago

I would like to include the readOnly attribute. I know this is a pretty rudimentary set of changes but please let me know what extra tests are needed in order to get integrated?

Here are some details about the readOnly attribute:

https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-02#section-9.4

Here is a discussion about uses of read only:

https://stackoverflow.com/questions/60840385/are-there-more-examples-of-readonly-being-used-at-several-levels-of-a-schema-to

StefanTerdell commented 3 weeks ago
  1. Please remove the formatting changes. Not only do they make the pull-request difficult to review, but I have also kept the standard formatting rules for the purpose of avoiding bike-shedding.
  2. If the keyword should be added at all it should be by the Readonly parser. I have kept it out due to difficulty in knowing how the schema is being used (input vs output) but I'm open to adding an optional flag to enable it. It should not be a separate argument to the main function however, but as part of the refs object.