ajv-cli icon indicating copy to clipboard operation
ajv-cli copied to clipboard

Use standard meta schema

Open sim642 opened this issue 3 years ago • 4 comments

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#"

sim642 avatar Jan 10 '22 09:01 sim642

@sim642: did you find the answer?

fharper avatar Apr 21 '22 22:04 fharper

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.

sim642 avatar Apr 22 '22 04:04 sim642

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

epoberezkin avatar Apr 22 '22 05:04 epoberezkin

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...

sim642 avatar Aug 11 '22 14:08 sim642