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(go): CTS implementation for go client #1509

Merged
merged 12 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
11 changes: 11 additions & 0 deletions clients/algoliasearch-client-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module github.com/algolia/algoliasearch-client-go/v4

go 1.19

require github.com/go-playground/validator/v10 v10.12.0

require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
)
32 changes: 32 additions & 0 deletions clients/algoliasearch-client-go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI=
github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA=
github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4=
github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"customGenerator": "algolia-go",
"tests": {
"extension": "_test.go",
"outputFolder": ""
"outputFolder": "tests"
}
}
}
9 changes: 8 additions & 1 deletion generators/src/main/java/com/algolia/codegen/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public static CodegenOperation specifyCustomRequest(CodegenOperation ope) {

/** Returns the client name for the given language */
public static String createClientName(String client, String language) {
return language.equals("javascript") ? camelize(client) : capitalize(camelize(client));
switch (language) {
case "javascript":
return camelize(client);
case "go":
return client;
default:
return capitalize(camelize(client));
}
}

// testInput -> test-input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static CTSManager getManager(String language, String client) {
return new JavaCTSManager(client);
case "php":
return new PhpCTSManager();
case "go":
return new GoCTSManager();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.algolia.codegen.cts.manager;

import com.algolia.codegen.exceptions.GeneratorException;
import java.util.*;
import org.openapitools.codegen.SupportingFile;

public class GoCTSManager implements CTSManager {

@Override
public void addSupportingFiles(List<SupportingFile> supportingFiles) {
supportingFiles.add(new SupportingFile("common.mustache", "tests/methods/requests", "common.go"));
}

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
Object clientPrefix = bundle.get("clientPrefix");

if (clientPrefix.equals("query-suggestions")) {
bundle.put("clientPrefix", "suggestions");
}

bundle.put("clientImport", clientPrefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ private Map<String, Object> traverseParams(
finalParamName = paramName.substring(1);
}

// type is a reserved keyword in go, we need to add more generic way to handle reversed keywords
// for all languages.
if (language.equals("go") && paramName.equals("type")) {
finalParamName = "type_";
}

Map<String, Object> testOutput = createDefaultOutput();
testOutput.put("key", finalParamName);
testOutput.put("parentSuffix", suffix - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Request {
public Map<String, Object> parameters;
public RequestOptions requestOptions;
public RequestProp request;
public Map<String, Object> extras;

@Override
public String toString() {
Expand All @@ -25,6 +26,7 @@ public String toString() {
sb.append(" parameters: ").append(parameters).append("\n");
sb.append(" requestOptions: ").append(requestOptions).append("\n");
sb.append(" request: ").append(request).append("\n");
sb.append(" extras: ").append(extras).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>

test.put("request", req.request);
test.put("hasParameters", req.parameters.size() != 0);
test.put("extras", req.extras);

if (req.requestOptions != null) {
test.put("hasRequestOptions", true);
Expand Down
10 changes: 10 additions & 0 deletions playground/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ require (
github.com/algolia/algoliasearch-client-go/v4 v4.0.0
github.com/joho/godotenv v1.4.0
)

require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/leodido/go-urn v1.2.2 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
)
32 changes: 32 additions & 0 deletions playground/go/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.12.0 h1:E4gtWgxWxp8YSxExrQFv5BpCahla0PVF2oTTEYaWQGI=
github.com/go-playground/validator/v10 v10.12.0/go.mod h1:hCAPuzYvKdP33pxWa+2+6AIKXEKqjIUyqsNCtbsSJrA=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4=
github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rwtodd/Go.Sed v0.0.0-20210816025313-55464686f9ef/go.mod h1:8AEUvGVi2uQ5b24BIhcr0GCcpd/RNAFWaN2CJFrWIIQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion playground/go/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func testInsights(appID, apiKey string) int {
insights.WithInsightEventQueryID("myQueryID")),
})
pushEventsResponse, err := insightsClient.PushEvents(
insightsClient.NewApiPushEventsRequest().WithInsightEvents(*events),
insightsClient.NewApiPushEventsRequest().WithInsightEvents(events),
)
if err != nil {
fmt.Printf("request error with PushEvents: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion playground/go/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func testPredict(appID, apiKey string) int {
predict.WithAllParamsTypesToRetrieve(predict.AllowedTypesToRetrieveEnumValues),
))
userProfile, err := predictClient.FetchUserProfile(
predictClient.NewApiFetchUserProfileRequest("userId").WithParams(params),
predictClient.NewApiFetchUserProfileRequest("userId").WithParams(&params),
)
if err != nil {
fmt.Printf("request error with FetchUserProfile: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion playground/go/recommend.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func testRecommend(appID, apiKey string) int {
}

searchResponse, err := recommendClient.GetRecommendations(
recommendClient.NewApiGetRecommendationsRequest().WithGetRecommendationsParams(params),
recommendClient.NewApiGetRecommendationsRequest().WithGetRecommendationsParams(&params),
)
if err != nil {
fmt.Printf("request error with SearchSingleIndex: %v\n", err)
Expand Down
2 changes: 1 addition & 1 deletion playground/go/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func testSearch(appID, apiKey string) int {
searchClient := search.NewClient(appID, apiKey)

searchParams := search.SearchParamsStringAsSearchParams(search.NewSearchParamsString(search.WithSearchParamsStringParams("query=jeans&hitsPerPage=2")))
searchResponse, err := searchClient.SearchSingleIndex(searchClient.NewApiSearchSingleIndexRequest(indexName).WithSearchParams(searchParams))
searchResponse, err := searchClient.SearchSingleIndex(searchClient.NewApiSearchSingleIndexRequest(indexName).WithSearchParams(&searchParams))
if err != nil {
fmt.Printf("request error with SearchSingleIndex: %v\n", err)
return 1
Expand Down
3 changes: 3 additions & 0 deletions scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
case 'java':
testsToStore = `${testsToStore} ${testsRootFolder}/build.gradle`;
break;
case 'go':
testsToStore = `${testsToStore} ${testsOutputBase}/methods/requests/common.go`;
break;
/**
* The CI runs on a node docker image, therefore it's not needed to run
* via the CLI for the JavaScript client.
Expand Down
11 changes: 8 additions & 3 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ export function wait(waitTime: number): Promise<void> {
}

export function createClientName(client: string, language: string): string {
return language === 'javascript'
? camelize(client)
: capitalize(camelize(client));
switch (language) {
case 'javascript':
return camelize(client);
case 'go':
return client;
default:
return capitalize(camelize(client));
}
}

/**
Expand Down
13 changes: 12 additions & 1 deletion scripts/cts/runCts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run, runComposerUpdate } from '../common';
import { DOCKER, run, runComposerUpdate } from '../common';
import { createSpinner } from '../spinners';

async function runCtsOne(language: string): Promise<void> {
Expand All @@ -22,6 +22,17 @@ async function runCtsOne(language: string): Promise<void> {
);
break;
}
case 'go':
if (DOCKER) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the distinction for docker, /usr/local/go/bin/go is already in the PATH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it is in the PATH but somehow it is not working with js runtime. I can run with just go from the container but when I used it with the run function it is not working.

I couldn't quite figure out the reason last time. So I already opened a separate ticket to resolve this if possible.

await run('/usr/local/go/bin/go test -count 1 ./...', {
cwd: 'tests/output/go',
});
} else {
await run('go test -count 1 ./...', {
cwd: 'tests/output/go',
});
}
break;
default:
spinner.warn(`skipping unknown language '${language}' to run the CTS`);
return;
Expand Down
49 changes: 40 additions & 9 deletions templates/go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package {{packageName}}
import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -39,10 +40,36 @@ func HeaderParamOption(name string, val any) Option {

type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request struct {
{{#allParams}}
{{paramName}} {{^isPathParam}}{{^isFreeFormObject}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isFreeFormObject}}{{/isPathParam}}{{{dataType}}}
{{paramName}} {{^isPathParam}}{{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}{{/isPathParam}}{{{dataType}}}
{{/allParams}}
}

func (r *{{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) UnmarshalJSON(b []byte) error {
req := map[string]json.RawMessage{}
err := json.Unmarshal(b, &req)
if err != nil {
return err
}
{{#allParams}}
if v, ok := req["{{paramName}}"]; ok {
err = json.Unmarshal(v, &r.{{paramName}})
if err != nil {
err = json.Unmarshal(b, &r.{{paramName}})
if err != nil {
return err
}
}
} {{#isBodyParam}}{{#required}}else {
err = json.Unmarshal(b, &r.{{paramName}})
if err != nil {
return err
}
}{{/required}}{{/isBodyParam}}
{{/allParams}}

return nil
}

{{#allParams}}
{{^isPathParam}}
{{#description}}
Expand All @@ -51,8 +78,8 @@ func HeaderParamOption(name string, val any) Option {
{{#isDeprecated}}
// Deprecated
{{/isDeprecated}}
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) With{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{paramName}} {{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
r.{{paramName}} = {{^isFreeFormObject}}{{^isPrimitiveType}}&{{/isPrimitiveType}}{{/isFreeFormObject}}{{paramName}}
func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request) With{{#lambda.titlecase}}{{paramName}}{{/lambda.titlecase}}({{paramName}} {{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}{{{dataType}}}) {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/structPrefix}}{{operationId}}Request {
r.{{paramName}} = {{paramName}}
return r
}

Expand Down Expand Up @@ -149,22 +176,22 @@ func (c *APIClient) {{nickname}}(r {{#structPrefix}}{{&classname}}{{/structPrefi

{{#queryParams}}
{{#required}}
queryParams.Add("{{baseName}}", parameterToString({{^isFreeFormObject}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isFreeFormObject}}r.{{paramName}}))
queryParams.Add("{{baseName}}", parameterToString({{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}r.{{paramName}}))
{{/required}}
{{^required}}
if !isNilorEmpty(r.{{paramName}}) {
queryParams.Add("{{baseName}}", parameterToString({{^isFreeFormObject}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isFreeFormObject}}r.{{paramName}}))
queryParams.Add("{{baseName}}", parameterToString({{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}r.{{paramName}}))
}
{{/required}}
{{/queryParams}}

{{#headerParams}}
{{#required}}
headers["{{baseName}}"] = parameterToString({{^isFreeFormObject}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isFreeFormObject}}r.{{paramName}})
headers["{{baseName}}"] = parameterToString({{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}r.{{paramName}})
{{/required}}
{{^required}}
if !isNilorEmpty(r.{{paramName}}) {
headers["{{baseName}}"] = parameterToString({{^isFreeFormObject}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isFreeFormObject}}r.{{paramName}})
headers["{{baseName}}"] = parameterToString({{^isFreeFormObject}}{{^isArray}}{{^isPrimitiveType}}*{{/isPrimitiveType}}{{/isArray}}{{/isFreeFormObject}}r.{{paramName}})
}
{{/required}}
{{/headerParams}}
Expand All @@ -180,8 +207,12 @@ func (c *APIClient) {{nickname}}(r {{#structPrefix}}{{&classname}}{{/structPrefi
}

{{#bodyParams}}
// body params
postBody = r.{{paramName}}
// body params{{^required}}
if isNilorEmpty(r.{{paramName}}) {
postBody = "{}"
} else { {{/required}}
postBody = r.{{paramName}}{{^required}}
} {{/required}}
{{/bodyParams}}
req, err := c.prepareRequest(context.Background(), requestPath, http.Method{{httpMethod}}, postBody, headers, queryParams)
if err != nil {
Expand Down
Loading