python-jsonschema / python-jsonschema/jsonschema

enabling format-assertion via adding vocabulary to a new meta-schema (dialect?)

Open
#1,355 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5k
Forks
671
Avg merge
1d 1h
Merged PRs (30d)
10

Description

What is the supported way to check a JSON file via a (local) schema that wants to enforce the format assertions?
It is already supported?

My example is what https://github.com/oasis-tcs/csaf/pull/962 is trying to do.

https://github.com/oasis-tcs/csaf/blob/78f4b61ba2ba05d375a452ef7938abde16949457/csaf_2.1/json_schema/csaf_json_schema.json#L2

sets a custom dialect:

  "$schema": "https://docs.oasis-open.org/csaf/csaf/v2.1/meta_json_schema.json",

which locally is
https://github.com/oasis-tcs/csaf/blob/78f4b61ba2ba05d375a452ef7938abde16949457/csaf_2.1/json_schema/meta_json_schema.json
and just aims for adding the necessary vocabulary to treat formats as assertion.

However as can be seen in https://github.com/oasis-tcs/csaf/pull/962#issuecomment-2841656817 and above, that is needs to explicitly set jsonschema.DRAFT202012 to just add the

resource = Resource(contents=schema, specification=jsonschema.DRAFT202012)

I haven't found a public API way to give the new dialect to the referencing.jsonschema._SPECIFICATIONS. (As we do not change the referencing behaviour, it may or not may be okay to use specification=jsonschema.DRAFT202012., it just feels not right as the meta schema is available.

The other concern is that adding the vocabularies does not seem to change assertion checking in the implementation, only adding format_checker=Draft202012Validator.FORMAT_CHECKER decides this. According to my (limited) understanding adding the vocabulary of format-assertion should enable the checks by default. Okay - Draft202012Validator is for the Draft 2020-12 where formation assertion is off by default, but can be enabled.

If it already works, then an example of how to create a new meta schema (dialect) that has format-assertion enable like it should be done in accordance with Draft 2020-12 would be very helpful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the CSAF schema case linked in the issue, including Resource(contents=schema, specification=jsonschema.DRAFT202012) and Draft202012Validator.FORMAT_CHECKER. Read the referenced meta_json_schema.json and the discussion around pull request 962; done means the supported public API and expected format-assertion behavior for a custom dialect are clearly established or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.