Request body schema validations are skipped when using multiple external refs
hiuxmaycry opened this issue · comments
Describe the bug
When you use schemas that are defined in an external file and try to reuse this schema several times, the validations to the schema are completely ignored
To Reproduce
Create a an external file external.ref.yaml
with the next content:
NewPet:
type: object
additionalProperties: false
required:
- name
properties:
name:
type: string
nullable: true
tag:
type: string
And then create a simple API with the next 2 post paths:
/pets1:
post:
operationId: addPet1
requestBody:
required: true
content:
application/json:
schema:
$ref: external.ref.yaml#/NewPet
responses:
'200':
description: pet response
content:
application/json: {}
/pets2:
post:
operationId: addPet2
requestBody:
required: true
content:
application/json:
schema:
$ref: external.ref.yaml#/NewPet
responses:
'200':
description: pet response
content:
application/json: {}
Actual behavior
See that the schema validations for post1 and post2 are not applied.
Expected behavior
Validations that are defined in the API should be applied.
Fox example, sending to POST to /pets1 with body { "name": null } should fail
Examples and context
See last commit from this repo to reproduce the error, there are 2 new tests failing due to this bug https://github.com/hiuxmaycry/express-openapi-validator