Skip to content

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

@slessard

Description

@slessard

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions