ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.57k stars 868 forks source link

[Q] Recommendations for Converting JSON Schema to TS Types in Ajv? #2339

Closed toteto closed 3 weeks ago

toteto commented 9 months ago

How can I convert my predefined JSON Schema files into TS Types as a developer? I've looked into:

  1. json-schema-to-typescript
    • Pros: Overall good output.
    • Cons:
      • Produces empty interface for patternProperties.
      • Issues with duplicate type outputs and can't see all the schemas to minimize duplicates.
  2. json-schema-to-ts
    • Pros: Good output for simple schemas and fast.
    • Cons: Problem resolving definitions in referenced schemas (issue #172).

I thought Ajv, being a prominent tool for validation, might have tools for this, but I've only found limited support for type inferring with JTD schemas and no support for type generation for JSON Schema. Does the Ajv community recommend any tools for this purpose, or is there an in-built tool in Ajv that I might have missed?

croconut commented 7 months ago

@sinclair/typebox. Specifically Static. I would also very seriously consider using other features in that lib

jasoniangreen commented 3 weeks ago

Closing as this has been covered in other issues and there is no follow up action.