OAS 3.0: readOnly properties are included in request body examples
See original GitHub issueVersion: 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@amochohan,
$refworks by overwriting all of its sibling attributes, soreadOnlydoes not actually have effect in your example. You’ll need to use something like:Here’s a related discussion about combining
$refwith other attributes: https://github.com/swagger-api/swagger-ui/issues/3325#issuecomment-334139931.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 thePOSTexample, but they still show up in thePATCHone. SincePATCHis 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?