From 0b4df7d1c1751da924abb54fe5d051f6ce26a342 Mon Sep 17 00:00:00 2001 From: Alex Dulin Date: Mon, 2 Mar 2026 12:49:00 -0500 Subject: [PATCH] fix: parse un-exploded query param to map This fixes an issue where query parameters that are objects with additional properties cannot be parsed into their values. For example, a query parameter like `tags=foo,bar,bim,baz` should end up becoming: ```go map[string]string{ "foo": "bar", "bim": "baz", } ``` This adheres to the [spec](https://swagger.io/docs/specification/v3_0/serialization/#query-parameters) for paramters of style=form and explode=false. Fixes: https://github.com/oapi-codegen/oapi-codegen/issues/698 Signed-off-by: Alex Dulin --- bindparam.go | 2 +- bindparam_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bindparam.go b/bindparam.go index 7906f53..cd2fdd5 100644 --- a/bindparam.go +++ b/bindparam.go @@ -508,7 +508,7 @@ func BindQueryParameterWithOptions(style string, explode bool, required bool, pa } else { err = bindSplitPartsToDestinationArray(parts, output) } - case reflect.Struct: + case reflect.Struct, reflect.Map: // Some struct types (e.g. types.Date, time.Time) are scalar values // that should be bound from a single string, not decomposed as // key-value objects. Detect these via the Binder and diff --git a/bindparam_test.go b/bindparam_test.go index a18fcbd..5b06543 100644 --- a/bindparam_test.go +++ b/bindparam_test.go @@ -542,6 +542,21 @@ func TestBindQueryParameter(t *testing.T) { assert.Equal(t, types.Date{Time: time.Date(2023, 6, 15, 0, 0, 0, 0, time.UTC)}, *params.StartDate) }) + t.Run("map_form_no_explode_optional", func(t *testing.T) { + want := map[string]string{ + "foo": "bar", + "bim": "baz", + } + queryParams := url.Values{ + "tags": {"foo,bar,bim,baz"}, + } + var got map[string]string + err := BindQueryParameter("form", false, false, "tags", queryParams, &got) + assert.NoError(t, err) + require.NotNil(t, got) + assert.Equal(t, want, got) + }) + t.Run("optional", func(t *testing.T) { queryParams := url.Values{ "time": {"2020-12-09T16:09:53+00:00"},