Skip to content

Commit

Permalink
fixes #987 - openapi3filter: Remove inconsistency for arrays in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
GildasLebel committed Jul 23, 2024
1 parent 25ce765 commit e762bd8
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 e762bd8

Please sign in to comment.