Redocly / Redocly/redoc

Problem with rendering multiple schema examples in complex json schema.

Open
#786 4 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

when using oneOf, only one of the schema examples renders. Redoc doesn't seem to have the option for picking from the oneOf.

In my example below, Redoc only renders the example from AdministrativeArea.

"schema": {
  "type": "object",
  "properties": {
    "hits": {
       "type": "integer",
       "format": "int32"
     },
    "data": {
      "type": "array",
      "items": {
        "oneOf": [
        {
           "$ref": "#/components/schemas/AdministrativeArea"
        },
        {
           "$ref": "#/components/schemas/EmploymentCategory"
        }, ...

However, multiple examples can be rendered if the schema is simplified as below. But our openapi spec is more complex than it.

 "schema": {
    "description": "Enhanced entity",
    "oneOf": [
      {
        "$ref": "#/components/schemas/OrganizationResponse"
      },
      {
        "$ref": "#/components/schemas/PersonResponse"
      }
    ]
  }

Is there a bug in my OpenAPI spec or is it a bug with Redoc? Any help is appreciated. Thanks in advance!

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

Start by reproducing the nested oneOf schema example and compare it with the simplified oneOf example shown in the issue. Check how Redoc renders examples for array items and referenced schemas, then verify the result against the OpenAPI specification; done means the reported complex schema behavior is explained and corrected or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, react, typescript
Domain
api, documentation, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.