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

read only fields appear in JSON request samples for POST request #1560

Closed
grundrauschen opened this issue Mar 25, 2021 · 2 comments
Closed

Comments

@grundrauschen
Copy link

Hello everyone,

As it seems, the bug #142 has reappeared.
As there did not seem to be an option to reopen the ticket, I am creating a new one.

I used the following code snippet as an example for the behaviour:

openapi: 3.0.3

info:
  title: "API for testing read-only values"
  version: "0.1.0"

tags:
- name: "Testendpoint"

paths:
  /tables:
    post:
      description: "Create a table"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TestTable"
      responses:
        200:
          description: "OK"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TestTable"

components:
  schemas:
    TestTable:
      type: object
      properties:
        id:
          type: "string"
          format: uuid
          readOnly: true
        inserted_at:
          type: string
          format: date-time
          description: "Date and Time at which the object was created"
          readOnly: true
        name:
          type: string
          description: "human-readable name"
      example:
        id: "7160f045-e24e-414e-891d-10fb5c9b8c5d"
        inserted_at: "2021-03-11T09:44:03Z"
        name: "Table1"

To create the documentation I used redoc-cli version 0.10.2.
NPM state the redoc version as 2.0.0-rc.48.

Screenshot 2021-03-25 at 18 58 25

Screenshot 2021-03-25 at 18 58 17

@RomanHotsiy
Copy link
Member

You have a literal example in your schema which redoc uses directly without any modifications.

It probably should remove fields from it. As a temporal workaround you can use the following schema:

openapi: 3.0.3

info:
  title: "API for testing read-only values"
  version: "0.1.0"

tags:
- name: "Testendpoint"

paths:
  /tables:
    post:
      description: "Create a table"
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TestTable"
      responses:
        200:
          description: "OK"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TestTable"

components:
  schemas:
    TestTable:
      type: object
      properties:
        id:
          type: "string"
          format: uuid
          readOnly: true
          example: "7160f045-e24e-414e-891d-10fb5c9b8c5d"
        inserted_at:
          type: string
          format: date-time
          description: "Date and Time at which the object was created"
          readOnly: true
          example: "2021-03-11T09:44:03Z"
        name:
          type: string
          description: "human-readable name"
          example: "Table1"

@grundrauschen
Copy link
Author

Thank you, I did not occur to me, that the examples are taken literally without filtering. Changing my schemas helped with this.

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

No branches or pull requests

2 participants