Skip to content

Commit

Permalink
Adding support for enum in endpoint and client for http GET in query …
Browse files Browse the repository at this point in the history
…params , list support backward compatible with rtapi (#579)

* Adding support for enum in endpoint and client

* client and endpoint utilising this

* generate code

* integration test for enum and list in get query param

* list query param should follow the rtapi way for it to be backward compatible

* unit test

* readme changes
  • Loading branch information
abhishekparwal committed Mar 22, 2019
1 parent a14c805 commit 45b84df
Show file tree
Hide file tree
Showing 26 changed files with 2,682 additions and 57 deletions.
18 changes: 14 additions & 4 deletions codegen/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,8 @@ func getQueryMethodForType(typeSpec compile.TypeSpec) string {
queryMethod = "GetQueryInt16"
case *compile.I32Spec:
queryMethod = "GetQueryInt32"
case *compile.EnumSpec:
queryMethod = "GetQueryInt32"
case *compile.I64Spec:
queryMethod = "GetQueryInt64"
case *compile.DoubleSpec:
Expand All @@ -1046,6 +1048,8 @@ func getQueryMethodForType(typeSpec compile.TypeSpec) string {
queryMethod = "GetQueryInt16List"
case *compile.I32Spec:
queryMethod = "GetQueryInt32List"
case *compile.EnumSpec:
queryMethod = "GetQueryInt32List"
case *compile.I64Spec:
queryMethod = "GetQueryInt64List"
case *compile.DoubleSpec:
Expand Down Expand Up @@ -1106,6 +1110,8 @@ func getQueryEncodeExpression(
} else {
encodeExpression = "%s"
}
case *compile.EnumSpec:
encodeExpression = "strconv.Itoa(int(%s))"
case *compile.ListSpec:
_, isValueTypedef := t.ValueSpec.(*compile.TypedefSpec)
switch compile.RootTypeSpec(t.ValueSpec).(type) {
Expand Down Expand Up @@ -1204,9 +1210,6 @@ func (ms *MethodSpec) setWriteQueryParamStatements(
longQueryName := ms.getLongQueryName(field, thriftPrefix)
identifierName := CamelCase(longQueryName) + "Query"
_, isList := realType.(*compile.ListSpec)
if isList {
longQueryName = longQueryName + "[]"
}

if !hasQueryFields {
statements.append("queryValues := &url.Values{}")
Expand Down Expand Up @@ -1288,10 +1291,17 @@ func (ms *MethodSpec) setParseQueryParamStatements(
}
}

if _, ok := field.Type.(*compile.EnumSpec); ok {
typedef, err = GoType(packageHelper, field.Type)
if err != nil {
finalError = err
return true
}
}

var listValueTypedef string
t, isList := realType.(*compile.ListSpec)
if isList {
longQueryName = longQueryName + "[]"
if _, ok := t.ValueSpec.(*compile.TypedefSpec); ok {
listValueTypedef, err = GoType(packageHelper, t.ValueSpec)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions codegen/thrift.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ func pointerMethodType(typeSpec compile.TypeSpec) string {
pointerMethod = "Float64"
case *compile.StringSpec:
pointerMethod = "String"
case *compile.EnumSpec:
pointerMethod = "Int32"
default:
panic(fmt.Sprintf(
"Unknown type (%T) %v for allocating a pointer",
Expand Down
6 changes: 3 additions & 3 deletions docs/thrift.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ how its serialized for the client ).
- list of bool, i8, i16, i32, i64, double or string
- struct with fields of bool, i8, i16, i32, i64, double, string, or list of bool, i8, i16, i32, i64, double or string

If the annotation is on a field of a list and that list is
a method argument, the URL query name will be prefixed with the
struct's field name plus "[]".
If the annotation is on a field of type list, the URL query name/value pair
can be repeated several times with '&' to send multiple values for a
list type.

If the annotation is on a field of a struct and that struct is
a method argument, the URL query name will be prefixed with the
Expand Down
111 changes: 102 additions & 9 deletions examples/example-gateway/build/clients/bar/bar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 45b84df

Please sign in to comment.