Skip to content

Schema properties declared with oneOf ignore the readonly flag on request samples #2574

Open
@renke0

Description

@renke0

Describe the bug

I have a component schema (Body) with a property (prop2) that should be readonly and its value can be either a number or an enum key. I declared it with oneOf to accomplish the desired result, and the property is correctly hidden when I check the Request Body Schema in the preview doc. Unfortunately, the same is not true for the generated sample request in the sidebar.

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:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Body'
      responses:
        '200':
          description: OK
components:
  schemas:
    Body:
      type: object
      properties:
        prop1:
          type: string
        prop2:
          readOnly: true
          oneOf:
            - $ref: '#/components/schemas/Enum'
            - type: number
    Enum:
      type: string
      enum:
        - value1
        - value2
  1. Run this command with these arguments... redocly ...
 redocly preview-docs openapi.yaml
  1. See error
    The generated request sample payload contains the field that should be readonly
{
  "prop1": "string",
  "prop2": "value1"
}

Expected behavior
The prop2 field should be omitted, in the same fashion it is in the Request Body Schema definition.

{
  "prop1": "string"
}

Logs
-

OpenAPI description
-

Redocly Version(s)

1.19.0

Node.js Version(s)

v20.13.1

Additional context
-

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions