Redocly / Redocly/redoc

Properties marked as readOnly are shown in POST payload examples

Open
#1,238 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

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?

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

Reproduce the behavior with the supplied OpenAPI example and trace the request sample payload generation path. Verify how the POST request schema removes readOnly properties, then ensure the generated sample payload follows the same filtering; done when id, createdAt, and updatedAt are absent from that payload.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.