Skip to content

Commit

Permalink
openapi3filter: Remove inconsistency for arrays in queries (getkin#990)
Browse files Browse the repository at this point in the history
Co-authored-by: Gildas Lebel <gildaslebel@gmail.com>
  • Loading branch information
TheSadlig and GildasLebel authored Jul 23, 2024
1 parent 25ce765 commit 1a2712f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions openapi3filter/req_resp_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
16 changes: 16 additions & 0 deletions openapi3filter/req_resp_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 1a2712f

Please sign in to comment.