Redocly / Redocly/redoc

Schema is always overridden in the samples when using `allOf` in the preview

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

Nobody has claimed this yet.

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

Description

Describe the bug

I am extending a component schema by using allOf. The first component definition (TestPage) contains a property with type, properties and the rest of the schema of the component. The second (Page) one only contains the same property with only a description, which I want to be the same for all extending objects. When using the preview command in the cli, the document I see in the browser has a response sample with said overridden property marked as null, regardless of its definition.

To Reproduce
Steps to reproduce the behavior:

  1. Given this redocly.yaml file
    None

  2. And this OpenAPI file(s)

openapi: 3.1.0
info:
  title: Test
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestPage'
components:
  schemas:
    Page:
      type: object
      properties:
        page:
          type: integer
        total:
          type: integer
        content:
          description: Awesome description
    TestPage:
      allOf:
        - type: object
          properties:
            content:
              type: array
              items:
                $ref: '#/components/schemas/TestSummary'
        - $ref: '#/components/schemas/Page'
    TestSummary:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
  1. Run this command with these arguments... redocly ...
redocly preview-docs openapi.yaml
  1. See error
    The generated response sample for status 200 is this:
{
  "content": null,
  "page": 0,
  "total": 0
}

Expected behavior

I expected the property content declared in TestPage to contain its definition, regardless of being overridden in Page, since the second doesn't contain a schema.

{
  "content": [
    {
      "id": 0,
      "name": "This is a test"
    }
  ],
  "page": 0,
  "total": 0
}

Logs
-

OpenAPI description
-

Redocly Version(s)

1.19.0

Node.js Version(s)

v20.13.1

Additional context
-

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 supplied OpenAPI document by running redocly preview-docs openapi.yaml and inspect the preview response-sample generation for allOf schemas. Trace how the content property is resolved, then verify that the generated sample preserves the array of TestSummary objects while retaining the description from Page.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, documentation
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.