Skip to content

Discriminated schema with shared ancestor shows invalid mapping options #2678

@milesizzo

Description

@milesizzo

Describe the bug

If a discriminated schema shares a common ancestor (schema) with another discriminated schema, extra schemas are shown in the UI (namely the two discriminated schemas).

Expected behavior

I would expect only the types listed in the mapping section to be shown.

Minimal reproducible OpenAPI snippet(if possible)

{
  "openapi": "3.0.1",
  "info": {
    "title": "My API",
    "version": "v1"
  },
  "paths": {
    "/animals": {
      "post": {
        "summary": "Create an animal",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateAnimalReqDto"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CreateAnimalReqDto": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "mammal": {
            "$ref": "#/components/schemas/MammalDto"
          },
          "reptile": {
            "$ref": "#/components/schemas/ReptileDto"
          }
        }
      },
      "AnimalDto": {
        "type": "object"
      },
      "MammalDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/AnimalDto"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              }
            },
            "discriminator": {
              "propertyName": "type",
              "mapping": {
                "cat": "#/components/schemas/CatDto",
                "dog": "#/components/schemas/DogDto"
              }
            }
          }
        ]
      },
      "ReptileDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/AnimalDto"
          },
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              }
            },
            "discriminator": {
              "propertyName": "type",
              "mapping": {
                "lizard": "#/components/schemas/LizardDto"
              }
            }
          }
        ]
      },
      "CatDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/MammalDto"
          },
          {
            "type": "object"
          }
        ]
      },
      "DogDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/MammalDto"
          },
          {
            "type": "object"
          }
        ]
      },
      "LizardDto": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ReptileDto"
          },
          {
            "type": "object"
          }
        ]
      }
    }
  }
}

Screenshots

Image

(highlighted discriminator values are invalid)

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions