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

Mis-canonicalisation of const in draft04 schemas (not a keyword until draft06) #76

Open
Zac-HD opened this issue Feb 3, 2021 · 2 comments

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Feb 3, 2021

The const keyword was added in draft-06, and therefore has no effect whatsoever in draft-04 schemas. While authors probably intended to constrain the value somewhat, we still have to follow the spec!

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "oneOf": [{"type": "boolean"}, {"const": None}],
    "type": ["boolean", "null"],
}
# Should canonicalise 
#    {"const": None} -> {}
#    "oneOf": [{"type": "boolean"}, {}] -> "not": {"type": "boolean"}
# and ultimately to
{"enum": [None]}

See also python-jsonschema/jsonschema#778; longer term this is another argument for my do-it-right schema processing redesign...

@Stranger6667
Copy link
Contributor

By coincidence, the very same behavior happened to me yesterday - I was canonicalising the Swagger schema (where $schema points to draft04) components and my test suite started failing when single-item enums were transformed to const :) Probably having a condition on the draft version should be sufficient to fix it

@Zac-HD
Copy link
Member Author

Zac-HD commented Feb 3, 2021

Yep.

We'll need to start passing the schema version around though, as well as adding version-awarness to gen_schema().

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

No branches or pull requests

2 participants