openapi-library / OpenAPIValidators

Use Jest or Chai to assert that HTTP responses satisfy an OpenAPI spec
MIT License
189 stars 35 forks source link

If the endpoint response is described only by HTTP status without a body, the comparison will fail #299

Open batyshkaLenin opened 9 months ago

batyshkaLenin commented 9 months ago

Are you using jest or chai? jest version 27.0.6 and jest-openapi version 0.14.2

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

Describe the bug clearly If the endpoint response is described only by HTTP status without a body, the comparison will fail.

Steps to reproduce the bug:

  1. We describe an endpoint, for example, as follows (according to the official documentation, an empty request body should be described in this way):
    /test:
    get:
      summary: Test summary
      responses:
        201:
          description: Test description
  2. Our endpoint's response will look like this
    const result = { status:  201 };
    expect(result).toSatisfyApiSpec();
  3. The error will look like this
    
    Error: expect(received).toSatisfyApiSpec() // Matches 'received' to a response defined in your API spec, then validates 'received' against it

expected received to satisfy the '201' response defined for endpoint 'GET /test' in your API spec

received did not satisfy it because: response must be null

received contained: { body: {}, text: 'Created' }

The '201' response defined for endpoint 'GET /test' in API spec: { '201': { description: 'Test description' } }



**What did you expect to happen instead?**
I expect the test to verify that there is a description for the HTTP status and the lack of a request body will not return an error. 

**Are you going to resolve the issue?**
I'm not sure if I'm gonna make it