Skip to content

Enhancement: Collapse overlapping numeric constraint error messages in anyOf/oneOf #173

@srivastava-diya

Description

@srivastava-diya

Problem Description

Currently, when validating against an anyOf or oneOf schema that has multiple overlapping numeric or string constraints, the error output returns a separate message for every failed alternative like so ,

{
  "anyOf": [
    {
      "type": "string",
      "maxLength": 2
    },
    {
      "type": "string",
      "maxLength": 4
    }
  ]
}
  • If we validate an instance like "hello" (length 5), the errors retured are:
Expected one or more of the alternatives to pass validation:
- Expected a string with no more than 2 characters
- Expected a string with no more than 4 characters

Proposed Enhancement

As pointed out by @jdesrosiers here since these constraints are somehow testing the same attribute (string length) and one constraint is a subset of the other, they could be collapsed into a single, more concise error message.

For the example above, the ideal collapsed output for the user would be:

"Expected a string with no more than 4 characters"

Opening this issue to discuss

  • What logic should be used to determine if two alternative errors are collapsible?
  • Feedback and suggestions are very welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions