how to compile/validate group of json-schema files that might reference each other in v4+
See original GitHub issueScenario: Directory with several JSON-schema files, some of which might $ref
erence the others. Each schema file defines a unique $id
property.
I want to compile/validate them all at once
This command worked in ajv-cli v3.x:
ajv -s 'src/models/*.json' -r 'src/models/*.json'
But with 4.x and 5.0, I get errors like this:
error: schema with key or id "https://mycompany.com/this/schema/model.json" already exists
But the only file that has that id is the file itself in that directory. It would seem that the -r flag is not excluding the file’s self when checking for duplicate ids in that referenced list.
How can I accomplish validating a group of schemas like this with the newer version?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Structuring a complex schema — Understanding JSON ...
You can set the base URI by using the $id keyword at the root of the schema. The value of $id is a...
Read more >Combining schemas - Ajv JSON schema validator
Combining schemas with $ref. You can structure your validation logic across multiple schema files and have schemas reference each other using $ref keyword....
Read more >How to Validate Your JSON Using JSON Schema
JSON Schema is a JSON-based format for defining the structure of JSON data. It provides a contract for what JSON data is required...
Read more >Tiny Validator for v4 JSON Schema
If schemas are referenced ( $ref ) but not known, then validation will return true and the missing schema(s) will be listed in...
Read more >How to manage multiple JSON schema files? - Stack Overflow
In JSON Schemas, you can either put a schema per file and then access them using their URL (where you stored them), or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree, the
-r
should omit file specified by the-s
flag.My scenario is
and got the error
schema with key or id ...already exists
. I have to specify -r multiple times, which is uncomfortable.Same problem with
ajv compile
.I am not sure the approach to filter out file will be the proper one. With glob, there is an order from which files are processed, thus depending on the order, depending schema might not be there yet. A more reliable fix would be to load everything with
-r
and then, on the-s
files/schemas check if they are loaded or not yet