Is readOnly flag misused in the schema?
Closed this issue · 3 comments
In the openapi.yml, for the PetType definition, "id" property is marked as readOnly:
PetType:
title: Pet type
description: A pet type.
allOf:
- $ref: '#/components/schemas/PetTypeFields'
- type: object
properties:
id:
title: ID
...
readOnly: true
required:
- id
According to the OpenAPI specification, this means:
Declares the property as "read only". This means that it MAY be sent as part of a response but SHOULD NOT be sent as part of the request.
see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#fixed-fields-20
This means: when I call "addPet" operation to create a new Pet, by specification I shouldn't be able to specify Pet -> type -> id field. Though it is this particular field which is responsible for handling association.
Example of a problem that may occur - is the OpenAPI client generator.
See this change: OpenAPITools/openapi-generator#1582
If using this code generator, the generated PetType pojo will not have a PetType#setId() attribute.
Summary:
I think that readOnly flag is misused in this schema, and it shouldn't be used, for objects that are used as request parameters.
similar problem is described here: #103 (comment)
I don't know if the readOnly
flag is misused or not, but when we call the POST /api/owners/{ownerId}/pets
endpoint without giving pet id
and name
we have an error 400. Thus there is an issue that we have to fix.