python-jsonschema / check-jsonschema

A CLI and set of pre-commit hooks for jsonschema validation with built-in support for GitHub Workflows, Renovate, Azure Pipelines, and more!
https://check-jsonschema.readthedocs.io/en/stable
Other
191 stars 39 forks source link

--schemafile from $schema #416

Closed 6nv closed 2 months ago

6nv commented 2 months ago

Hi, can check-jsonschema automatically detect which schema to validate against based on the value in $schema? I found --check-metaschema which is almost exactly what I want, but not quite. I want to write a pipeline to automatically validate all json files against their respective schemas without having to write a new check each time I add a new file.


a.json:

{
 "$schema": "../schema/a.json"
}

b.json:

{
 "$schema": "../schema/b.json"
}

(...you could imagine I have several more json files, each with their own schema.)

../schema/a.json

{
 "$schema": "http://json-schema.org/draft-04/schema#",
 ...
}

../schema/b.json

{
 "$schema": "http://json-schema.org/draft-04/schema#",
 ...
}

I want to write something like this:

$ check-jsonschema database/*.json
# Usage: check-jsonschema [OPTIONS] INSTANCEFILES...
# Error: Either --schemafile, --builtin-schema, or --check-metaschema must be provided

But currently I need to write this:

$ check-jsonschema --schemafile schema/a.json database/a.json
$ check-jsonschema --schemafile schema/b.json database/a.json
$ check-jsonschema --schemafile schema/c.json database/c.json
...

I tried --builtin-schema which looked promising but still not quite what I'm looking for. Do I have any options right now or is this not currently a feature of this tool? Thanks!

Might be a duplicate of #310

sirosen commented 2 months ago

I think this is the same feature as requested in #310.

Current status is that I haven't been working on it. I've been stretched a bit thin since midwinter this past year and unable to make much progress on most FOSS projects. I'm going to close to consolidate with #310, but feel free to either add detail there if you think there's important information missing from that conversation, or to reopen this if you think I'm wrong and it's not a duplicate.