Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add support for discriminator #29

Copy link
Copy link
Closed
@gberaudo

Description

@gberaudo
Issue body actions

It would be nice to have support for the discriminator object so that anyOf or oneOf schemas can return good validation errors.

Exemple schema:

{
    "$ref": "#/$defs/Route",
    "$defs": {
        "MountainHiking": {
            "type": "object",
            "properties": {
                "discipline": {
                    "type": "string",
                    "enum": ["mountain_hiking"]
                },
                "length": {
                    "type": "integer",
                }
            },
            "required": ["discipline", "length"]
        },
        "AlpineClimbing": {
            "type": "object",
            "properties": {
                "discipline": {
                    "type": "string",
                    "enum": ["alpine_climbing"]
                },
                "height": {
                    "type": "integer",
                },
            },
            "required": ["discipline", "height"]
        },
        "Route": {
          "discriminator": {
              "propertyName": "discipline",
              "mapping": {
                  "mountain_hiking": {"$ref": "#/$defs/MountainHiking"},
                  "alpine_climbing": {"$ref": "#/$defs/AlpineClimbing"},
              }
          },
            "oneOf": [
                {"$ref": "#/$defs/MountainHiking"},
                {"$ref": "#/$defs/AlpineClimbing"},
            ]
        }
    }
}

Example instance:

{
    "discipline": "mountain_hiking",
    "length": "bad_string"
}

Current error:

....is not valid under any of the given schemas...

Expected error:

...'bad_string' is not of type integer...

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.