Redocly / Redocly/redoc

Discriminator dropdown shown for all variants

Open
#1,031 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

openapi
Dominant language
TypeScript
Stars
25.9k
Forks
2.4k
Avg merge
13h 10m
Merged PRs (30d)
4

Description

I have a base schema Pet with a discriminant petType and some schemas Cat, Dog and Lizard that inherit from it. When I use the Pet schema in documentation, I get the dropdown for petType as expected with each of the different types, but when I use the Cat type I also get the same, despite petType: "Cat" being the only valid value for this.

These are the types I get (first Pet and then Cat):

image
image

For the second one, I'd expect something like this instead:

image

These are the files that I'm using for this test case:

openapi: 3.0.2
info:
  title: Test API
  version: playground
servers: []

paths:
  /pets:
    get:
      summary: "Get all pets"
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: "#/components/schemas/Pet"
  /cats:
    get:
      summary: "Get all cats"
      responses:
        200:
          description: ""
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: "#/components/schemas/Cat"

components:
  schemas:
    Pet:
      type: object
      description: "Pet superclass"
      required:
        - petType
      properties:
        petType:
          type: string
          description: "Pet type"
      discriminator:
        propertyName: petType
    Cat:
      description: "Cat subclass"
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Cat`
          properties:
            name:
              description: "Name"
              type: string
    Dog:
      description: "Dog subclass"
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              description: "Bark"
              type: string
    Lizard:
      description: "Lizard subclass"
      allOf:
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Lizard`
          properties:
            lovesRocks:
              description: "Loves rocks"
              type: boolean

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by loading the supplied OpenAPI 3.0.2 Pet/Cat example and compare the discriminator dropdown rendered for Pet with the one rendered for Cat. Trace the documentation schema-rendering entry point that produces these controls; done means the Cat view presents only its valid discriminator value rather than the full Pet variant list.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.