Skip to content

Test that oneOf handles missing optional property #307

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

Closed
aznan2 opened this issue Nov 19, 2019 · 17 comments
Closed

Test that oneOf handles missing optional property #307

aznan2 opened this issue Nov 19, 2019 · 17 comments
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.

Comments

@aznan2
Copy link

aznan2 commented Nov 19, 2019

This shouldn't really be necessary, but at least one validation library fails this test.

{
  "description": "oneOf complex types",
  "schema": {
    "oneOf": [
      {
        "properties": {
          "bar": {"type": "integer"}
         /* , "baz": {"type": "boolean"} <-- new optional propery, not in data */
        },
        "required": ["bar"]
      },
      {
        "properties": {
          "foo": {"type": "string"}
        },
        "required": ["foo"]
      }
    ]
  },
  "tests": [
    {
      "description": "first oneOf valid (complex)",
      "data": {"bar": 2},
      "valid": true
    },
    {
      "description": "second oneOf valid (complex)",
      "data": {"foo": "baz"},
      "valid": true
    },
    {
      "description": "both oneOf valid (complex)",
      "data": {"foo": "baz", "bar": 2},
      "valid": false
    },
    {
      "description": "neither oneOf valid (complex)",
      "data": {"foo": 2, "bar": "quux"},
      "valid": false
    }
  ]
}
@Relequestual
Copy link
Member

Yikes, that's concerning!
These tests can probably be simplified by using boolean values as schemas, although I can't test the failure of the library in question easily to confirm that.

@aznan2
Copy link
Author

aznan2 commented Nov 19, 2019

@Relequestual You are correct, the added property could be simplified as

"properties": {
  "bar": {"type": "integer"},
  "baz": true
},
"required": ["bar"]

@Relequestual
Copy link
Member

Which of the tests does it fail? all of them?
I feel the name of the test needs to be more descriptive.

@aznan2
Copy link
Author

aznan2 commented Nov 19, 2019

Oh, in my example I've taken the existing test in oneOf.json with the description "oneOf complex types" and augmented it. Maybe it should be its own test.

The library fails test 1 and 3, {"bar": 2} and {"foo": "baz", "bar": 2}.

@Relequestual
Copy link
Member

Relequestual commented Nov 19, 2019

Ugh, sorry for having double standards on test naming...
We should probably have better names for our tests...

Out of interest, what does the library do with the following?:
https://jsonschema.dev/s/N4IgziBcLAOgdgAkbE8D2AXVlFyciiAA4BO6xApqZgJaVg54KGGoBGAhqU-q66kwBPKk1S14mSgHNqqFvwC+AGgUCQXAF681-QSMpiN6dABtKnePIKtFulbtSlKARwCutZwBMmAbV3IHNzWrAC6CnbwiiDKILRQMApB2lCIAEwI0YpAA

@Julian
Copy link
Member

Julian commented Nov 19, 2019 via email

@aznan2
Copy link
Author

aznan2 commented Nov 20, 2019

@Relequestual The library succeeds in validating your example.

@Julian The bug stems from the fact that the validator, if a property is missing, checks and reacts to whether it is a "complex validator" (allOf/anyOf/oneOf) before checking if the property is required.

@Julian
Copy link
Member

Julian commented Nov 20, 2019

Got it -- well, fair enough, if it's a bug that happened in the wild it's something we always have added -- happy to see a PR adding a new test for these -- do you think you'd have time to send one?

@Julian Julian added the missing test A request to add a test to the suite that is currently not covered elsewhere. label Nov 20, 2019
@Julian
Copy link
Member

Julian commented Nov 20, 2019

Can you just make sure to mention the downstream issue in either or both of the test case name or the commit message?

@Relequestual
Copy link
Member

@aznan2 Julian said what I was trying to allude to.
The location of a subschema should not change the validation result of that subschema by itself.
The combination of an array of subschema validation results should be collected and modified by the encasing applicator keyword, if any, such as *Of and not for example.

@aznan2
Copy link
Author

aznan2 commented Nov 21, 2019

Sure. Would you prefer if I modify the existing "complex types" test or should this be a new test case?

@Julian
Copy link
Member

Julian commented Nov 21, 2019 via email

@aznan2 aznan2 changed the title Test that allOf/anyOf/oneOf handles missing optional property Test that oneOf handles missing optional property Nov 22, 2019
@aznan2
Copy link
Author

aznan2 commented Nov 22, 2019

Created the PR #308

@aznan2
Copy link
Author

aznan2 commented Nov 22, 2019

Ugh. Can you guys fill me in on why my PR is breaking the build?

@Julian
Copy link
Member

Julian commented Nov 22, 2019

It's because you have a boolean schema there, but the test suite still uses draft 4 for its schemas.

Updating that is #238, but for now the easiest thing to do is likely just to switch to using {} instead of true.

@Julian
Copy link
Member

Julian commented Nov 22, 2019

Sorry, it's too early in the morning clearly for me to be responding to issues.

Scratch the above, it isn't related to #238, but is you using a boolean schema in the draft 4 folder which draft4 didn't have those -- so you do need to use {} but just in that one file.

@aznan2
Copy link
Author

aznan2 commented Nov 22, 2019

Yay, thank you!

Julian added a commit that referenced this issue Nov 22, 2019
issue #307 - test that oneOf handles missing optional property
@aznan2 aznan2 closed this as completed Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing test A request to add a test to the suite that is currently not covered elsewhere.
Projects
None yet
Development

No branches or pull requests

3 participants