Skip to content

Commit

Permalink
Add query renaming case to bar client
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuntao Lu committed Sep 27, 2017
1 parent 76361a6 commit 152bb03
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 10 deletions.
12 changes: 9 additions & 3 deletions codegen/test_data/bar.json
Expand Up @@ -179,8 +179,8 @@
"\tanOptStrQuery := *r.AnOptStr",
"\tqueryValues.Set(\"anOptStr\", anOptStrQuery)",
"}",
"aBoolQuery := strconv.FormatBool(r.ABool)",
"queryValues.Set(\"aBool\", aBoolQuery)",
"aBooleanQuery := strconv.FormatBool(r.ABool)",
"queryValues.Set(\"aBoolean\", aBooleanQuery)",
"if r.AnOptBool != nil {",
"\tanOptBoolQuery := strconv.FormatBool(*r.AnOptBool)",
"\tqueryValues.Set(\"anOptBool\", anOptBoolQuery)",
Expand Down Expand Up @@ -388,8 +388,14 @@
"IsEndpoint": false,
"ParseQueryParamGoStatements": null,
"WriteQueryParamGoStatements": [
"queryValues := \u0026url.Values{}",
"uuidQuery := r.UUID",
"queryValues.Set(\"uuid\", uuidQuery)",
"if r.Params != nil {",
"}"
"paramsUserUUIDQuery := r.Params.UserUUID",
"queryValues.Set(\"params.userUUID\", paramsUserUUIDQuery)",
"}",
"fullURL += \"?\" + queryValues.Encode()"
],
"ReqHeaderGoStatements": null,
"ResHeaderFields": {
Expand Down
10 changes: 8 additions & 2 deletions codegen/test_data/clients/bar.gogen
Expand Up @@ -372,8 +372,8 @@ func (c *barClient) ArgWithManyQueryParams(
anOptStrQuery := *r.AnOptStr
queryValues.Set("anOptStr", anOptStrQuery)
}
aBoolQuery := strconv.FormatBool(r.ABool)
queryValues.Set("aBool", aBoolQuery)
aBooleanQuery := strconv.FormatBool(r.ABool)
queryValues.Set("aBoolean", aBooleanQuery)
if r.AnOptBool != nil {
anOptBoolQuery := strconv.FormatBool(*r.AnOptBool)
queryValues.Set("anOptBool", anOptBoolQuery)
Expand Down Expand Up @@ -542,8 +542,14 @@ func (c *barClient) ArgWithParams(
// Generate full URL.
fullURL := c.httpClient.BaseURL + "/bar" + "/argWithParams" + "/" + string(r.UUID) + "/segment" + "/" + string(r.Params.UserUUID)

queryValues := &url.Values{}
uuidQuery := r.UUID
queryValues.Set("uuid", uuidQuery)
if r.Params != nil {
paramsUserUUIDQuery := r.Params.UserUUID
queryValues.Set("params.userUUID", paramsUserUUIDQuery)
}
fullURL += "?" + queryValues.Encode()

err := req.WriteJSON("GET", fullURL, headers, nil)
if err != nil {
Expand Down
Expand Up @@ -108,6 +108,24 @@ func (handler *BarArgWithNestedQueryParamsHandler) HandleRequest(
requestBody.Request.UserUUID = ptr.String(requestUserUUIDQuery)
}

requestAuthUUIDOk := req.HasQueryValue("request.authUUID")
if requestAuthUUIDOk {
requestAuthUUIDQuery, ok := req.GetQueryValue("request.authUUID")
if !ok {
return
}
requestBody.Request.AuthUUID = ptr.String(requestAuthUUIDQuery)
}

requestAuthUUID2Ok := req.HasQueryValue("request.authUUID2")
if requestAuthUUID2Ok {
requestAuthUUID2Query, ok := req.GetQueryValue("request.authUUID2")
if !ok {
return
}
requestBody.Request.AuthUUID2 = ptr.String(requestAuthUUID2Query)
}

if req.HasQueryPrefix("opt") || requestBody.Opt != nil {
if requestBody.Opt == nil {
requestBody.Opt = &endpointsBarBar.QueryParamsOptsStruct{}
Expand Down
Expand Up @@ -79,6 +79,15 @@ func (handler *BarArgWithQueryHeaderHandler) HandleRequest(
requestBody.UserUUID = ptr.String(xUUIDValue)
}

userUUIDOk := req.HasQueryValue("userUUID")
if userUUIDOk {
userUUIDQuery, ok := req.GetQueryValue("userUUID")
if !ok {
return
}
requestBody.UserUUID = ptr.String(userUUIDQuery)
}

workflow := ArgWithQueryHeaderEndpoint{
Clients: handler.Clients,
Logger: req.Logger,
Expand Down
10 changes: 8 additions & 2 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.

4 changes: 3 additions & 1 deletion examples/example-gateway/idl/clients/bar/bar.thrift
Expand Up @@ -167,7 +167,9 @@ service Bar {
BarResponse argWithManyQueryParams(
1: required string aStr
2: optional string anOptStr
3: required bool aBool
3: required bool aBool (
zanzibar.http.ref = "query.aBoolean"
)
4: optional bool anOptBool
5: required i8 aInt8
6: optional i8 anOptInt8
Expand Down
4 changes: 2 additions & 2 deletions test/endpoints/bar/bar_arg_with_query_params_test.go
Expand Up @@ -161,7 +161,7 @@ func TestBarWithManyQueryParamsCall(t *testing.T) {
"GET", "/bar/argWithManyQueryParams",
func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t,
"aBool=true&aFloat64=5.1&aInt16=48&aInt32=12&"+
"aBoolean=true&aFloat64=5.1&aInt16=48&aInt32=12&"+
"aInt64=4&aInt8=24&aStr=foo&anOptBool=false&"+
"anOptFloat64=-0.4&anOptInt16=-100&anOptInt32=-10&"+
"anOptInt64=-1&anOptInt8=-50&anOptStr=bar",
Expand Down Expand Up @@ -696,7 +696,7 @@ func TestBarWithManyQueryParamsOptionalCall(t *testing.T) {
"GET", "/bar/argWithManyQueryParams",
func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t,
"aBool=true&aFloat64=5.1&aInt16=48&aInt32=12&"+
"aBoolean=true&aFloat64=5.1&aInt16=48&aInt32=12&"+
"aInt64=4&aInt8=24&aStr=foo&anOptBool=false&"+
"anOptInt8=-50&anOptStr=bar",
r.URL.RawQuery,
Expand Down

0 comments on commit 152bb03

Please sign in to comment.