kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
895 stars 237 forks source link

Only validate first item when using ref in array #834

Open fabien-renaud opened 2 years ago

fabien-renaud commented 2 years ago

When using $ref on array schema, it only validate (and apply default value to) the first item, ignoring others.

Example

      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Todo'
                - type: array
                  items:
                    - $ref: '#/components/schemas/Todo'

This works

curl --request POST 'localhost:11000/v1/todo' \
--header 'Content-Type: application/json' \
--data-raw '[
    {"valide": "json"}, {"valide": "json"}
]'

This also works

curl --request POST 'localhost:11000/v1/todo' \
--header 'Content-Type: application/json' \
--data-raw '[
    {"valide": "json"}, {"invalide": "json"}
]'

This issue only occurs when using $ref on array, it works well when declaring schema directly on the requestBody, not using $ref.