Skip to content

Response validator not working when referencing same responses #576

Closed
@crudo

Description

@crudo

Describe the bug

It happens only if you have multiple responses referencing same file in multiple paths.

I have created a repo with this bug: https://github.com/crudo/express-openapi-validator-issue-2

Very similar to #553 but this time response validation is not working.

eg.

clusters > 200, 400
users > 200, 400
# 400 must reference the same response

Having:

get:
  tags:
    - Users
  description: Returns a list of users
  operationId: getUsers
  responses:
    "200":
      $ref: "../responses/users.yaml"
    "400":
      $ref: "../responses/400.yaml"

This will fail:

get:
  tags:
    - Clusters
  description: Returns a list of clusters
  operationId: getClusters
  responses:
    "200":
      $ref: "../responses/clusters.yaml"
    "400":
      $ref: "../responses/400.yaml"

This will NOT fail:

get:
  tags:
    - Clusters
  description: Returns a list of clusters
  operationId: getClusters
  responses:
    "200":
      $ref: "../responses/clusters.yaml"

It will not fail, if you reference response only once:

clusters > 200, 400
users > 200

or

clusters > 200
users > 200, 400

To Reproduce

https://github.com/crudo/express-openapi-validator-issue-2

Actual behavior

{
  "message": "Cannot read property 'content' of undefined"
}

Expected behavior

{
  "message": ".response should be array",
  "errors": [{
    "path": ".response",
    "message": "should be array",
    "errorCode": "type.openapi.validation"
  }]
}

Examples and context

https://github.com/crudo/express-openapi-validator-issue-2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions