vitalics / ajv-ts

First-class ajv typescript JSON-schema builder inspired from Zod
https://www.npmjs.com/package/ajv-ts
MIT License
39 stars 1 forks source link

[Deep] Parse JSON Schema to Builder/s to facilitate a hybrid approach to composition in Typescript #52

Closed lburgess closed 5 months ago

lburgess commented 5 months ago

Is your feature request related to a problem? Please describe. Being able to use an existing JSON schema is certainly useful, however it does not appear that it is possible further modify the schema using the builder pattern. Both approaches are really useful independently, but would be so much more beneficial to a host of use cases which I have if it were possible to combine them.

Describe the solution you'd like I would like to be able to write something along the lines of:

const composedSchema = s.jsonSchema(PERSON_JSON_SCHEMA) .omit({ middleNames: true }) .extend({ nameOfFavouriteShop: s.string(), addressOfFavouriteShop: s.jsonSchema(ADDRESS_JSON_SCHEMA), }) .requiredFor('nameOfFavouriteShop');

Describe alternatives you've considered Composing derived JSON schemas on using pure JSON and then setting the ObjectBuilder schema to this new JSON schema. It arguably has greater utility since it is library/framework agnostic, but it somewhat undermines the point of using a library such as ajv-ts to create a better, more guided developer experience through [strongly-typed] Typescript.

Additional context I am using fragments of JSON schema derived from Open API specifications and re-hashing them for use in HTML forms which are validated using AJV.

vitalics commented 5 months ago

Hi @lburgess. Thanks for the issue. Have you tried the solution described in readme file?

vitalics commented 5 months ago

close the issue due to unactivity