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

Validation of headers in a response does not support data types other than string #709

Closed
slessard opened this issue Dec 16, 2022 · 0 comments · Fixed by #712
Closed

Validation of headers in a response does not support data types other than string #709

slessard opened this issue Dec 16, 2022 · 0 comments · Fixed by #712

Comments

@slessard
Copy link
Contributor

slessard commented Dec 16, 2022

The code to validate the headers in an HTTP response will always fail if the header's data type is anything other than string.

The code at https://github.com/getkin/kin-openapi/blob/v0.110.0/openapi3filter/validate_response.go#L92 gets the value for a given header. The header's value, by the nature of http, is a string. This string is then passed to the VisitJSON method at https://github.com/getkin/kin-openapi/blob/v0.110.0/openapi3/schema.go#L810. The VisitJSON method expects the value that is passed in to have already been converted into the appropriate Go type. Because the value hasn't been converted the VisitJSON method will return an error for any header that is supposed to be an integer, number, boolean, or array.

I believe the solution is to insert some code between lines 92 and 93. This inserted code should switch on the value of s.Value.Schema.Value.Type and convert the string accordingly.

It looks like the function decaodeValue at https://github.com/getkin/kin-openapi/blob/v0.110.0/openapi3filter/req_resp_decoder.go#L259 might do the kind conversion that is needed

slessard pushed a commit to slessard/kin-openapi that referenced this issue Dec 16, 2022
… schema

Previously the code assumed response headers were only strings. Now the code can validate any type of response header
@fenollp fenollp linked a pull request Dec 16, 2022 that will close this issue
slessard pushed a commit to slessard/kin-openapi that referenced this issue Dec 17, 2022
slessard pushed a commit to slessard/kin-openapi that referenced this issue Dec 17, 2022
slessard pushed a commit to slessard/kin-openapi that referenced this issue Dec 17, 2022
slessard pushed a commit to slessard/kin-openapi that referenced this issue Dec 17, 2022
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 a pull request may close this issue.

1 participant