Redocly / Redocly/redoc

Issue with dropdown options for discriminated schema in request body

Open
#1,288 3 comments 6 reactions 1 assignee View on GitHub

@AlexVarchuk is already working on this.

Since Aug 8, 2023.

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

Description

When defining a schema for a request body that uses oneOf and a discriminator with a mapping, the dropdowns show the option for the base item as well, which is incorrect and should not be defined as an option.

redoc_issue

Simplified Example:

openapi: 3.0.0
info:
  title: test
  version: 1.0.0
    
paths:
  '/test/{testId}':
    patch:
      summary: Broken test
      operationId: updateSchedule
      parameters:
        - $ref: '#/components/parameters/TestIdPath'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/TestRequestBody'
      responses:
        '200':
          $ref: '#/components/responses/TestModel'
          
          
components:
  parameters:
    TestIdPath:
      in: path
      required: true
      name: testId
      schema:
        type: integer
  
  schemas:
    TestRequestBody:
      allOf:
        - $ref: '#/components/schemas/TestModel'
        - description: Additional description
    
    BaseTestModel:
      type: object
      properties:
        baseProperty:
            type: string
    
    SubTestModel1:
      allOf:
        - $ref: '#/components/schemas/BaseTestModel'
        - type: object
          properties:
            subProp1:
              type: string
      
    SubTestModel2:
      allOf:
        - $ref: '#/components/schemas/BaseTestModel'
        - type: object
          properties:
            subProp2:
              type: string
    
    TestModel:
      oneOf:
        - $ref: '#/components/schemas/SubTestModel1'
        - $ref: '#/components/schemas/SubTestModel2'
      discriminator:
        propertyName: baseProperty
        mapping:
          ONE: '#/components/schemas/SubTestModel1'
          TWO: '#/components/schemas/SubTestModel2'
  
  
  responses:
    TestModel:
      description: A test model
      content:
        application/vnd.yellowfin.api-v1+json:
          schema:
            $ref: '#/components/schemas/TestModel'

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.