SchemaValidator fails to validate schema with array as a root element with items containing readOnly/writeOnly properties

Issue #240 resolved
Mayur Patel created an issue

Schema with array as a root element with items containing readOnly/writeOnly properties are not validated properly.

Validator would not honor readOnly/writeOnly properties appropriately (Inside request/response schemas)

Example:

[

{

"notReadOnly":"abc",

"readOnly": "123"

}

]

above validating above json as response schema against swagger below would complain about absence of writeOnly property.

openapi: 3.0.0
info:
  version: 1.0.0
  title: RequiredReadOnly
servers:
  - url: /
paths:
  /readOnly:
    patch:
      summary: patch an item
      requestBody:
        description: patched
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReadOnlyArray'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadOnlyArray'
        '401':
          description: Not authenticated
        '403':
          description: Not authorized
components:
  schemas:
    ReadOnly:
      type: object
      properties:
        readOnly:
          type: string
          readOnly: true
          example: 'read'
        notReadOnly:
          type: string
          example: 'abc'
        writeOnly:
          type: string
          writeOnly: true
          example: 'write'
      required:
        - readOnly
        - notReadOnly
        - writeOnly
    ReadOnlyArray:
      type: array
      items:
        $ref: '#/components/schemas/ReadOnly'

Comments (5)

  1. Log in to comment