Redocly / Redocly/redoc

List of Object referenced in OneOf is not generating sample response

Open
#2,396 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Redoc possibly not creating the 'Sample response' when using OneOf referencing array of objects(same type).

Below is the sample API definition:

openapi: 3.0.3
info:
  title: Simple Pets API
  description: |-
    This is a sample Pets API showcasing some `oneOf` scenarios
  version: 0.0.1
tags:
  - name: pets
    description: Everything about your Pets
paths:
  /animals:
    get:
      tags:
        - pets
      summary: Get pets from catalog
      description: Returns a list of pets found on the server
      operationId: getAnimals
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                oneOf: 
                  - $ref: '#/components/schemas/Cat'
                  - $ref: '#/components/schemas/Dog'            
components:
  schemas:
    Animal:
      type: object
      properties:
        breed:
          type: string
          example: poodle
    Cat:
      type: array
      items:
        $ref: '#/components/schemas/Animal'
    Dog:
      type: array
      items:
        $ref: '#/components/schemas/Animal'

Actual Behaviour: No sample response generated in swagger documentation

Expected behaviour: Sample response for array of objects need to generated in the swagger

"[
{
"breed":"poodle"
}
]"

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 issue in Redoc with the OpenAPI definition provided in the report, focusing on sample response generation for oneOf schemas referencing arrays. Trace that generation path and add coverage for the example; done means the documentation shows the expected array containing an object with the breed value.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.