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

Disagreement with other schema validators for JSON is valid against more than one schema from 'oneOf' error #225

Closed
ilyagr opened this issue Feb 9, 2025 · 7 comments · Fixed by #226

Comments

@ilyagr
Copy link

ilyagr commented Feb 9, 2025

For this schema, validating the following json

{
       "colors" : {
           "author": "blue"
       }
} 

passes with jsonschema validate v. 5.0.1.

Problem: I think it is not supposed to pass.

Other validators report an error, e.g. https://www.jsonschemavalidator.net/s/SVJT4LS6 reports:

Found 1 error(s)

Message: JSON is valid against more than one schema from 'oneOf'. Valid schema indexes: 0, 1.

Schema path: #/properties/colors/propertyNames/oneOf

https://taplo.tamasfe.dev/configuration/developing-schemas.html behaves the same; changing the metaschema to draft 4 does not change the behavior.

I think the error is real, tha part of the schema in https://github.com/jj-vcs/jj/blob/07c63ed182bb1cbd9b52fe8e4f41638bdb5aafb6/cli/src/config-schema.json#L271-L300 seems buggy (deleting the whole propertyNames section together with the now unused basicFormatiingLabes section fixes it). So, this seems like a bug in jsonschema. Both tools claim to support Draft 7 of JSON Schema fully.

Aside/FR: If jsonschema could have a more detailed error in this case and/or a nice lint, that would be great! This is what I was hoping for when I tried jsonschema.

@ilyagr ilyagr changed the title Disagreement with other schema validators Disagreement with other schema validators for "JSON is valid against more than one schema from 'oneOf'" Feb 9, 2025
@ilyagr ilyagr changed the title Disagreement with other schema validators for "JSON is valid against more than one schema from 'oneOf'" Disagreement with other schema validators for JSON is valid against more than one schema from 'oneOf' error Feb 9, 2025
@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

Hey @ilyagr ,

Interesting. It does seem like a bug. Let me get into it and release a fix today. In the mean-time, you might also be interested in contributing a test case for this to the official JSON Schema Test Suite: https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main

@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

This is what it seems to be going on: property names are always strings, so Blaze (https://github.com/sourcemeta/blaze) is too-eagerly optimising out the { "type": "string" } case to nothing (as its always true), without considering the impact it can have on specific conditionals like oneOf. I'm fixing it now! Great catch.

In any case, are you sure your schema is doing what you expect? If it is a oneOf between an enum of strings and string type, then the schema is by definition unsatisfiable?

jviotti added a commit to sourcemeta/blaze that referenced this issue Feb 10, 2025
See: sourcemeta/jsonschema#225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

Fix incoming. Getting the PR merged in Blaze, will bump it here, and release a new version of the CLI.

jviotti added a commit to sourcemeta/blaze that referenced this issue Feb 10, 2025
See: sourcemeta/jsonschema#225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 10, 2025
Fixes: #225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 10, 2025
Fixes: #225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 10, 2025
Fixes: #225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
jviotti added a commit that referenced this issue Feb 10, 2025
Fixes: #225
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

Just released v5.0.2 with the fix: https://github.com/sourcemeta/jsonschema/releases/tag/v5.0.2. Please give it a shot and thanks for reporting this! 🙏🏻

@ilyagr
Copy link
Author

ilyagr commented Feb 10, 2025

Thank you very much for the fix!

In the mean-time, you might also be interested in contributing a test case for this to the official JSON Schema Test Suite: https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main

I might leave this to you, since you better understand the problem, the policies of the JSON Schema test suite, etc.

As an aside, I should get https://github.com/jj-vcs/jj/blob/main/cli/src/config-schema.json ingested into https://schemas.sourcemeta.com/ :)

Note that the schema changes often as config options are added/removed. We usually recommend people use https://jj-vcs.github.io/jj/latest/config-schema.json, there is also the stable (but also buggy) https://jj-vcs.github.io/jj/v0.26.0/config-schema.json .

In any case, are you sure your schema is doing what you expect? If it is a oneOf between an enum of strings and string type, then the schema is by definition unsatisfiable?

Yes, the schema is broken, I'm pretty sure. I'm about to fix it.

@jviotti
Copy link
Member

jviotti commented Feb 10, 2025

Great stuff and please let us know if there is anything we can ship tooling wise to make your work with JSON Schema more enjoyable!

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