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

Failing test_canonicalises_to_equivalent_fixpoint #64

Open
Stranger6667 opened this issue Aug 26, 2020 · 2 comments
Open

Failing test_canonicalises_to_equivalent_fixpoint #64

Stranger6667 opened this issue Aug 26, 2020 · 2 comments

Comments

@Stranger6667
Copy link
Contributor

Stranger6667 commented Aug 26, 2020

Currently the test_canonicalises_to_equivalent_fixpoint test fails on assert cc == canonicalish(cc) with the following schema:

schema = {'not': {'anyOf': [{'type': 'number'}, {'if': {'type': 'null'}, 'then': {'type': 'null'}, 'else': {}}]}}

As far as I see, calling canonicalise second time should not transform the schema again. But here is schema after the first call:

{
    "not": {"anyOf": [{"const": None}, {"not": {"const": None}}]},
    "type": ["null", "boolean", "string", "array", "object"],
}

and after the second call:

{
    "not": {
        "anyOf": [
            {"const": None},
            {
                "type": ["null", "boolean", "string", "array", "object"],
                "not": {"const": None},
            },
        ]
    },
    "type": ["null", "boolean", "string", "array", "object"],
}

git bisect gave me this commit - afc292b

Should the second call leave the input schema as is?

@Zac-HD
Copy link
Member

Zac-HD commented Aug 27, 2020

Hmm. This schema should in fact canonicalise to {"not": {}}, because {"anyOf": [S1, {"not": S2}]} should canonicalise to {} for any schemas where merged([S1, S2]) == S1. This is the main thing to fix.

It would also be nice to express that not: {const: None} excludes type: null, and likewise for enums containing None or both booleans.

In the process, we should overhaul our corpus-based tests: keep the valid and invalid inputs for the test suite schemas and check that their status doesn't change by canonicalising. We might want to do this with submodules, given the size of the schemastore corpus (see https://github.com/Zac-HD/hypothesis-jsonschema/compare/catalog-update).

@Zac-HD
Copy link
Member

Zac-HD commented Sep 30, 2020

A simpler example - consider the three schemas A, B, and C:

A = {'not': {'anyOf': [{'type': 'number'}, {'type': 'integer'}]}}
B = {'type': ['null', 'boolean', 'string', 'array', 'object'], 'not': {'type': 'integer'}}
C = {'type': ['null', 'boolean', 'string', 'array', 'object']}

C is the canonical form. B canonicalises to C, correctly. However A canonicalises to B, instead of directly to C!

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