From 1a2712f0758d88f28e5ed3a2f4e78975494ff898 Mon Sep 17 00:00:00 2001 From: Gildas Lebel Date: Tue, 23 Jul 2024 12:00:54 -0400 Subject: [PATCH] openapi3filter: Remove inconsistency for arrays in queries (#990) Co-authored-by: Gildas Lebel --- openapi3filter/req_resp_decoder.go | 4 ++++ openapi3filter/req_resp_decoder_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/openapi3filter/req_resp_decoder.go b/openapi3filter/req_resp_decoder.go index c509def3e..31fce2346 100644 --- a/openapi3filter/req_resp_decoder.go +++ b/openapi3filter/req_resp_decoder.go @@ -320,6 +320,10 @@ func decodeValue(dec valueDecoder, param string, sm *openapi3.SerializationMetho switch { case schema.Value.Type.Is("array"): decodeFn = func(param string, sm *openapi3.SerializationMethod, schema *openapi3.SchemaRef) (any, bool, error) { + res, b, e := dec.DecodeArray(param, sm, schema) + if len(res) == 0 { + return nil, b, e + } return dec.DecodeArray(param, sm, schema) } case schema.Value.Type.Is("object"): diff --git a/openapi3filter/req_resp_decoder_test.go b/openapi3filter/req_resp_decoder_test.go index 6e456d2aa..53763901d 100644 --- a/openapi3filter/req_resp_decoder_test.go +++ b/openapi3filter/req_resp_decoder_test.go @@ -878,6 +878,22 @@ func TestDecodeParameter(t *testing.T) { want: map[string]any{"id": "foo", "name": "bar"}, found: true, }, + { + 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, + found: false, + err: nil, + }, { name: "deepObject explode additionalProperties with object properties - missing index on nested array", param: &openapi3.Parameter{