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

OneOf validation gives unnecessary errors #535

Closed
ksychla opened this issue Mar 18, 2022 · 13 comments
Closed

OneOf validation gives unnecessary errors #535

ksychla opened this issue Mar 18, 2022 · 13 comments

Comments

@ksychla
Copy link
Contributor

ksychla commented Mar 18, 2022

Let's say we have a schema like this one:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/product.schema.json",
  "title": "",
  "description": "",
  "type": "object",
  "properties": {
    "mainprop": {
      "type": "object",
      "oneOf": [
        {
          "required": [
            "property1"
          ],
          "properties": {
            "property1": {
              "enum": [
                "AAA",
                "BBB",
                "CCC"
              ],
              "type": "string"
            }
          }
        },
        {
          "required": [
            "property2"
          ],
          "properties": {
            "property2": {
              "type": "number"
            }
          }
        }
      ]
    }
  },
  "required": [ "mainprop" ]
}

So we have one oneOf property that requires either property1 or property2.

{
  "mainprop": {
    "property1": "INVALID"
  }
}

This json is incorrect and the validator should return error that the value of property1 is incorrect, but in addition to that it returns an error that property2 is required and missing:

$.mainprop.property1: does not have a value in the enumeration [AAA, BBB, CCC]
$.mainprop.property2: is missing but it is required

It's not correct, because property1 is already present, just incorrect. So the error that property2 is required is unnecessary/incorrect.

I have a fix for that, just have to submit a PR

@AndreasALoew
Copy link
Contributor

I think I have seen the same issue recently.

Would it be possible that we do see the superfluous "is missing but it is required" not just in an OneOf, but also an AnyOf scenario (with at least one value required, but more than one valid)?

Looking forward to seeing your PR submitted...

@ksychla
Copy link
Contributor Author

ksychla commented Mar 24, 2022

Sure, I would be happy to submit the PR, but I don't have the permissions to push my changes to a branch. Can you help with that?

@AndreasALoew
Copy link
Contributor

@RenegadeWizard , you can perfectly create a PR from your own fork (and typically also, a dedicated branch in this fork) of the project: see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

@ksychla
Copy link
Contributor Author

ksychla commented Mar 24, 2022

Great, thanks for your help, I submitted a PR: #537

@AndreasALoew
Copy link
Contributor

Hello @RenegadeWizard,

what is your current progress regarding the addition of an "AnyOf" fix to your PR that we discussed here: #537 (comment)?

Even though there could already be at least one subschema passing validation without "required" property issues, this fact so far is not taken into account, and subsequent "required" validation issues for other subschemas are still reported (even though they should not matter as we already have at least one valid subschema)...

In case you don't have a fix in preparation already, I'd try myself to derive one throughout the rest of this week.

Thanks a million for a short update on your status! 👍

AndreasALoew added a commit to AndreasALoew/json-schema-validator that referenced this issue Apr 24, 2022
…Validator, too

(in addition to OneOfValidator)
@AndreasALoew
Copy link
Contributor

AndreasALoew commented Apr 24, 2022

As I haven't heard back from @RenegadeWizard, I have moved forward and created a proposed fix myself: #559 😄

(Please note that in the current state of master, some tests fail, but this is NOT due to this my PR...)

@stevehu
Copy link
Contributor

stevehu commented Apr 24, 2022

@AndreasALoew I have rerun the test on the master branch and all tests are passed. Could you please point out which test case failed for you? Thanks.

@AndreasALoew
Copy link
Contributor

[ERROR] Errors:
[ERROR]   V201909JsonSchemaTest.testRefRemoteValidator:315->BaseSuiteJsonSchemaTest.runTestFile:163 » IllegalState
[ERROR]   V4JsonSchemaTest.testIdSchemaWithUrl:287->BaseSuiteJsonSchemaTest.runTestFile:163 » IllegalState
[ERROR]   V4JsonSchemaTest.testLoadingWithId:38 » FileNotFound http://localhost:1234/sel...
[ERROR]   V4JsonSchemaTest.testRefRemoteValidator:247->BaseSuiteJsonSchemaTest.runTestFile:163 » IllegalState
[ERROR]   V6JsonSchemaTest.testRefRemoteValidator:212->BaseSuiteJsonSchemaTest.runTestFile:163 » IllegalState
[ERROR]   V7JsonSchemaTest.testRefRemoteValidator:308->BaseSuiteJsonSchemaTest.runTestFile:163 » IllegalState
[INFO]
[ERROR] Tests run: 374, Failures: 0, Errors: 6, Skipped: 56

surefire-reports.zip

@AndreasALoew
Copy link
Contributor

@stevehu @RenegadeWizard Please tell me in case there is anything that stops you from applying my PR #559 or at least answering my question there about whether I should change it according to @RenegadeWizard's remark...

Thank you! :-)

stevehu pushed a commit that referenced this issue May 23, 2022
@stevehu
Copy link
Contributor

stevehu commented May 23, 2022

Sorry. I missed the confirmation from @RenegadeWizard. I tested this morning and merged. Thanks a lot for your help.

@stevehu stevehu closed this as completed May 23, 2022
@AndreasALoew
Copy link
Contributor

Many thanks as well to you, @stevehu , for now doing this super-fast merge! 👍

May I ask you for when the next offcial release (i.e. 1.0.70 ?) will be scheduled? Will this be before June 3rd?

Thanks again for your kind help! 😄

@stevehu
Copy link
Contributor

stevehu commented May 23, 2022

I have released 1.0.70 minutes ago. Please let me know if you encounter any issues. Thanks.

@AndreasALoew
Copy link
Contributor

Will do, but only tomorrow... Thanks again for your great responsiveness! 👍 👍 👍

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

3 participants