question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Status Code and Header validation in response.

See original GitHub issue

I defined a path in my “openapi.yml” with a response defined in this way:

      responses:
        '302':
          headers:
            Location:
              schema:
                type: string
                format: uri
          description: Authorization Response

However if i send back an empty response with a different error code, or if I send back a "302 "response with “Location” header set to a non URL string, no errors are triggered also if i set “validateResponses” to “true”.

Looking in the repo code I cannot find the validation of status code and header in the response. Is this supported?

If no, i think that this type of validation could be very useful to avoid broking api specification and i think that i can work to add this type of validation, if this issue is approved as an enhancement request.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
efabriscommented, May 28, 2020

@cdimascio absolutely. I will start working on it tonight.

2reactions
cdimasciocommented, May 28, 2020

@efabris currently, only the body is validated in the response. this should be improved. would you be interested in taking a first attempt at a solution?

These are some key points to improve: (effectively the header schema must be added to the validation functions, then later the headers must be provided as input when the validation function is executed) https://github.com/cdimascio/express-openapi-validator/blob/master/src/middlewares/openapi.response.validator.ts#L249

https://github.com/cdimascio/express-openapi-validator/blob/master/src/middlewares/openapi.response.validator.ts#L172

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Validate Response Status using Rest Assured?
Steps to verify Response Status Code with Rest Assured. How to test response status code in API Testing? how to add assert on...
Read more >
HTTP Status Codes - REST API Tutorial
This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty...
Read more >
HTTP/1.1: Status Code Definitions
This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty...
Read more >
Add support for response header validation #130 - GitHub
You can add HTTP status codes to each of the endpoints. As HAPI routes don not directly have a property for status codes...
Read more >
What's an appropriate HTTP status code to return by a REST ...
If "validation failure" means that there is some client error in the request, then use HTTP 400 (Bad Request). For instance if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found