openapi-library / OpenAPIValidators

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

Options to specify output #245

Open rnphilp opened 3 years ago

rnphilp commented 3 years ago

OpenAPI version 3

Is your feature request related to a problem? Please describe. When using the toSatisfyApiSpec function, the output often overruns the history limit of the terminal. This is the case when the API route being tested returns an array of items (even if only one of the objects in the whole array is invalid), or when running a full test suite, where there are multiple errors returned. The output of the body response can be too large, making it difficult/impossible to navigate to the actual issues, when the key information is just the initial message at the top.

Describe the solution you'd like An options object that passed into the function allowing you to suppress certain sections of the output. Something like:

toSatisfyApiSpec({ message: true, response: false, schema: false })

Everything can be true by default to avoid changing the current functionality.

Describe alternatives you've considered Reducing the request body logs to remove the valid items in the array and only include the errors. So the output would be more like:

{
  my_response: [
    ...
    {
       foo: 'bar',
       error: 'in_just_this_object',
    }
    ...
  ]
}

Or just displaying a reduced snapshot of that section of the body, with say 5 lines above and below.

Additional context No

Are you going to resolve the issue? Not currently got the opportunity.

rwalle61 commented 2 years ago

Hi @rnphilp, thanks for raising this! Would you mind recreating this with our recreation template, so we can see exactly which output is too verbose?

For context, some of the error output comes from our validation dependency, but we are the ones deciding to output the whole response body, to aid debugging (but in this case it can be improved).

Just as a note - if our output overruns the history limit of the terminal because many tests are failing their toSatifyApiSpec() assertions, I'd suggest running and fixing those tests one by one.

Thanks for bringing this to our attention 🙂