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

JSON Schema string is inconsistent (no trailing #) #111

Closed
henryiii opened this issue Oct 9, 2023 · 3 comments · Fixed by #113
Closed

JSON Schema string is inconsistent (no trailing #) #111

henryiii opened this issue Oct 9, 2023 · 3 comments · Fixed by #113

Comments

@henryiii
Copy link
Collaborator

henryiii commented Oct 9, 2023

In trying to support SchemaStore and validate-pyproject, I've run into a really annoying inconsistency. SchemaStore's JSON validator checks that the $schema property is a valid schema:

Valid schemas: [
    "https://json-schema.org/draft/2020-12/schema",
    "https://json-schema.org/draft/2019-09/schema",
    "http://json-schema.org/draft-07/schema#"
    "http://json-schema.org/draft-06/schema#",
    "http://json-schema.org/draft-04/schema#",
    "http://json-schema.org/draft-03/schema#"
]

But validate-pyproject requires "http://json-schema.org/draft-07/schema" (since fastjsonschema requires a subschema matches the parent schema exactly), so all plugins currently require the # not be present.

As far as I can tell, SchemaStore is correct - the correct spelling is with the trailing #, it was not removed until draft 2019-09 moved to https. And there are already 700+ schemas on SchemaStore there using it. :)

If you agree that the trailing # is correct, I think it would be easy to migrate, since validate-pyproject gets to pre-process schemas that go to fastjsonschema. The steps would be:

  • Move all schemas stored in validate-pyproject to "http://json-schema.org/draft-07/schema#"
  • Check all schemas loaded via the entry points to see if they have "http://json-schema.org/draft-07/schema". If they do, make a shallow copy and modify the $schema to have the trailing #.
  • Eventually produce a warning if a plugin has the incorrect schema.

Doing it sooner rather than later would be ideal, so more plugins don't keep appearing with the missing #.

If we didn't change this, then we could still handle this in reverse when loading a plugin, we could strip the # instead, so it's not a blocker for SchemaStore support.

Thoughts?

@henryiii henryiii changed the title JSON Schema string is inconsistant JSON Schema string is inconsistent (no trailing #) Oct 9, 2023
@henryiii
Copy link
Collaborator Author

henryiii commented Oct 9, 2023

Ahh, finally found a fairly official reference: https://json-schema.org/understanding-json-schema/reference/schema#schema - which does include the # for the pre 2019 schemas.

@abravalheri
Copy link
Owner

Hi @henryiii, thank you very much for pointing this out. That was probably an oversight.
I agree with the suggestion. We should change the schemas we ship and modify any plugin that is not compatible, when loading them.

@henryiii
Copy link
Collaborator Author

Okay, I'll try to work on this soon, after #112.

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

Successfully merging a pull request may close this issue.

2 participants