question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAS 3.0: readOnly properties are included in request body examples

See original GitHub issue

Version: ft/oas3 branch, commit a1ce0e7b3c54d66534faf59599c6bce5f23656f2

In 3.0 specs, request body examples generated from the schema include read-only properties – but they should not be included in requests. The issue does not exist in 2.0 specs.

Spec:

openapi: 3.0.0
info:
  version: 0.0.0
  title: test

paths:
  /users:
    post:
      summary: Create a user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/User'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          example: 5
          readOnly: true
        name:
          type: string
          example: Bob

Expected result: Request body example is:

{
  "name": "Bob"
}

Actual result: Request body example includes the read-only property id:

{
  "id": 5,
  "name": "Bob"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
hkosovacommented, Oct 26, 2017

@amochohan, $ref works by overwriting all of its sibling attributes, so readOnly does not actually have effect in your example. You’ll need to use something like:

        example_attribute:
          readOnly: true
          allOf:
            - $ref: '#/components/schemas/AnotherModel'

Here’s a related discussion about combining $ref with other attributes: https://github.com/swagger-api/swagger-ui/issues/3325#issuecomment-334139931.

0reactions
Adeynackcommented, May 8, 2019

EDIT: Nevermind this.

Just realised it is an issue with the SwaggerDoc, not OpenAPI. The online editor display examples properly. The version we have offline does not. My apologies

Original post

I still have the same problem, observed in SwaggerDoc. I changed some properties to readOnly: true. They disappeared from the POST example, but they still show up in the PATCH one. Since PATCH is a write verb, I expect them not to show up in the example.

Should I post this here, since it is a closed issue (to be reopened) or should I create a new one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and ...
Read more >
How to declare a $ref property as readOnly in OpenAPI ...
It works on Swagger UI, but when you try to generate Client SDK (i.e. Java) the output Class are not correctly generated on...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
schemas - Redocly
The readOnly properties show in the request only. The following example uses the same ChessResult schema as the previous example. OAS 3.0OAS ......
Read more >
Hide a Request Field in Swagger API - Baeldung
Swagger provides an alternative property, readOnly, as well. We can use it to hide the specified field during update operations but still show ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found