Skip to content

Commit 447d2bd

Browse files
authored
Fix: Unsigned values as parameters (#535)
* Parse uint parameters in client code Server and client generated code correctly support uint types, but using uint in client code causes a runtime error. This adds the full complement of uint types to the parameter parser. Fix: issues/521 * Parse int16 parameters in client code All of the other int types are covered by `primitiveToString`; this completes the set.
1 parent 31b967a commit 447d2bd

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

styleparam.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,10 @@ func primitiveToString(value interface{}) (string, error) {
360360
kind := t.Kind()
361361

362362
switch kind {
363-
case reflect.Int8, reflect.Int32, reflect.Int64, reflect.Int:
363+
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int:
364364
output = strconv.FormatInt(v.Int(), 10)
365+
case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint:
366+
output = strconv.FormatUint(v.Uint(), 10)
365367
case reflect.Float64:
366368
output = strconv.FormatFloat(v.Float(), 'f', -1, 64)
367369
case reflect.Float32:

styleparam_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,31 @@ func TestStyleParam(t *testing.T) {
490490
assert.NoError(t, err)
491491
assert.EqualValues(t, "7", result)
492492

493+
type UintType uint
494+
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, UintType(9))
495+
assert.NoError(t, err)
496+
assert.EqualValues(t, "9", result)
497+
498+
type Uint8Type uint8
499+
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, Uint8Type(9))
500+
assert.NoError(t, err)
501+
assert.EqualValues(t, "9", result)
502+
503+
type Uint16Type uint16
504+
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, Uint16Type(9))
505+
assert.NoError(t, err)
506+
assert.EqualValues(t, "9", result)
507+
508+
type Uint32Type uint32
509+
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, Uint32Type(9))
510+
assert.NoError(t, err)
511+
assert.EqualValues(t, "9", result)
512+
513+
type Uint64Type uint64
514+
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, Uint64Type(9))
515+
assert.NoError(t, err)
516+
assert.EqualValues(t, "9", result)
517+
493518
type FloatType64 float64
494519
result, err = StyleParamWithLocation("simple", false, "foo", ParamLocationQuery, FloatType64(7.5))
495520
assert.NoError(t, err)

0 commit comments

Comments
 (0)