Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions styleparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
"strings"
"time"

"github.com/oapi-codegen/runtime/types"
"github.com/google/uuid"

"github.com/oapi-codegen/runtime/types"
)

// Parameter escaping works differently based on where a header is found
Expand Down Expand Up @@ -288,19 +289,15 @@ func styleMap(style string, explode bool, paramName string, paramLocation ParamL
}
return MarshalDeepObject(value, paramName)
}

dict, ok := value.(map[string]interface{})
if !ok {
return "", errors.New("map not of type map[string]interface{}")
}
v := reflect.ValueOf(value)

fieldDict := make(map[string]string)
for fieldName, value := range dict {
str, err := primitiveToString(value)
for _, fieldName := range v.MapKeys() {
str, err := primitiveToString(v.MapIndex(fieldName).Interface())
if err != nil {
return "", fmt.Errorf("error formatting '%s': %s", paramName, err)
}
fieldDict[fieldName] = str
fieldDict[fieldName.String()] = str
}
return processFieldDict(style, explode, paramName, paramLocation, fieldDict)
}
Expand Down
32 changes: 31 additions & 1 deletion styleparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
package runtime

import (
"fmt"
"testing"
"time"

"github.com/oapi-codegen/runtime/types"
"github.com/google/uuid"
"github.com/oapi-codegen/runtime/types"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -690,3 +691,32 @@ func TestStyleParam(t *testing.T) {
assert.EqualValues(t, "972beb41-e5ea-4b31-a79a-96f4999d8769", result)

}

// Issue 37 - https://github.com/oapi-codegen/runtime/issues/37
func TestIssue37(t *testing.T) {
styles := []string{
"simple",
"spaceDelimited",
"pipeDelimited",
"deepObject",
"form",
"matrix",
"label",
}
values := []struct {
name string
value interface{}
}{
{"int", map[string]int{"k1": 1, "k2": 2, "k3": 3}},
{"string", map[string]string{"k1": "v1", "k2": "v2", "k3": "v3"}},
{"any", map[string]any{"k1": "v1", "k2": 2, "k3": 3.5}},
}
for _, style := range styles {
for _, value := range values {
t.Run(fmt.Sprintf("%s %s", value.name, style), func(t *testing.T) {
_, err := StyleParamWithLocation("form", true, "priority", ParamLocationQuery, value.value)
assert.NoError(t, err)
})
}
}
}