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

Is readOnly flag misused in the schema? #122

Closed
alexbudarov opened this issue Oct 27, 2023 · 3 comments
Closed

Is readOnly flag misused in the schema? #122

alexbudarov opened this issue Oct 27, 2023 · 3 comments

Comments

@alexbudarov
Copy link

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.

@alexbudarov
Copy link
Author

similar problem is described here: #103 (comment)

@arey
Copy link
Member

arey commented Nov 2, 2023

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.

@arey
Copy link
Member

arey commented Nov 26, 2023

See #125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants