Redocly / redoc

📘 OpenAPI/Swagger-generated API Reference Documentation
https://redocly.github.io/redoc/
MIT License
23.68k stars 2.31k forks source link

Issue with dropdown options for discriminated schema in request body #1288

Open zimmyg opened 4 years ago

zimmyg commented 4 years ago

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'
joseneto-payroc commented 1 year ago

I'm having this exact problem, does anybody know a workaround?

RomanHotsiy commented 1 year ago

This is weird. It used to work correctly. Still works correctly for the Petstore case. We'll take a look.

cc @AlexVarchuk

joseneto-payroc commented 1 year ago

Hi Roman, this extension worked for me. https://redocly.com/docs/redoc/redoc-vendor-extensions/#x-explicitmappingonly

But, when I thought I had everything sorted. I stumbled across another bug =/ https://github.com/Redocly/redoc/issues/1031