Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response validator not working when referencing same responses #576

Closed
crudo opened this issue Apr 12, 2021 · 3 comments
Closed

Response validator not working when referencing same responses #576

crudo opened this issue Apr 12, 2021 · 3 comments

Comments

@crudo
Copy link
Contributor

crudo commented Apr 12, 2021

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

crudo added a commit to crudo/express-openapi-validator that referenced this issue Apr 13, 2021
@LarsV123
Copy link

Is there a fix/workaround for this? Having some trouble splitting my OpenAPI-spec into multiple files and I suspect this is the cause.

crudo added a commit to crudo/express-openapi-validator that referenced this issue Aug 17, 2021
@crudo
Copy link
Contributor Author

crudo commented Aug 17, 2021

@LarsV123 Hey, looks like adding this to config solves my issue. https://github.com/cdimascio/express-openapi-validator#%EF%B8%8F-refparsermode-optional

$refParser: {
  mode: 'dereference',
},

@crudo crudo closed this as completed Aug 17, 2021
@crudo
Copy link
Contributor Author

crudo commented Aug 17, 2021

@LarsV123 Hey, looks like adding this to config solves my issue. https://github.com/cdimascio/express-openapi-validator#%EF%B8%8F-refparsermode-optional

$refParser: {
  mode: 'dereference',
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants