redoc icon indicating copy to clipboard operation
redoc copied to clipboard

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

Open renke0 opened this issue 1 year ago • 3 comments

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 -

renke0 avatar Aug 26 '24 09:08 renke0

Hi @renke0, thank you for the issue. We know this problem. For now, to get your expected behavior you can replace the order of your items inside AllOf.

AlexVarchuk avatar Aug 28 '24 09:08 AlexVarchuk

Hi @renke0, thank you for the issue. We know this problem. For now, to get your expected behavior you can replace the order of your items inside AllOf.

moncefdhk999 avatar Aug 30 '24 17:08 moncefdhk999

I recover my github which now many people use to destroy our global system

moncefdhk999 avatar Aug 30 '24 17:08 moncefdhk999