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

decodeStyledParameter has an inconsistency for arrays in query #989

Closed
TheSadlig opened this issue Jul 23, 2024 · 1 comment · Fixed by #990
Closed

decodeStyledParameter has an inconsistency for arrays in query #989

TheSadlig opened this issue Jul 23, 2024 · 1 comment · Fixed by #990

Comments

@TheSadlig
Copy link
Contributor

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

@TheSadlig
Copy link
Contributor Author

See #990 for a potential fix

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