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

Properties marked as readOnly are shown in POST payload examples #1238

Open
Perni1984 opened this issue Apr 21, 2020 · 3 comments
Open

Properties marked as readOnly are shown in POST payload examples #1238

Perni1984 opened this issue Apr 21, 2020 · 3 comments

Comments

@Perni1984
Copy link

I am using the latest version from I am trying to mark some of my properties in the schema as readOnly:

openapi: 3.0.0
info:
    title: Readonly Example
    version: 0.0.1
servers:
    - url: https://myserver.com/api/v1
      description: Test Environment
paths:
    /backend/article:
        get:
            summary: Returns a list with all articles in the system
            responses:
                '200':
                    description: A list of all event series
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ArrayOfArticles'
            tags:
                - Backend/Article
        post:
            summary: Creates a new article
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/Article'
                required: true
            responses:
                '200':
                    description: Success
            tags:
                - Backend/Article
components:
    schemas:
        ArrayOfArticles:
            type: array
            items:
                $ref: '#/components/schemas/Article'
        Article:
            type: object
            properties:
                id:
                    type: string
                    readOnly: true
                title:
                    type: string
                content:
                    type: string
                createdAt:
                    type: string
                    readOnly: true
                updatedAt:
                    type: string
                    readOnly: true
            required:
                - id
                - title
                - content
                - createdAt
                - updatedAt
            example:
                id: 1e8b472d03s6ae24457f15a2
                title: My Article 01
                content: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean arcu arcu, finibus sed mattis in, placerat in justo. Proin feugiat semper laoreet.
                updatedAt: 2020-04-06T17:14:37+02:00
                createdAt: 2020-04-06T17:14:37+02:00

This gets rendered as follows:
image

In the POST request body schema the properties id, updatedAt, createdAt are correctly stripped out.
image

Unfortunately the sample values are getting displayed in the sample payload of the POST request.
image

My expectation would be that those properties are getting stripped out from the sample payload in the POST request aswell. Am I missing something?

@Perni1984
Copy link
Author

A viable workaround as for now seems to be to provide the examples directly in the GET response and POST request definitions and not in the components section:

openapi: 3.0.0
info:
    title: Readonly Example
    version: 0.0.1
servers:
    - url: https://myserver.com/api/v1
      description: Test Environment
paths:
    /backend/article:
        get:
            summary: Returns a list with all articles in the system
            responses:
                '200':
                    description: A list of all event series
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ArrayOfArticles'
                            example:
                                id: 1e8b472d03s6ae24457f15a2
                                title: My Article 01
                                content: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean arcu arcu, finibus sed mattis in, placerat in justo. Proin feugiat semper laoreet.
                                updatedAt: 2020-04-06T17:14:37+02:00
                                createdAt: 2020-04-06T17:14:37+02:00
            tags:
                - Backend/Article
        post:
            summary: Creates a new article
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/Article'
                        example:
                            title: My Article 01
                            content: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean arcu arcu, finibus sed mattis in, placerat in justo. Proin feugiat semper laoreet.
                required: true
            responses:
                '200':
                    description: Success
            tags:
                - Backend/Article
components:
    schemas:
        ArrayOfArticles:
            type: array
            items:
                $ref: '#/components/schemas/Article'
        Article:
            type: object
            properties:
                id:
                    type: string
                    readOnly: true
                title:
                    type: string
                content:
                    type: string
                createdAt:
                    type: string
                    readOnly: true
                updatedAt:
                    type: string
                    readOnly: true
            required:
                - id
                - title
                - content
                - createdAt
                - updatedAt

image
image

The POST request payload example now correctly does not render id, updatedAt and createdAt fields:
image
image

@RomanHotsiy
Copy link
Member

@Perni1984 when there is a implicit example on a schema Redoc uses it directly without any changes.

As a workaround, you can define examples on each field vs on the schema.

mik-laj pushed a commit to apache/airflow that referenced this issue Nov 8, 2021
Add an example based on the workaround described in Redocly/redoc#1238
jedcunningham pushed a commit to apache/airflow that referenced this issue Dec 7, 2021
Add an example based on the workaround described in Redocly/redoc#1238

(cherry picked from commit e6ccfae)
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Mar 10, 2022
Add an example based on the workaround described in Redocly/redoc#1238

(cherry picked from commit e6ccfaea822f9241e380e04014ffd698b7845b9a)

GitOrigin-RevId: a431a14bdeac7e53ae83ad728bd1cc527faa990c
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Jun 4, 2022
Add an example based on the workaround described in Redocly/redoc#1238

(cherry picked from commit e6ccfaea822f9241e380e04014ffd698b7845b9a)

GitOrigin-RevId: a431a14bdeac7e53ae83ad728bd1cc527faa990c
@NickUfer

This comment was marked as outdated.

kosteev pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Jul 10, 2022
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Aug 27, 2022
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Oct 4, 2022
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
aglipska pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Oct 7, 2022
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Dec 7, 2022
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
leahecole pushed a commit to GoogleCloudPlatform/composer-airflow that referenced this issue Jan 27, 2023
Add an example based on the workaround described in Redocly/redoc#1238

GitOrigin-RevId: e6ccfaea822f9241e380e04014ffd698b7845b9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment