Skip to content

decodeStyledParameter has an inconsistency for arrays in query #989

@TheSadlig

Description

@TheSadlig

Hi,

I noticed some inconsistencies while using arrays in query.

When the schema is an array and;

  1. The query is empty, the function returns nil
  2. The query is not empty, the function returns []interface{nil}

This can be reproduced with the following test cases (to add in https://github.com/getkin/kin-openapi/blob/master/openapi3filter/req_resp_decoder_test.go#L859 ) :

{
	name:  "no param, for arrays",
	param: &openapi3.Parameter{Name: "something", In: "query", Schema: stringArraySchema},
	query: "",
	want:  nil,
	found: false,
	err:   nil,
},
{
	name:  "missing param, for arrays",
	param: &openapi3.Parameter{Name: "something", In: "query", Schema: stringArraySchema},
	query: "foo=bar",
	want:  nil, // Will fail
	found: false,
	err:   nil,
},

This is due to the first case returning nil via this condition: https://github.com/getkin/kin-openapi/blob/master/openapi3filter/req_resp_decoder.go#L248
While the second case returns nil via this condition https://github.com/getkin/kin-openapi/blob/master/openapi3filter/req_resp_decoder.go#L524 (that function returns a []any, thus the nil is wrapped in a slice

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions