prance icon indicating copy to clipboard operation
prance copied to clipboard

Support `writeOnly` properties

Open alessiofachechi opened this issue 4 years ago • 0 comments

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

alessiofachechi avatar Nov 11 '21 14:11 alessiofachechi