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

Possible mishandling in allOf keyword canonicalisation #65

Closed
Stranger6667 opened this issue Aug 26, 2020 · 4 comments
Closed

Possible mishandling in allOf keyword canonicalisation #65

Stranger6667 opened this issue Aug 26, 2020 · 4 comments

Comments

@Stranger6667
Copy link
Contributor

Consider the following schema:

SCHEMA = {
    "allOf": [
        {"$ref": "#/definitions/ref"},
        {"required": ["foo"]}
    ],
    "properties": {
        "foo": {},
    },
    "definitions": {
        "ref": {"maxProperties": 1}
    },
    "type": "object"
}

If we call jsonschema.validate({}, SCHEMA) then it will complain that 'foo' is a required property which is expected. But, if we canonicalise the schema, then $ref keyword will be placed to the schema's root and will cancel the validation of other keywords as implemented in jsonschema. I can't find the exact place in the spec itself, but there are tests in the JSON Schema suite that ensure that other keywords are ignored.

So, with the canonicalised version of the schema an empty object passes validation:

>>> CANONICALISED = canonicalish(SCHEMA)
>>> jsonschema.validate({}, CANONICALISED)

What would be the best way to solve it? Should we check if there are schemas with $ref keywords, then keep them inside allOf and move everything else to the previous level?

P.S. I found the issue via Webpack bootstrap-loader configuration file schema in the testing catalog

@Zac-HD
Copy link
Member

Zac-HD commented Aug 27, 2020

Canonicalising should remove the $ref keyword for non-recursive references, but we will probably need to add special handling for recursive references.

@Stranger6667
Copy link
Contributor Author

Canonicalising should remove the $ref keyword for non-recursive references

Aha, I missed that :) I found it in my experiment branch, where I didn't inline references at all.

but we will probably need to add special handling for recursive references.

Would it make sense if I submit a PR that will handle it? I.e. to be future-compatible with recursive references? Or is it better to add it as a part of that recursive references PR?

@Zac-HD
Copy link
Member

Zac-HD commented Aug 27, 2020

I'd be happy either way, but I don't think we can really test it separately so let's keep them together.

@Zac-HD
Copy link
Member

Zac-HD commented Feb 3, 2021

Having checked on master, this no longer happens 🙂

@Zac-HD Zac-HD closed this as completed Feb 3, 2021
Zac-HD added a commit that referenced this issue Feb 3, 2021
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