Redocly / Redocly/redoc

redoc-cli - discriminators handled neither correctly nor consistently

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

Nobody has claimed this yet.

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

Description

Consider the following specs

openapi: 3.1.0
info:
  title: Sample API
  version: '1.0'
  contact:
    email: some@email.com
  description: Api description.
tags:
  - name: sample tag
    description: tag description
servers:
  - url: http://localhost:3000
paths:
  /sample-path:
    post:
      summary: Sample op
      operationId: sample-op
      description: Op description.
      requestBody:
        content:
          application/json:
            schema:
              title: Test
              type: object
              properties:
                prop1:
                  title: Test Polymorph
                  oneOf:
                    - $ref: '#/components/schemas/test1'
                    - $ref: '#/components/schemas/test2'
                  discriminator:
                    propertyName: testType
                    mapping:
                      ONE: '#/components/schemas/test1'
                      TWO: '#/components/schemas/test2'
                prop2:
                  $ref: '#/components/schemas/testPolymorph'
      tags:
        - sample tag
  /another-path:
    post:
      summary: Another op
      operationId: another-op
      description: Another op description.
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/testPolymorph'
      tags:
        - sample tag
components:
  schemas:
    test1:
      title: Test - Variant 1
      type: object
      properties:
        testType:
          type: string
        testOne:
          type: string
    test2:
      title: Test Variant 2
      type: object
      properties:
        testType:
          type: string
        testTwo:
          type: number
    testPolymorph:
      title: Test Polymorph
      discriminator:
        propertyName: testType
        mapping:
          ONE: '#/components/schemas/test1'
          TWO: '#/components/schemas/test2'
      oneOf:
        - $ref: '#/components/schemas/test1'
        - $ref: '#/components/schemas/test2'

All of the prop1, prop2 should be the same (only difference is that $ref is expanded in prop1) and also prop2 and request schema of /another-path should be the same (same $ref target). All of them should have select box on testType property.

However, we can see the output here.

image

I'm using redoc-cli via npm in the latest version

$ redoc-cli --version
0.13.20

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

Reproduce the rendering with the provided OpenAPI 3.1 specification using redoc-cli 0.13.20. Compare prop1, prop2, and the /another-path request schema; done means each renders the same discriminator select box for testType despite the expanded or referenced schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, documentation
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.