Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generator changes to add query parameters to rest calls #550

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -187,6 +187,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
20 changes: 11 additions & 9 deletions src/main/resources/twilio-go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ 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, body...)
{{/vendorExtensions.x-is-json-type}}
{{^vendorExtensions.x-is-json-type}}
resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers)
{{/vendorExtensions.x-is-json-type}}
{{#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}}
resp, err := c.requestHandler.{{httpMethod}}(c.baseURL+path, data, headers)
{{^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}}
{{#returnType}}
if err != nil {
Expand Down Expand Up @@ -96,7 +98,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 @@ -184,7 +186,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, nil)
if err != nil {
return nil, err
}
Expand Down
47 changes: 44 additions & 3 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 Down Expand Up @@ -47,10 +48,20 @@ if params != nil && params.PathAccountSid != nil {
return nil, err
}

data.Add("{{{baseName}}}", string(v))
{{^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}}
data.Add("{{{baseName}}}", item)
{{^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 @@ -62,10 +73,20 @@ if params != nil && params.PathAccountSid != nil {
return nil, err
}

data.Set("{{{baseName}}}", string(v))
{{^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 @@ -92,10 +113,20 @@ if params != nil && params.PathAccountSid != 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 @@ -107,10 +138,20 @@ if params != nil && params.PathAccountSid != 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
Loading