jacksmith15 / statham-schema

Statham is a Python Model Parsing Library for JSON Schema.
https://statham-schema.readthedocs.io/en/latest/
MIT License
38 stars 11 forks source link

Implement JSON Schema Draft 7 Support #81

Open theonewolf opened 3 years ago

theonewolf commented 3 years ago

Description of requested feature Draft 7 is the latest specification for JSON Schema and libraries such as jsonschema support it out of the box. I have a spec which I'd like to generate a Python class for, but am worried about subtle incompatibilities.

The changes do not seem drastic: https://json-schema.org/draft-07/json-schema-release-notes.html

I think we can scope this project well.

Workaround Just try Draft 7 schemas with statham out of the box. They may work, especially since a lot of it is backwards compatible ("In terms of validation keywords and outcomes, it is fully backwards-compatible with draft-06.").

Additional context I think primary differences are in new out of the box formats, as described on the Draft 7 release notes linked above.

jacksmith15 commented 3 years ago

I think the main task there is if, then and else. The other keywords are largely annotative when considered in from the perspective of this library.

I rarely see if, then and else used in schemas, and have never had a need for them myself. I don't expect it would be overly hard to add them however.

The first step on this journey would be enabling the draft 7 test suite here to see how many tests fail.

FWIW Draft 07 is not the latest specification. The latest specification is 2019-09, but I have little intention of supporting that draft any time soon, as it breaks compatibility with the JSON Reference specification.

jacksmith15 commented 3 years ago

I'd be interested in ideas for how if/then/else will look in the models. First thing that comes to mind:

class Person(Object):
    address: Object = Conditional(
        if_=Element(properties={"country": Property(Element(const="USA"))}),
        then=Object.inline(properties={"postcode": Property(String(pattern="[0-9]{5}(-[0-9]{4})?"))}),
        else_=Object.inline(properties={"postcode": Property(String())}),
    )
theonewolf commented 3 years ago

@themontem do you have some clean hypothetical examples you could drop in here from our large schema(s)? Also, did we move onto 2019-09? At which point this is less useful to us.

c4lcifer commented 2 years ago

Would also be interested in draft-07 enhancement.

danielchalef commented 1 year ago

+1. The CMS "Transparency in Coverage" healthcare pricing data uses a draft-07 schema.