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 validation does not work when multiple response content-types are defined in the API #288

Open
tomasvalentaopenbean opened this issue Dec 7, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@tomasvalentaopenbean
Copy link

Are you using jest or chai?
Chai

Are you using OpenAPI 2, 3.0.X, or 3.1.0?
3.0.3

Describe the bug clearly
When API has defined multiple content-types as possible responses, the validation only picks up the first defined content-type and fails when the API returns the other content-type in the response.

Steps to reproduce the bug:

  1. Define an API that returns 2 content-types:
get:
  summary: Get Something
  operationId: getSomething
  responses:
    '200':
      content:
        text/csv:
          schema:
            type: string
            format: binary
        application/json:
          schema:
            type: array
            items:
              type: string
  1. Send a request that generates the 2nd content-type as a response
  2. An error is received (see below)
 AssertionError: expected res to satisfy API spec

expected res to satisfy the '200' response defined for endpoint 'GET /something' in your API spec

res did not satisfy it because: response must be string

res contained: {
  body: [
    'text1',
    'text2',
    'text3',
    'text4',
    'text5'
  ]
}

The '200' response defined for endpoint 'GET /something' in API spec: {
  '200': {
    description: "Get something.",
    content: {
      'text/csv': { schema: { type: 'string', format: 'binary' } },
      'application/json': {
        schema: { type: 'array', items: { type: 'string' } } }
      }
    }
  }
}

What did you expect to happen instead?
Validation should pass because the response is valid.

Are you going to resolve the issue?

@tomasvalentaopenbean tomasvalentaopenbean added the bug Something isn't working label Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant