Redoc: Cannot show properly when discriminator is located in relative document

Created on 5 Jul 2018  路  3Comments  路  Source: Redocly/redoc

OpenAPI version: 3.0.1

openapi.yaml

openapi: "3.0.1"
info:
  version: 1.0.0
  title: Swagger Petstore
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          type: integer
          format: int32
      responses:
        "200":
          description: A paged array of pets
          content:
            application/json:
              schema:
                $ref: 'definitions.yaml#/Pets'
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        "201":
          description: Null response
  /pets/{petId}:
    parameters:
      - name: petId
        in: path
        required: true
        description: The id of the pet to retrieve
        type: string
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      responses:
        "200":
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: 'definitions.yaml#/Pet'

definitions.yaml

Pets:
  type: array
  items:
    $ref: '#/Pet'
Error:
  required:
    - code
    - message
  properties:
    code:
      type: integer
      format: int32
    message:
      type: string
Pet:
  type: object
  required:
    - pet_type
  properties:
    pet_type:
      type: string
  discriminator:
    propertyName: pet_type
    mapping:
      cachorro: '#/Dog'
Cat:
  allOf:
    - $ref: '#/Pet'
    - type: object
      # all other properties specific to a `Cat`
      properties:
        name:
          type: string
Dog:
  allOf:
    - $ref: '#/Pet'
    - type: object
      # all other properties specific to a `Dog`
      properties:
        bark:
          type: string
Lizard:
  allOf:
    - $ref: '#/Pet'
    - type: object
      # all other properties specific to a `Lizard`
      properties:
        lovesRocks:
          type: boolean
bug help wanted

All 3 comments

There are two issues here.
1) this is the limitation of the discriminator. In order to work your schemas should be all located in the definitions section of the OpenAPI document.

To workaround this just reference definitions.yaml from the definitions section of your spec:

openapi: "3.0.1"
info:
  version: 1.0.0
  title: Swagger Petstore
definitions:
  $ref: 'definitions.yaml'
paths:
 # ...

2) even is you apply this woraround it wont work, now because of ReDoc has a bug with mapping field if it is located in relative document (pointers are not updated when mergin it into one document).

This have to be fixed. I'm not sure yet how to fix it properly.
PR's are welcome.

@wlaoh no, it won't help. The issue is caused by definitions being in different documents: when ReDoc merges them into one big spec mapping field $refs are not updated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skllcrn picture skllcrn  路  3Comments

jaroslawr picture jaroslawr  路  3Comments

typekpb picture typekpb  路  4Comments

bmarwell picture bmarwell  路  3Comments

RomanHotsiy picture RomanHotsiy  路  3Comments