Redocly / Redocly/redoc

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

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

Nobody has claimed this yet.

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

Description

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
-

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 running redocly preview-docs openapi.yaml with the OpenAPI example and compare the Request Body Schema with the generated request sample in the sidebar. Trace the request-sample generation entry point for readOnly properties inside oneOf schemas; done means prop2 is omitted from the sample while remaining hidden in the schema view.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.