Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement JSON Schema Draft 7 Support #81

Open
theonewolf opened this issue Jan 15, 2021 · 5 comments
Open

Implement JSON Schema Draft 7 Support #81

theonewolf opened this issue Jan 15, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@theonewolf
Copy link

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.

@theonewolf theonewolf added the enhancement New feature or request label Jan 15, 2021
@jacksmith15
Copy link
Owner

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
Copy link
Owner

jacksmith15 commented Jan 20, 2021

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
Copy link
Author

@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
Copy link

c4lcifer commented Mar 3, 2022

Would also be interested in draft-07 enhancement.

@danielchalef
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants