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

Feat/add response validation middleware #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zucchinho
Copy link

@zucchinho zucchinho commented Mar 15, 2024

The OapiResponseValidator follows largely the same pattern as the OapiRequestValidator. A key difference is that the validation happens after the handler chain has been invoked, and it is obviously the response we are validating.

A wrapper around the underlying gin.ResponseWriter is needed to capture the response content. If the response is valid, it is written to the underlying writer.

In the case of bad responses, a 500 status code is returned.
If the route is not recognized, a 404 is returned.

Where feasible, common code is now shared between the 2 middlewares. This also facilitates creating a hybrid middleware which validates both requests and responses at some point in the future.

Move shared code into types and utils files
Add proper types for context keys to get rid of linter warning
Remove case for SecurityRequirementsError
Improve test coverage
@zucchinho
Copy link
Author

any chance of a review on this?

@jamietanna
Copy link
Member

Will come back to it after the release of v2.2.0 for oapi-codegen, which should be next couple of days :)

@zucchinho
Copy link
Author

Will come back to it after the release of v2.2.0 for oapi-codegen, which should be next couple of days :)

@jamietanna did the update to 2.2.0 go smoothly? i appear to acquired some conflicts here as a result, any use resolving these now or should i wait for v2 to stabilize?

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

Successfully merging this pull request may close these issues.

2 participants