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

Question / feature proposal: Using the validator with httptest.ResponseRecorder #40

Open
jamietanna opened this issue Dec 8, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@jamietanna
Copy link

jamietanna commented Dec 8, 2023

I'm looking at adding libopenapi to https://gitlab.com/jamietanna/httptest-openapi, a library I've got for writing (unit) tests with Go's net/http handlers by validating the response matches an OpenAPI spec.

I've looked at using this library to give me full OpenAPI 3.0 and 3.1 support, instead of Kin's OpenAPI 3.0 only, but noticed that I couldn't use it right away.

In the test code i.e. https://gitlab.com/jamietanna/httptest-openapi/-/blob/v0.3.0/openapi3/validator.go?ref_type=tags#L95 we only have access to a httptest.ResponseRecorder whereas the library expects an http.Response.

Would it be of interest to add support for providing a httptest.ResponseRecorder or should I instead look at how to convert between the two types?

@jamietanna
Copy link
Author

jamietanna commented Dec 8, 2023

I guess I could pass in a httptest.ResponseRecorder but couldn't remember whether they're safe for production use cases, as the middleware is expected for prod code

@daveshanley
Copy link
Member

Hi Jamie,

I'm not quite sure what you mean, would you be able to help me understand?

I'd be happy to help add in support to allow you get this working, I just need more help understanding the use case.

@jamietanna jamietanna changed the title Question / feature proposal: Using the validator with http.HandlerFunc Question / feature proposal: Using the validator with httptest.ResponseRecorder Dec 9, 2023
@jamietanna
Copy link
Author

Hey, thank you! That'll teach me from raising an issue on mobile 😅

I'd originally phrased the question correctly, then second-guessed myself, and amended it.

I've amended the description to note that I'm actually trying to use this with httptest.ResponseRecorder, not for use with a http.Response.

@daveshanley
Copy link
Member

I can't see why not, I used the httptest.ResponseRecorder in the tests myself. I will have a look at the code and see how much work it would be.

@daveshanley daveshanley added the enhancement New feature or request label Jan 18, 2024
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