sphinx-jsonschema icon indicating copy to clipboard operation
sphinx-jsonschema copied to clipboard

Support for Draft 2020-12

Open moi90 opened this issue 10 months ago • 3 comments

The documentation states that

I only tested it for use with the draft 4 specification of JSON Schema.

However, Draft 4 is ANCIENT (published in 2013) and the current Version is Draft 2020-12 (published in 2022).

Is it planned to update sphinx-jsonschema to follow the latest json-schema.org specification?

moi90 avatar Mar 09 '25 07:03 moi90

There are currently no plans to support the latest specification. BUT I do welcome a PR that implements it (preferably in a backwards compatible way).

lnoor avatar Mar 10 '25 12:03 lnoor

Do you have an idea how this could be implemented in a backwards compatible way?

I just had a very brief look at the source. It seems that class JsonSchema is agnostic of the actual schema file contents and WideFormat (what does this name mean?) is responsible for actually formatting the schema. Is that right?

Then, we could have multiple version-specific subclasses of WideFormat that get instantiated depending on the version specified in the file.

moi90 avatar Mar 11 '25 09:03 moi90

WideFormat was named because it creates rst tables that grow across, not downwards. So when the schema is deeply nested, WideFormat will keep adding columns to the table. Remember that WideFormat doesn't actually format the schema, it converts it into an rst table whereafter sphinx/docutils renders it as any other snippet of rst text.

Multiple versions of WideFormat will do the trick. But maybe (I didn't look at the latest version) it is sufficient to expand the dicts and lists defining the different types of keywords and their behaviour. A very fancy approach would be to declare for each keyword and schema construct an (anonymous/lambda) function on how to convert it. A new version would mean the addition of a new table. Yet another approach could be to annotate each construct with a list of versions. But those approaches will be more demanding than multiple versions of WideFormat.

lnoor avatar Mar 13 '25 21:03 lnoor