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

Support for Status Code and Header validation in response. #308

Open
efabris opened this issue May 26, 2020 · 5 comments
Open

Support for Status Code and Header validation in response. #308

efabris opened this issue May 26, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@efabris
Copy link
Contributor

efabris commented May 26, 2020

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.

@cdimascio cdimascio added the enhancement New feature or request label May 28, 2020
@cdimascio
Copy link
Owner

cdimascio commented 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

@efabris
Copy link
Contributor Author

efabris commented May 28, 2020

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

@cdimascio
Copy link
Owner

@efabris how are things going? feel free to reach out on gitter if you need help. best

@efabris
Copy link
Contributor Author

efabris commented Jun 24, 2020

@cdimascio sorry but after a first look, I no longer had time to continue. The new arrival in the family, my daughter, and my job keep me very busy. I hope to be able to work on it in July.

@cdimascio
Copy link
Owner

cdimascio commented Jun 24, 2020

@efabris congrats on the new arrival! let me know if you decide to pick it up in july

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

No branches or pull requests

2 participants