chris48s / v8r

✔️ A command-line JSON, YAML and TOML validator that's on your wavelength
https://chris48s.github.io/v8r/
MIT License
29 stars 5 forks source link

Ajv 7 #5

Closed chris48s closed 2 years ago

chris48s commented 3 years ago

Unfortunately upgrading isn't a straight no-brainer because Ajv 7 adds compatibility with draft-2019-09 but drops support for draft-04. Need to do a bit of research: Which are there more of on schemastore? Schemas using draft-2019-09 or draft-04 ?

chris48s commented 3 years ago

Schemastore does have external links, but in https://github.com/SchemaStore/schemastore/tree/master/src/schemas/json there are 2 schemas that use draft-2019-09 and ~200 that use draft-04 so sticking on Ajv6 is clearly the way forward for now

chris48s commented 3 years ago

There's probably an inflection point somewhere down the line where this stops being a no-brainer.

One possible option here might be to make ajv a peer dependency and support both. Then the user can make the choice, but that complicates everything (including setup for users).

chris48s commented 3 years ago

Another possibility would be to switch out ajv for another library that supports both draft-2019-09 and draft-04. e.g: https://github.com/hyperjump-io/json-schema-validator or https://github.com/ExodusMovement/schemasafe

Ajv is a much more widely used library, but one advantage of https://github.com/ExodusMovement/schemasafe is that this is the library used in the schemastore repo for their tests. Given this project is heavily tied to schemastore, that might be a better choice to ensure more compatibility between the most commonly used schemas and the validation library. That would probably help reduced the issues noted in #18 too.

chris48s commented 2 years ago

Hmm. It looks like ajv might be back in the game.

https://ajv.js.org/json-schema.html#json-schema-versions

draft-04

You can use JSON Schema draft-04 schemas with Ajv from v8.5.0 and the additional package ajv-draft-04 (both ajv and ajv-draft-04 should be installed).

const Ajv = require("ajv-draft-04")
const ajv = new Ajv()
chris48s commented 2 years ago

Did a spike on this. Ajv >=8.5 is looking promising so far..

chris48s commented 2 years ago

0.7.0 released using ajv 8