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

OneOfValidator give incorrect message when the wrong json element is not the first one in the list #470

Closed
jsu216 opened this issue Oct 14, 2021 · 7 comments
Assignees
Labels

Comments

@jsu216
Copy link
Contributor

jsu216 commented Oct 14, 2021

Since version 1.0.46, we found that if the invalid json is not the first in the oneOf choice list, the error message is not right.
For an example, if the schema is like below:

oneOf:
        - $ref: '#/components/schemas/SearchByEmail'
        - $ref: '#/components/schemas/SearchByPartialName'
        - $ref: '#/components/schemas/SearchByPhone'

The SearchByPartialName's definition is like below:

SearchByPartialName:
      type: object
      additionalProperties: false
      properties:
        byPartialName:
          type: object
          required:
            - partialName
          properties:
            partialName:
              type: string
              nullable: true
              maxLength: 70
              minLength: 1

If the json message has partialName exceeds 70 chars like below:

{
  "search": {
    "byPartialName": {
      "partialName": "aabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccddaabbccdd"
    }
  }
}

The error message is wrong: Schema Validation Error - requestBody.search.byPartialName: is not defined in the schema and the schema does not allow additional properties

However, if SearchByPartialName is the first in the oneOf list. the error message becomes correct. Schema Validation Error - requestBody.search.byPartialName.partialName: may only be 70 characters long

@stevehu
Copy link
Contributor

stevehu commented Oct 14, 2021

This has been fixed in the following ticket. I will release a new version today or tomorrow. Thanks for raising it.

#456

@stevehu stevehu closed this as completed Oct 16, 2021
@jsu216 jsu216 reopened this Oct 19, 2021
@jsu216
Copy link
Contributor Author

jsu216 commented Oct 19, 2021

The latest code for issue #456 does not fix this issue. The root cause of this issue is that the OneOfValidator reports multiple errors from each schema in the oneOf list. The SchemaValidator in light-rest-j4/openapi-validator only picks the first error in the error list as the validation response. So depending on the order in the oneOf list, the error response can be misleading.
There was a logic in the OneOfValidator to remove errors are caused by addtionalProperties, but it was removed in a03170d

@stevehu
Copy link
Contributor

stevehu commented Oct 20, 2021

@jsu216 It looks like your issue is not exactly the same as the #456. Would you be able to submit a PR to get it fixed? Thanks.

@jsu216
Copy link
Contributor Author

jsu216 commented Oct 20, 2021

@stevehu PR created

@stevehu stevehu added the bug label Oct 21, 2021
@stevehu
Copy link
Contributor

stevehu commented Oct 21, 2021

@jsu216 Thanks a lot for the fix. I have released 1.0.63 and the release note can be found at https://github.com/networknt/json-schema-validator/releases/tag/1.0.63

@stevehu stevehu closed this as completed Oct 21, 2021
@jsu216
Copy link
Contributor Author

jsu216 commented Oct 21, 2021

Thanks @stevehu, Do you know when is the next light-4j release going to be built with this 1.0.63 json-schema-validator? The latest one is still with 1.0.49.

@stevehu
Copy link
Contributor

stevehu commented Oct 21, 2021

I will release 1.6.x before the end of the month with the dependency update. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants