Skip to content

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

@jsu216

Description

@jsu216

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions