ajv-validator / ajv-cli

Command-line interface for Ajv JSON Validator
https://ajv.js.org
MIT License
262 stars 66 forks source link

Use standard meta schema #199

Open sim642 opened 2 years ago

sim642 commented 2 years ago

From ajv's documentation I see there are standard meta schemas that can be used, but how to do that from the CLI?

Using -m /usr/share/nodejs/ajv/lib/refs/json-schema-draft-04.json doesn't seem to help at all:

meta-schema /usr/share/nodejs/ajv/lib/refs/json-schema-draft-04.json is invalid
error: no schema with key or ref "http://json-schema.org/draft-04/schema#"
fharper commented 2 years ago

@sim642: did you find the answer?

sim642 commented 2 years ago

No, I just ended up removing the meta schema reference before validation in a GitHub Actions workflow where I'm using ajv:

 ​      - ​name​: ​Work around meta-schema missing error ​#​ https://github.com/ajv-validator/ajv-cli/issues/199 
 ​        ​run​: ​| 
 ​          sed -i 's|"$schema": "http://json-schema.org/draft-04/schema#",||' src/util/options.schema.json

It's very ugly and not scalable to actual local usage of ajv-cli conveniently.

epoberezkin commented 2 years ago

Ajv doesn’t support draft4 in after v6. There is an option “draft” that would include the correct meta schema automatically without referencing it.

sim642 commented 2 years ago

There is an option “draft” that would include the correct meta schema automatically without referencing it.

What option? There isn't one here.

I did find https://ajv.js.org/json-schema.html#draft-04, but installing ajv-draft-04 made no difference. I guess that cannot be used with ajv-cli?

I also found ajv migrate -s schema to be a nicer workaround than sed-ing the schema...