Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
renke0 opened this issue Aug 26, 2024 · 2 comments

Comments

@renke0
Copy link

renke0 commented Aug 26, 2024

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
-

@AlexVarchuk
Copy link
Collaborator

hi @renke0, thank you for the issue.
According to OpenAPI 3.1 specification, you should avoid using requestBody inside the get operation.
Otherwise, if you put in inside parameters, or response it works well.
Is it necessary to use requestBody inside the GET request in your case?

@AlexVarchuk AlexVarchuk transferred this issue from Redocly/redocly-cli Aug 28, 2024
@renke0
Copy link
Author

renke0 commented Sep 17, 2024

Hi @AlexVarchuk. You are correct, and the spec has a GET operation only because it was generated by default by the IDE and I forgot to change it while writing the example. Changing it to POST (or any other verb that should support request bodies) has the same effect.

Edit: I updated the issue description to use POST instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants