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

Support writeOnly properties #119

Open
alessiofachechi opened this issue Nov 11, 2021 · 0 comments
Open

Support writeOnly properties #119

alessiofachechi opened this issue Nov 11, 2021 · 0 comments

Comments

@alessiofachechi
Copy link

alessiofachechi commented Nov 11, 2021

Expected Behaviour

As stated on the docs:

You can use the readOnly and writeOnly keywords to mark specific properties as read-only or write-only. This is useful, for example, when GET returns more properties than used in POST – you can use the same schema in both GET and POST and mark the extra properties as readOnly. readOnly properties are included in responses but not in requests, and writeOnly properties may be sent in requests but not in responses.

So writeOnly properties should not be rendered in responses.

Minimal Example Spec

openapi: "3.0.0"
info:
  title: Sample API
  description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
  version: "0.1"
paths:
  /users:
    post:
      summary: Create a user.
      requestBody:
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
      responses:
        '201':
          description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          example: 1
          readOnly: true
        suggestedId:
          type: integer
          example: 100
          writeOnly: true

Actual Behaviour

writeOnly properties are rendered in responses.

Steps to Reproduce

Just render the spec above. The write only suggestedId will be rendered also in the PATCH response also.

Environment

  • OS: Docker container
  • Python version: 3.6+
  • Swagger/OpenAPI version used: 3.0.0+
  • Backend: openapi-spec-validator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant