fix: correctly handle `map`s with different value types when binding by andnow873 · Pull Request #38 · oapi-codegen/runtime

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