openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

Array with unspecified item specification passes validation

Open msladecek opened this issue 6 years ago • 0 comments

An array without specified items: passes validation.

From swagger.io:

the items keyword is required in arrays

Example

(correct version)

definitions:
  Pet:
    required:
      - id
      - name
    properties:
      id:
        type: integer
        format: int64
      name:
        type: string
      tag:
        type: string
  Pets:
    type: object
    properties:
      payload:
        type: array
        items:
          $ref: '#/definitions/Pet'

(buggy version, shares the same Pet definition)

  Pets:
    type: object
    properties:
      payload:
        type: array
      items:
        $ref: '#/definitions/Pet'

Due to bad indentation, items is interpreted as another property of Pets and payload array is without item specification. This schema passes through validator, but can't be used in (eg. swagger-ui). Since the validator let's this pass, a bug like this can be very difficult to find, especially if it's part of a big code diff.

msladecek avatar Feb 12 '19 09:02 msladecek