Skip to content

Commit

Permalink
Adding support for query params for all http operations
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Nov 6, 2023
1 parent 9821a21 commit 1e0aca4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/twilio/oai/TwilioGoGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ public void postProcessParameter(final CodegenParameter parameter) {
if(parameter.isBodyParam){
parameter.vendorExtensions.put("x-is-body-param",true);
}
if(parameter.isQueryParam){
parameter.vendorExtensions.put("x-is-query-param",true);
}
if (parameter.isFreeFormObject || parameter.isAnyType) {
parameter.vendorExtensions.put("x-marshal", true);
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/resources/twilio-go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ func (c *ApiService) {{{nickname}}}({{#allParams}}{{#required}}{{paramName}} {{{
}
{{/headerParams}}
{{/hasHeaderParams}}
{{#vendorExtensions.x-is-create-operation}}
{{#vendorExtensions.x-is-json-type}}
resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers, queryParams, body...)
{{/vendorExtensions.x-is-json-type}}
{{^vendorExtensions.x-is-json-type}}
resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers, queryParams)
{{/vendorExtensions.x-is-json-type}}
{{/vendorExtensions.x-is-create-operation}}
{{^vendorExtensions.x-is-create-operation}}
{{^vendorExtensions.x-is-json-type}}
resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers, queryParams)
{{/vendorExtensions.x-is-json-type}}
{{/vendorExtensions.x-is-create-operation}}

resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers)
{{#returnType}}
if err != nil {
return nil, err
Expand Down Expand Up @@ -87,7 +99,7 @@ func (c *ApiService) Page{{{vendorExtensions.x-domain-name}}}({{#allParams}}{{#r
data.Set("Page", pageNumber)
}

resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
resp, err := c.requestHandler.Get(c.baseURL+path, data, headers, queryParams)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -175,7 +187,7 @@ func (c *ApiService) getNext{{{returnContainer}}}(nextPageUrl string) (interface
if nextPageUrl == "" {
return nil, nil
}
resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
resp, err := c.requestHandler.Get(nextPageUrl, nil, nil, queryParams)
if err != nil {
return nil, err
}
Expand Down
51 changes: 44 additions & 7 deletions src/main/resources/twilio-go/partial_serialization.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if params != nil && params.PathAccountSid != nil {
{{/pathParams}}

data := url.Values{}
queryParams := url.Values{}
{{^vendorExtensions.x-is-json-type}}
headers := make(map[string]interface{})

Expand All @@ -24,13 +25,13 @@ if params != nil && params.PathAccountSid != nil {
{{#hasOptionalParams}}
{{#optionalParams}}
{{#vendorExtensions.x-is-body-param}}
body := []byte{}
if params != nil && params.{{paramName}} != nil {
v, err := json.Marshal(*params.{{paramName}})
b, err := json.Marshal(*params.{{paramName}})
if err != nil {
return nil, err
}
urlEncodedData := url.QueryEscape(string(v))
data.Set("{{baseName}}", urlEncodedData)
body = b
}
{{/vendorExtensions.x-is-body-param}}
{{^vendorExtensions.x-is-body-param}}
Expand All @@ -46,11 +47,20 @@ if params != nil && params.PathAccountSid != nil {
if err != nil {
return nil, err
}

{{^vendorExtensions.x-is-query-param}}
data.Add("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Add("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{/items.vendorExtensions.x-marshal}}
{{^items.vendorExtensions.x-marshal}}
{{^vendorExtensions.x-is-query-param}}
data.Add("{{{baseName}}}", item)
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Add("{{{baseName}}}", item)
{{/vendorExtensions.x-is-query-param}}
{{/items.vendorExtensions.x-marshal}}
}
{{/isArray}}
Expand All @@ -61,11 +71,20 @@ if params != nil && params.PathAccountSid != nil {
if err != nil {
return nil, err
}

{{^vendorExtensions.x-is-query-param}}
data.Set("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Set("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{/vendorExtensions.x-marshal}}
{{^vendorExtensions.x-marshal}}
{{^vendorExtensions.x-is-query-param}}
data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}})
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}})
{{/vendorExtensions.x-is-query-param}}
{{/vendorExtensions.x-marshal}}
{{/isArray}}
}
Expand All @@ -91,11 +110,20 @@ if params != nil && params.PathAccountSid != nil {
if err != nil {
return nil, err
}

{{^vendorExtensions.x-is-query-param}}
data.Add("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Add("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{/items.vendorExtensions.x-marshal}}
{{^items.vendorExtensions.x-marshal}}
{{^vendorExtensions.x-is-query-param}}
data.Add("{{{baseName}}}", item)
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Add("{{{baseName}}}", item)
{{/vendorExtensions.x-is-query-param}}
{{/items.vendorExtensions.x-marshal}}
}
{{/isArray}}
Expand All @@ -106,11 +134,20 @@ if params != nil && params.PathAccountSid != nil {
if err != nil {
return nil, err
}

{{^vendorExtensions.x-is-query-param}}
data.Set("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Set("{{{baseName}}}", string(v))
{{/vendorExtensions.x-is-query-param}}
{{/vendorExtensions.x-marshal}}
{{^vendorExtensions.x-marshal}}
{{^vendorExtensions.x-is-query-param}}
data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}})
{{/vendorExtensions.x-is-query-param}}
{{#vendorExtensions.x-is-query-param}}
queryParams.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}})
{{/vendorExtensions.x-is-query-param}}
{{/vendorExtensions.x-marshal}}
{{/isArray}}
}
Expand Down

0 comments on commit 1e0aca4

Please sign in to comment.