Redocly / Redocly/redoc

Discriminator / OneOf broken when using external file reference

Open
#862 10 comments 7 reactions 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

The discriminator functionnality is broken when using with external files. Here's a reproducible test case :

openapi: 3.0.0
info:
  title: test
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: test
          content:
            'application/json':
              schema:
                oneOf:
                  - $ref: './external-file.yaml#/components/schemas/simpleObject'
                  - $ref: './external-file.yaml#/components/schemas/complexObject'
                discriminator:
                  propertyName: objectType

## external-file.yaml :
openapi: 3.0.0
components:
  schemas:
    simpleObject:
      type: object
      required:
        - objectType
      properties:
        objectType:
          type: string
    complexObject:
      type: object
      required:
        - objectType
      properties:
        objectType:
          type: string

And when we try to see the responses object in ReDoc, we have the following error :

2019-03-21 10_07_31-MPD API PRIVEE - NFC 1 3

I tried to debug it quickly, and I figured out that in this case, the oneOf variable is empty : https://github.com/Rebilly/ReDoc/blob/master/src/components/Schema/Schema.tsx#L43

Another related issue (I think) : if we remove the discriminator part, it will work but the schemas names are not displayed correctly (object instead of simpleObject for example) :

2019-03-21 10_14_57-MPD API PRIVEE - NFC 1 3

Please tell me if you need more informations to fix it, thanks !

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 issue with the provided OpenAPI document and external-file.yaml, then inspect oneOf handling at src/components/Schema/Schema.tsx around line 43. Compare the discriminator case with the working case without discriminator; done means externally referenced schemas render under oneOf and display their schema names correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation, frontend
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.