From ae5b0607eed5db9f51cf00dd0cd3e36decb53a41 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 9 Jan 2024 17:34:41 +0100 Subject: [PATCH 01/18] feat(clients): generate code snippets from cts --- config/clients.config.json | 4 ++++ config/generation.config.mjs | 2 ++ .../codegen/cts/tests/TestsRequest.java | 18 ++++++++++++++++++ scripts/cts/generate.ts | 4 ++++ snippets/python/pyproject.toml | 17 +++++++++++++++++ .../python/tests/snippets/method.mustache | 19 +++++++++++++++++++ 6 files changed, 64 insertions(+) create mode 100644 snippets/python/pyproject.toml create mode 100644 templates/python/tests/snippets/method.mustache diff --git a/config/clients.config.json b/config/clients.config.json index 69ee42e6bd..7593c223aa 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -197,6 +197,10 @@ "tests": { "extension": "_test.py", "outputFolder": "tests" + }, + "snippets": { + "extension": ".py", + "outputFolder": "snippets" } }, "ruby": { diff --git a/config/generation.config.mjs b/config/generation.config.mjs index 0819d96c4d..5bd35d40b9 100644 --- a/config/generation.config.mjs +++ b/config/generation.config.mjs @@ -78,6 +78,8 @@ export const patterns = [ '!clients/algoliasearch-client-dart/packages/algoliasearch/lib/algoliasearch.dart', // Python + 'snippets/python/**', + '!snippets/python/pyproject.toml', 'clients/algoliasearch-client-python/**', '!clients/algoliasearch-client-python/algoliasearch/http/**', '!clients/algoliasearch-client-python/algoliasearch/py.typed', diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index f5487a41cd..bf8b82786a 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -35,9 +35,22 @@ public void addSupportingFiles(List supportingFiles, String outp if (!available()) { return; } + + // tests generation supportingFiles.add( new SupportingFile("requests/requests.mustache", outputFolder + "/requests", Helpers.createClientName(client, language) + extension) ); + + // snippets generation + String snippetsExtension = Helpers.getClientConfigField(language, "snippets", "extension"); + String snippetsOutputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); + + supportingFiles.add( + new SupportingFile( + "snippets/method.mustache", + "../../../" + snippetsOutputFolder + "/" + language + "/" + Helpers.createClientName(client, language) + snippetsExtension + ) + ); } @Override @@ -66,6 +79,7 @@ public void run(Map models, Map Request[] op = cts.get(operationId); List tests = new ArrayList<>(); + List snippets = new ArrayList<>(); for (int i = 0; i < op.length; i++) { Map test = new HashMap<>(); Request req = op[i]; @@ -141,6 +155,9 @@ public void run(Map models, Map paramsType.enhanceParameters(req.parameters, test, ope); tests.add(test); + if (i == 0) { + snippets.add(test); + } } catch (CTSException e) { e.setTestName((String) test.get("testName")); throw e; @@ -148,6 +165,7 @@ public void run(Map models, Map } Map testObj = new HashMap<>(); testObj.put("tests", tests); + testObj.put("snippets", snippets); testObj.put("operationId", operationId); blocks.add(testObj); } diff --git a/scripts/cts/generate.ts b/scripts/cts/generate.ts index 7a72b015ec..be1f022168 100644 --- a/scripts/cts/generate.ts +++ b/scripts/cts/generate.ts @@ -59,5 +59,9 @@ export async function ctsGenerateMany(generators: Generator[]): Promise { } await formatter(lang, toAbsolutePath(`tests/output/${lang}`)); + + if (lang === 'python') { + await formatter(lang, toAbsolutePath(`snippets/${lang}`)); + } } } diff --git a/snippets/python/pyproject.toml b/snippets/python/pyproject.toml new file mode 100644 index 0000000000..20bfdcdda3 --- /dev/null +++ b/snippets/python/pyproject.toml @@ -0,0 +1,17 @@ +[tool.poetry] +name = "snippets" +version = "0.0.1" +description = "snippets for the python api client" +authors = ["Algolia Team "] +license = "MIT" +homepage = "https://www.algolia.com" +repository = "https://github.com/algolia/api-clients-automation" + +[tool.poetry.dependencies] +python = "3.11.6" +algoliasearch = { path = "../../clients/algoliasearch-client-python", develop = true } +flake8 = "6.1.0" +autoflake = "2.2.1" +autopep8 = "2.0.4" +black = "23.11.0" +isort = "5.13.0" diff --git a/templates/python/tests/snippets/method.mustache b/templates/python/tests/snippets/method.mustache new file mode 100644 index 0000000000..ae0057cbda --- /dev/null +++ b/templates/python/tests/snippets/method.mustache @@ -0,0 +1,19 @@ +from algoliasearch.{{{import}}}.client import {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} + + +class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: + {{#blocksRequests}} + {{#snippets}} + async def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}(): + _client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) + + resp = await _client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + + # use the class directly + print(resp) + + # print the JSON response + print(resp.to_json()) + + {{/snippets}} + {{/blocksRequests}} \ No newline at end of file From 61a03902b20ed4f2b2bcaced703b6e106a1f0a22 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 9 Jan 2024 17:38:42 +0100 Subject: [PATCH 02/18] fix: skip for non supported --- .../main/java/com/algolia/codegen/cts/tests/TestsRequest.java | 4 ++++ templates/python/tests/snippets/method.mustache | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index bf8b82786a..81872298dd 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -41,6 +41,10 @@ public void addSupportingFiles(List supportingFiles, String outp new SupportingFile("requests/requests.mustache", outputFolder + "/requests", Helpers.createClientName(client, language) + extension) ); + if (!language.equals("python")) { + return; + } + // snippets generation String snippetsExtension = Helpers.getClientConfigField(language, "snippets", "extension"); String snippetsOutputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); diff --git a/templates/python/tests/snippets/method.mustache b/templates/python/tests/snippets/method.mustache index ae0057cbda..c939758fda 100644 --- a/templates/python/tests/snippets/method.mustache +++ b/templates/python/tests/snippets/method.mustache @@ -5,7 +5,7 @@ class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: {{#blocksRequests}} {{#snippets}} async def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}(): - _client = SearchClient("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) + _client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) resp = await _client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) From d61b70098929f6f1edad6ba559ae5cd25a966a53 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 9 Jan 2024 17:41:55 +0100 Subject: [PATCH 03/18] trigger From 95ea5597eb3a860381996a6cea8754da027a0f9f Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 9 Jan 2024 17:55:38 +0100 Subject: [PATCH 04/18] feat: add testName --- .../com/algolia/codegen/cts/tests/TestsRequest.java | 10 ++++++---- templates/python/tests/snippets/method.mustache | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index 81872298dd..8cb7c1cc11 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -83,12 +83,13 @@ public void run(Map models, Map Request[] op = cts.get(operationId); List tests = new ArrayList<>(); - List snippets = new ArrayList<>(); + Map snippet = new HashMap<>(); for (int i = 0; i < op.length; i++) { Map test = new HashMap<>(); Request req = op[i]; test.put("method", operationId); - test.put("testName", req.testName == null ? operationId + i : req.testName); + String testName = req.testName == null ? operationId + i : req.testName; + test.put("testName", testName); test.put("testIndex", i); try { @@ -160,7 +161,8 @@ public void run(Map models, Map paramsType.enhanceParameters(req.parameters, test, ope); tests.add(test); if (i == 0) { - snippets.add(test); + snippet = test; + snippet.put("description", testName); } } catch (CTSException e) { e.setTestName((String) test.get("testName")); @@ -169,7 +171,7 @@ public void run(Map models, Map } Map testObj = new HashMap<>(); testObj.put("tests", tests); - testObj.put("snippets", snippets); + testObj.put("snippet", snippet); testObj.put("operationId", operationId); blocks.add(testObj); } diff --git a/templates/python/tests/snippets/method.mustache b/templates/python/tests/snippets/method.mustache index c939758fda..30ebf052fa 100644 --- a/templates/python/tests/snippets/method.mustache +++ b/templates/python/tests/snippets/method.mustache @@ -3,8 +3,11 @@ from algoliasearch.{{{import}}}.client import {{#lambda.pascalcase}}{{{client}}} class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: {{#blocksRequests}} - {{#snippets}} + {{#snippet}} async def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}(): + """ + {{{description}}} + """ _client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) resp = await _client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) @@ -15,5 +18,5 @@ class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: # print the JSON response print(resp.to_json()) - {{/snippets}} + {{/snippet}} {{/blocksRequests}} \ No newline at end of file From a9afbe44c11189dce56dfc2002af1feef9d2a367 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Tue, 9 Jan 2024 17:57:23 +0100 Subject: [PATCH 05/18] fix: store snippets in artifact --- scripts/ci/githubActions/createMatrix.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index 4b2f068013..12d1fbb189 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -118,7 +118,7 @@ async function createClientMatrix(baseBranch: string): Promise { testsToStore = `${testsToStore} ${testsRootFolder}/package.json`; break; case 'python': - testsToStore = `${testsToStore} ${testsRootFolder}/poetry.lock`; + testsToStore = `${testsToStore} ${testsRootFolder}/poetry.lock snippets/python`; break; case 'ruby': testsToStore = `${testsToStore} ${testsRootFolder}/Gemfile.lock`; From 0daeaf213ba0a3cd58bfbccaa4510ba2334fcb6e Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 12:07:16 +0100 Subject: [PATCH 06/18] feat(generators): add snippets generator --- config/clients.config.json | 2 +- .../codegen/cts/AlgoliaCTSGenerator.java | 17 ++++++- .../codegen/cts/manager/DartCTSManager.java | 7 --- .../codegen/cts/manager/GoCTSManager.java | 2 +- .../codegen/cts/manager/JavaCTSManager.java | 2 +- .../cts/manager/JavascriptCTSManager.java | 2 +- .../codegen/cts/manager/KotlinCTSManager.java | 7 --- .../codegen/cts/manager/PhpCTSManager.java | 11 +--- .../codegen/cts/manager/PythonCTSManager.java | 6 +-- .../cts/snippets/SnippetsGenerator.java | 51 +++++++++++++++++++ .../codegen/cts/tests/TestsClient.java | 6 ++- .../codegen/cts/tests/TestsRequest.java | 18 ++----- .../{tests => }/snippets/method.mustache | 2 +- templates/python/tests/client/method.mustache | 2 +- templates/python/tests/client/step.mustache | 6 +-- templates/python/tests/client/suite.mustache | 4 +- .../tests/requests/generateParams.mustache | 2 +- .../python/tests/requests/requests.mustache | 6 +-- 18 files changed, 93 insertions(+), 60 deletions(-) create mode 100644 generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java rename templates/python/{tests => }/snippets/method.mustache (64%) diff --git a/config/clients.config.json b/config/clients.config.json index 7593c223aa..96bfcdd232 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -200,7 +200,7 @@ }, "snippets": { "extension": ".py", - "outputFolder": "snippets" + "outputFolder": "" } }, "ruby": { diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java index 4dfe82b240..099428bb36 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java @@ -3,6 +3,7 @@ import com.algolia.codegen.cts.lambda.*; import com.algolia.codegen.cts.manager.CTSManager; import com.algolia.codegen.cts.manager.CTSManagerFactory; +import com.algolia.codegen.cts.snippets.*; import com.algolia.codegen.cts.tests.*; import com.algolia.codegen.exceptions.*; import com.algolia.codegen.utils.*; @@ -53,8 +54,7 @@ public void processOpts() { String outputFolder = Helpers.getClientConfigField(language, "tests", "outputFolder"); String extension = Helpers.getClientConfigField(language, "tests", "extension"); - setTemplateDir("templates/" + language + "/tests"); - setOutputDir("tests/output/" + language); + setTemplateDir("templates/" + language); ctsManager.addSupportingFiles(supportingFiles); testsGenerators.add(new TestsRequest(language, client)); @@ -63,6 +63,19 @@ public void processOpts() { for (TestsGenerator testGen : testsGenerators) { testGen.addSupportingFiles(supportingFiles, outputFolder, extension); } + + SnippetsGenerator snippetGenerator = new SnippetsGenerator(language, client); + + if (!snippetGenerator.available()) { + return; + } + + String snippetsExtension = Helpers.getClientConfigField(language, "snippets", "extension"); + String snippetsOutputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); + + snippetGenerator.addSupportingFiles(supportingFiles, snippetsOutputFolder, snippetsExtension); + + testsGenerators.add(snippetGenerator); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/DartCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/DartCTSManager.java index bbc85331cf..823dac8d07 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/DartCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/DartCTSManager.java @@ -2,11 +2,9 @@ import com.algolia.codegen.exceptions.GeneratorException; import com.algolia.codegen.utils.*; -import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.WordUtils; -import org.openapitools.codegen.SupportingFile; public class DartCTSManager implements CTSManager { @@ -16,11 +14,6 @@ public DartCTSManager(String clientName) { this.clientName = clientName; } - @Override - public void addSupportingFiles(List supportingFiles) { - // NO-OP - } - @Override public void addDataToBundle(Map bundle) throws GeneratorException { bundle.put("packageVersion", Helpers.getClientConfigField("dart", "packageVersion")); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java index a681aae775..02a923a7f1 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/GoCTSManager.java @@ -8,7 +8,7 @@ public class GoCTSManager implements CTSManager { @Override public void addSupportingFiles(List supportingFiles) { - supportingFiles.add(new SupportingFile("common.mustache", "tests/requests", "common.go")); + supportingFiles.add(new SupportingFile("tests/common.mustache", "tests/output/go/tests/requests", "common.go")); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java index 94aeb74219..86d9b8ab88 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java @@ -15,7 +15,7 @@ public JavaCTSManager(String client) { @Override public void addSupportingFiles(List supportingFiles) { - supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle")); + supportingFiles.add(new SupportingFile("tests/build.mustache", "tests/output/java", "build.gradle")); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java index 47eb5142af..aaf513460d 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavascriptCTSManager.java @@ -16,7 +16,7 @@ public JavascriptCTSManager(String client) { @Override public void addSupportingFiles(List supportingFiles) { - supportingFiles.add(new SupportingFile("package.mustache", "", "package.json")); + supportingFiles.add(new SupportingFile("tests/package.mustache", "tests/output/javascript", "package.json")); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/KotlinCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/KotlinCTSManager.java index 4f84d6ce46..8615c6d424 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/KotlinCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/KotlinCTSManager.java @@ -2,9 +2,7 @@ import com.algolia.codegen.exceptions.GeneratorException; import com.algolia.codegen.utils.*; -import java.util.List; import java.util.Map; -import org.openapitools.codegen.SupportingFile; public class KotlinCTSManager implements CTSManager { @@ -14,11 +12,6 @@ public KotlinCTSManager(String client) { this.client = client; } - @Override - public void addSupportingFiles(List supportingFiles) { - // NO-OP - } - @Override public void addDataToBundle(Map bundle) throws GeneratorException { bundle.put("packageVersion", Helpers.getClientConfigField("kotlin", "packageVersion")); diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/PhpCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/PhpCTSManager.java index 0093e4d61b..b2a11ac43d 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/PhpCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/PhpCTSManager.java @@ -1,14 +1,5 @@ package com.algolia.codegen.cts.manager; -import com.algolia.codegen.exceptions.GeneratorException; import java.util.*; -import org.openapitools.codegen.SupportingFile; -public class PhpCTSManager implements CTSManager { - - @Override - public void addSupportingFiles(List supportingFiles) {} - - @Override - public void addDataToBundle(Map bundle) throws GeneratorException {} -} +public class PhpCTSManager implements CTSManager {} diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/PythonCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/PythonCTSManager.java index 39b906136b..69afdf8193 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/PythonCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/PythonCTSManager.java @@ -15,9 +15,9 @@ public PythonCTSManager(String client) { @Override public void addSupportingFiles(List supportingFiles) { - supportingFiles.add(new SupportingFile("__init__.mustache", "tests/", "__init__.py")); - supportingFiles.add(new SupportingFile("__init__.mustache", "tests/requests", "__init__.py")); - supportingFiles.add(new SupportingFile("__init__.mustache", "tests/client", "__init__.py")); + supportingFiles.add(new SupportingFile("tests/__init__.mustache", "tests/output/python/tests/", "__init__.py")); + supportingFiles.add(new SupportingFile("tests/__init__.mustache", "tests/output/python/tests/requests", "__init__.py")); + supportingFiles.add(new SupportingFile("tests/__init__.mustache", "tests/output/python/tests/client", "__init__.py")); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java new file mode 100644 index 0000000000..7fb1635994 --- /dev/null +++ b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java @@ -0,0 +1,51 @@ +package com.algolia.codegen.cts.snippets; + +import com.algolia.codegen.cts.tests.*; +import com.algolia.codegen.utils.*; +import java.io.File; +import java.util.*; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.SupportingFile; + +public class SnippetsGenerator extends TestsRequest { + + public SnippetsGenerator(String language, String client) { + super(language, client); + } + + protected Map loadRequestCTS() throws Exception { + return super.loadRequestCTS(); + } + + @Override + public boolean available() { + File templates = new File("templates/" + language + "/snippets/method.mustache"); + return templates.exists(); + } + + @Override + public void addSupportingFiles(List supportingFiles, String outputFolder, String extension) { + if (!available()) { + return; + } + + if (!outputFolder.equals("")) { + outputFolder = "/" + outputFolder + "/"; + } else { + outputFolder = "/"; + } + + supportingFiles.add( + new SupportingFile( + "snippets/method.mustache", + "snippets/" + language + outputFolder + Helpers.createClientName(client, language) + extension + ) + ); + } + + @Override + public void run(Map models, Map operations, Map bundle) throws Exception { + super.run(models, operations, bundle); + } +} diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java index fde82695cf..11881dd6dd 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsClient.java @@ -36,7 +36,11 @@ public void addSupportingFiles(List supportingFiles, String outp return; } supportingFiles.add( - new SupportingFile("client/suite.mustache", outputFolder + "/client", Helpers.createClientName(client, language) + extension) + new SupportingFile( + "tests/client/suite.mustache", + "tests/output/" + language + "/" + outputFolder + "/client", + Helpers.createClientName(client, language) + extension + ) ); } diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index 8cb7c1cc11..b40f608467 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -36,23 +36,11 @@ public void addSupportingFiles(List supportingFiles, String outp return; } - // tests generation - supportingFiles.add( - new SupportingFile("requests/requests.mustache", outputFolder + "/requests", Helpers.createClientName(client, language) + extension) - ); - - if (!language.equals("python")) { - return; - } - - // snippets generation - String snippetsExtension = Helpers.getClientConfigField(language, "snippets", "extension"); - String snippetsOutputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); - supportingFiles.add( new SupportingFile( - "snippets/method.mustache", - "../../../" + snippetsOutputFolder + "/" + language + "/" + Helpers.createClientName(client, language) + snippetsExtension + "tests/requests/requests.mustache", + "tests/output/" + language + "/" + outputFolder + "/requests", + Helpers.createClientName(client, language) + extension ) ); } diff --git a/templates/python/tests/snippets/method.mustache b/templates/python/snippets/method.mustache similarity index 64% rename from templates/python/tests/snippets/method.mustache rename to templates/python/snippets/method.mustache index 30ebf052fa..161da143c3 100644 --- a/templates/python/tests/snippets/method.mustache +++ b/templates/python/snippets/method.mustache @@ -10,7 +10,7 @@ class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: """ _client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) - resp = await _client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + resp = await _client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) # use the class directly print(resp) diff --git a/templates/python/tests/client/method.mustache b/templates/python/tests/client/method.mustache index a5bacdbd40..b9b9fa7532 100644 --- a/templates/python/tests/client/method.mustache +++ b/templates/python/tests/client/method.mustache @@ -1 +1 @@ -{{^isError}}_req = {{/isError}}await self._client.{{#lambda.snakecase}}{{{path}}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file +{{^isError}}_req = {{/isError}}await self._client.{{#lambda.snakecase}}{{{path}}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file diff --git a/templates/python/tests/client/step.mustache b/templates/python/tests/client/step.mustache index 5d85cd5695..04d1f043d7 100644 --- a/templates/python/tests/client/step.mustache +++ b/templates/python/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} -{{> client/createClient}} +{{> tests/client/createClient}} {{/isCreateClient}} {{#isVariable}} -{{> client/variable}} +{{> tests/client/variable}} {{/isVariable}} {{#isMethod}} -{{> client/method}} +{{> tests/client/method}} {{/isMethod}} \ No newline at end of file diff --git a/templates/python/tests/client/suite.mustache b/templates/python/tests/client/suite.mustache index 45bb1c6296..277fb05de6 100644 --- a/templates/python/tests/client/suite.mustache +++ b/templates/python/tests/client/suite.mustache @@ -25,12 +25,12 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: {{#steps}} {{#isError}} try: - {{> client/step}} + {{> tests/client/step}} except (ValueError, Exception) as e: assert str(e) == {{#lambda.codeSnakeCase}}"{{{expectedError}}}"{{/lambda.codeSnakeCase}} {{/isError}} {{^isError}} - {{> client/step}} + {{> tests/client/step}} {{#match}} {{#testUserAgent}} regex_user_agent = compile("{{#lambda.escapeSlash}}{{{match}}}{{/lambda.escapeSlash}}") diff --git a/templates/python/tests/requests/generateParams.mustache b/templates/python/tests/requests/generateParams.mustache index e632dd46d2..c204515cf9 100644 --- a/templates/python/tests/requests/generateParams.mustache +++ b/templates/python/tests/requests/generateParams.mustache @@ -1 +1 @@ -{{#isRoot}}{{#lambda.snakecase}}{{{key}}}{{/lambda.snakecase}}={{/isRoot}} {{#useAnonymousKey}}{{#parent}}"{{{key}}}":{{/parent}}{{/useAnonymousKey}} {{#isNull}} None, {{/isNull}} {{#isString}} "{{{value}}}", {{/isString}} {{#isInteger}} {{{value}}}, {{/isInteger}} {{#isLong}} {{{value}}}, {{/isLong}} {{#isDouble}} {{{value}}}, {{/isDouble}} {{#isBoolean}} {{#lambda.titlecase}}{{{value}}}{{/lambda.titlecase}}, {{/isBoolean}} {{#isEnum}} "{{{value}}}", {{/isEnum}} {{#isArray}} [ {{#value}}{{> requests/generateParams}}{{/value}} ], {{/isArray}} {{#isObject}} { {{#value}}{{> requests/generateParams}}{{/value}} }, {{/isObject}} {{#isFreeFormObject}} {{#isAnyType}} { {{#value}}{{#entrySet}}"{{{key}}}":"{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}} }, {{/isAnyType}} {{^isAnyType}} { {{#value}}{{> requests/generateParams}}{{/value}} }, {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file +{{#isRoot}}{{#lambda.snakecase}}{{{key}}}{{/lambda.snakecase}}={{/isRoot}} {{#useAnonymousKey}}{{#parent}}"{{{key}}}":{{/parent}}{{/useAnonymousKey}} {{#isNull}} None, {{/isNull}} {{#isString}} "{{{value}}}", {{/isString}} {{#isInteger}} {{{value}}}, {{/isInteger}} {{#isLong}} {{{value}}}, {{/isLong}} {{#isDouble}} {{{value}}}, {{/isDouble}} {{#isBoolean}} {{#lambda.titlecase}}{{{value}}}{{/lambda.titlecase}}, {{/isBoolean}} {{#isEnum}} "{{{value}}}", {{/isEnum}} {{#isArray}} [ {{#value}}{{> tests/requests/generateParams}}{{/value}} ], {{/isArray}} {{#isObject}} { {{#value}}{{> tests/requests/generateParams}}{{/value}} }, {{/isObject}} {{#isFreeFormObject}} {{#isAnyType}} { {{#value}}{{#entrySet}}"{{{key}}}":"{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}} }, {{/isAnyType}} {{^isAnyType}} { {{#value}}{{> tests/requests/generateParams}}{{/value}} }, {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/python/tests/requests/requests.mustache b/templates/python/tests/requests/requests.mustache index d9ab9de424..dbb31283eb 100644 --- a/templates/python/tests/requests/requests.mustache +++ b/templates/python/tests/requests/requests.mustache @@ -32,7 +32,7 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{ """ {{{testName}}} """ - _req = await self._client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + _req = await self._client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) {{#request}} assert _req.path == "{{{path}}}" @@ -50,13 +50,13 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}{{#isE2E}}E2E{ {{/request}} {{#response}} - raw_resp = await SearchClient(self._e2e_app_id, self._e2e_api_key).{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + raw_resp = await SearchClient(self._e2e_app_id, self._e2e_api_key).{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) {{#statusCode}} assert raw_resp.status_code == {{statusCode}} {{/statusCode}} {{#body}} - resp = await SearchClient(self._e2e_app_id, self._e2e_api_key).{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + resp = await SearchClient(self._e2e_app_id, self._e2e_api_key).{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}} request_options={ {{#requestOptions.headers.parameters}}"headers":loads("""{{{.}}}"""),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}"query_parameters":loads("""{{{.}}}"""),{{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) _expected_body = loads("""{{{.}}}""") assert self._helpers.union(_expected_body, loads(resp.to_json())) == _expected_body {{/body}} From d539d246e27d2d8f3935f2a4edb55cf260889edb Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 12:20:44 +0100 Subject: [PATCH 07/18] fix: paths to partial templates --- templates/dart/tests/client/method.mustache | 2 +- templates/dart/tests/client/step.mustache | 6 +++--- templates/dart/tests/client/suite.mustache | 8 ++++---- templates/dart/tests/param_map.mustache | 2 +- templates/dart/tests/param_object.mustache | 2 +- templates/dart/tests/param_value.mustache | 6 +++--- templates/dart/tests/request_param.mustache | 2 +- templates/dart/tests/requests/requests.mustache | 6 +++--- templates/javascript/tests/client/step.mustache | 6 +++--- templates/javascript/tests/client/suite.mustache | 6 +++--- templates/kotlin/tests/client/method.mustache | 2 +- templates/kotlin/tests/client/step.mustache | 6 +++--- templates/kotlin/tests/client/suite.mustache | 6 +++--- templates/kotlin/tests/param_json_element.mustache | 4 ++-- templates/kotlin/tests/param_json_object.mustache | 2 +- templates/kotlin/tests/param_list.mustache | 2 +- templates/kotlin/tests/param_map.mustache | 2 +- templates/kotlin/tests/param_object.mustache | 2 +- templates/kotlin/tests/param_value.mustache | 2 +- templates/kotlin/tests/request_param.mustache | 2 +- templates/kotlin/tests/requests/requests.mustache | 6 +++--- templates/php/tests/client/method.mustache | 4 ++-- templates/php/tests/client/suite.mustache | 10 +++++----- templates/php/tests/generateParams.mustache | 6 +++--- .../php/tests/requests/requestOptionsParams.mustache | 2 +- templates/php/tests/requests/requests.mustache | 6 +++--- templates/ruby/tests/client/method.mustache | 2 +- templates/ruby/tests/client/step.mustache | 6 +++--- templates/ruby/tests/client/suite.mustache | 6 +++--- templates/ruby/tests/requests/generateParams.mustache | 2 +- templates/ruby/tests/requests/requests.mustache | 6 +++--- templates/scala/tests/client/method.mustache | 2 +- templates/scala/tests/client/step.mustache | 6 +++--- templates/scala/tests/client/suite.mustache | 4 ++-- templates/scala/tests/param_json_element.mustache | 4 ++-- templates/scala/tests/param_json_object.mustache | 2 +- templates/scala/tests/param_list.mustache | 2 +- templates/scala/tests/param_map.mustache | 2 +- templates/scala/tests/param_object.mustache | 2 +- templates/scala/tests/param_optional.mustache | 4 ++-- templates/scala/tests/param_value.mustache | 2 +- templates/scala/tests/request_param.mustache | 2 +- .../scala/tests/requests/requestOptionsParams.mustache | 2 +- templates/scala/tests/requests/requests.mustache | 6 +++--- 44 files changed, 86 insertions(+), 86 deletions(-) diff --git a/templates/dart/tests/client/method.mustache b/templates/dart/tests/client/method.mustache index 261f9b8c24..7e79d814ed 100644 --- a/templates/dart/tests/client/method.mustache +++ b/templates/dart/tests/client/method.mustache @@ -1,5 +1,5 @@ return client.{{path}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} ); \ No newline at end of file diff --git a/templates/dart/tests/client/step.mustache b/templates/dart/tests/client/step.mustache index d968b91bb9..5e73287485 100644 --- a/templates/dart/tests/client/step.mustache +++ b/templates/dart/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} -{{> client/create_client}} +{{> tests/client/create_client}} {{/isCreateClient}} {{#isVariable}} -{{> client/variable}} +{{> tests/client/variable}} {{/isVariable}} {{#isMethod}} -{{> client/method}} +{{> tests/client/method}} {{/isMethod}} \ No newline at end of file diff --git a/templates/dart/tests/client/suite.mustache b/templates/dart/tests/client/suite.mustache index 36b70290eb..f93b32efa8 100644 --- a/templates/dart/tests/client/suite.mustache +++ b/templates/dart/tests/client/suite.mustache @@ -22,13 +22,13 @@ void main() { expectError( '{{{expectedError}}}', () { - {{> client/step}} + {{> tests/client/step}} }, ); {{/isError}} {{^isError}} {{#isCreateClient}} - {{> client/create_client}} + {{> tests/client/create_client}} {{/isCreateClient}} {{#isMethod}} runTest( @@ -42,7 +42,7 @@ void main() { ), call: (client) => client.{{path}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} ), intercept: (request) { @@ -66,4 +66,4 @@ void main() { ); {{/tests}} {{/blocksClient}} -} +} \ No newline at end of file diff --git a/templates/dart/tests/param_map.mustache b/templates/dart/tests/param_map.mustache index 39eaadd881..4397a1fcbe 100644 --- a/templates/dart/tests/param_map.mustache +++ b/templates/dart/tests/param_map.mustache @@ -1 +1 @@ -{ {{#value}}'{{key}}' : {{> param_value}},{{/value}} } \ No newline at end of file +{ {{#value}}'{{key}}' : {{> tests/param_value}},{{/value}} } \ No newline at end of file diff --git a/templates/dart/tests/param_object.mustache b/templates/dart/tests/param_object.mustache index e405db9ca6..4c989974cc 100644 --- a/templates/dart/tests/param_object.mustache +++ b/templates/dart/tests/param_object.mustache @@ -1,5 +1,5 @@ {{{objectName}}}( {{#value}} -{{> request_param}} +{{> tests/request_param}} {{/value}} ) \ No newline at end of file diff --git a/templates/dart/tests/param_value.mustache b/templates/dart/tests/param_value.mustache index b45ac52d67..b6a93a815c 100644 --- a/templates/dart/tests/param_value.mustache +++ b/templates/dart/tests/param_value.mustache @@ -3,9 +3,9 @@ {{#isNumber}}{{{value}}}{{/isNumber}} {{#isBoolean}}{{{value}}}{{/isBoolean}} {{#isEnum}}{{{objectName}}}.fromJson("{{value}}"){{/isEnum}} -{{#isArray}}[{{#value}}{{> param_value}},{{/value}}]{{/isArray}} +{{#isArray}}[{{#value}}{{> tests/param_value}},{{/value}}]{{/isArray}} {{#isFreeFormObject}} {{#isAnyType}}{ {{#value}}{{#entrySet}}'{{{key}}}' : '{{{value}}}',{{/entrySet}}}{{/value}}{{/isAnyType}} -{{^isAnyType}}{{> param_map}}{{/isAnyType}} +{{^isAnyType}}{{> tests/param_map}}{{/isAnyType}} {{/isFreeFormObject}} -{{#isObject}}{{> param_object}}{{/isObject}} \ No newline at end of file +{{#isObject}}{{> tests/param_object}}{{/isObject}} \ No newline at end of file diff --git a/templates/dart/tests/request_param.mustache b/templates/dart/tests/request_param.mustache index f693a2a552..be2a04a688 100644 --- a/templates/dart/tests/request_param.mustache +++ b/templates/dart/tests/request_param.mustache @@ -1,5 +1,5 @@ {{^isAdditionalProperty}} -{{#isKeyAllUpperCase}}{{#lambda.lowercase}}{{&key}}{{/lambda.lowercase}}{{/isKeyAllUpperCase}}{{^isKeyAllUpperCase}}{{#lambda.camelcase}}{{&key}}{{/lambda.camelcase}}{{/isKeyAllUpperCase}} : {{> param_value}}, +{{#isKeyAllUpperCase}}{{#lambda.lowercase}}{{&key}}{{/lambda.lowercase}}{{/isKeyAllUpperCase}}{{^isKeyAllUpperCase}}{{#lambda.camelcase}}{{&key}}{{/lambda.camelcase}}{{/isKeyAllUpperCase}} : {{> tests/param_value}}, {{/isAdditionalProperty}} {{#isAdditionalProperty}} additionalProperties : { '{{{key}}}' : '{{{value}}}' }, diff --git a/templates/dart/tests/requests/requests.mustache b/templates/dart/tests/requests/requests.mustache index 2593dfd044..4bdceaf74f 100644 --- a/templates/dart/tests/requests/requests.mustache +++ b/templates/dart/tests/requests/requests.mustache @@ -20,7 +20,7 @@ void main() { ), call: (client) => client.{{method}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} {{#hasRequestOptions}} requestOptions : RequestOptions( @@ -34,7 +34,7 @@ void main() { {{#requestOptions.queryParameters}} urlParameters: { {{#requestOptions.queryParameters.parametersWithDataType}} - '{{{key}}}' : {{> param_value}}, + '{{{key}}}' : {{> tests/param_value}}, {{/requestOptions.queryParameters.parametersWithDataType}} }, {{/requestOptions.queryParameters}} @@ -68,4 +68,4 @@ void main() { ); {{/tests}} {{/blocksRequests}} -} +} \ No newline at end of file diff --git a/templates/javascript/tests/client/step.mustache b/templates/javascript/tests/client/step.mustache index 04a32846f2..56a27039c8 100644 --- a/templates/javascript/tests/client/step.mustache +++ b/templates/javascript/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} - {{> client/createClient}} + {{> tests/client/createClient}} {{/isCreateClient}} {{#isVariable}} - const result = {{> client/variable}} + const result = {{> tests/client/variable}} {{/isVariable}} {{#isMethod}} - const result = await ({{> client/method}}) as unknown as EchoResponse; + const result = await ({{> tests/client/method}}) as unknown as EchoResponse; {{/isMethod}} \ No newline at end of file diff --git a/templates/javascript/tests/client/suite.mustache b/templates/javascript/tests/client/suite.mustache index 8488779e59..cf201483bf 100644 --- a/templates/javascript/tests/client/suite.mustache +++ b/templates/javascript/tests/client/suite.mustache @@ -22,14 +22,14 @@ describe('{{testType}}', () => { {{#steps}} {{#isError}} try { - {{> client/step}} + {{> tests/client/step}} throw new Error('test is expected to throw error'); } catch(e) { expect((e as Error).message).toMatch("{{{expectedError}}}"); } {{/isError}} {{^isError}} - {{> client/step}} + {{> tests/client/step}} {{#testUserAgent}} expect(decodeURIComponent(result.algoliaAgent)).toMatch(/{{{match}}}/); @@ -47,4 +47,4 @@ describe('{{testType}}', () => { {{/tests}} }) -{{/blocksClient}} +{{/blocksClient}} \ No newline at end of file diff --git a/templates/kotlin/tests/client/method.mustache b/templates/kotlin/tests/client/method.mustache index fb8b82a3db..d52cb41d37 100644 --- a/templates/kotlin/tests/client/method.mustache +++ b/templates/kotlin/tests/client/method.mustache @@ -1,5 +1,5 @@ client.{{path}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} ) \ No newline at end of file diff --git a/templates/kotlin/tests/client/step.mustache b/templates/kotlin/tests/client/step.mustache index 5d85cd5695..04d1f043d7 100644 --- a/templates/kotlin/tests/client/step.mustache +++ b/templates/kotlin/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} -{{> client/createClient}} +{{> tests/client/createClient}} {{/isCreateClient}} {{#isVariable}} -{{> client/variable}} +{{> tests/client/variable}} {{/isVariable}} {{#isMethod}} -{{> client/method}} +{{> tests/client/method}} {{/isMethod}} \ No newline at end of file diff --git a/templates/kotlin/tests/client/suite.mustache b/templates/kotlin/tests/client/suite.mustache index d3b9e66a8b..e84545bb9a 100644 --- a/templates/kotlin/tests/client/suite.mustache +++ b/templates/kotlin/tests/client/suite.mustache @@ -22,19 +22,19 @@ class {{clientPrefix}}Test { {{#steps}} {{#isError}} assertFails { - {{> client/step}} + {{> tests/client/step}} }.let { error -> assertError(error, "{{{expectedError}}}") } {{/isError}} {{^isError}} {{#isCreateClient}} - {{> client/createClient}} + {{> tests/client/createClient}} {{/isCreateClient}} {{#isMethod}} client.runTest( call = { {{path}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} ) }, diff --git a/templates/kotlin/tests/param_json_element.mustache b/templates/kotlin/tests/param_json_element.mustache index b6bf593054..4f2f0d39db 100644 --- a/templates/kotlin/tests/param_json_element.mustache +++ b/templates/kotlin/tests/param_json_element.mustache @@ -20,12 +20,12 @@ JsonPrimitive({{{value}}}), JsonPrimitive("{{{value}}}"), {{/isEnum}} {{#isArray}} -{{> param_json_element}}, +{{> tests/param_json_element}}, {{/isArray}} {{#isFreeFormObject}} buildJsonObject { {{#value}} - put("{{{key}}}", {{> param_json_element}}) + put("{{{key}}}", {{> tests/param_json_element}}) {{/value}} }, {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/kotlin/tests/param_json_object.mustache b/templates/kotlin/tests/param_json_object.mustache index 7fe3cb5860..fb079aa4c6 100644 --- a/templates/kotlin/tests/param_json_object.mustache +++ b/templates/kotlin/tests/param_json_object.mustache @@ -1,5 +1,5 @@ buildJsonObject { {{#value}} - put("{{{key}}}", {{> param_json_element}}) + put("{{{key}}}", {{> tests/param_json_element}}) {{/value}} } \ No newline at end of file diff --git a/templates/kotlin/tests/param_list.mustache b/templates/kotlin/tests/param_list.mustache index 0cb3ac8e3f..b9896bd612 100644 --- a/templates/kotlin/tests/param_list.mustache +++ b/templates/kotlin/tests/param_list.mustache @@ -1 +1 @@ -{{#oneOfModel}}{{{parentClassName}}}.of{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}(listOf({{#value}}{{> param_value}}{{/value}})){{/oneOfModel}}{{^oneOfModel}}listOf({{#value}}{{> param_value}}{{/value}}){{/oneOfModel}} \ No newline at end of file +{{#oneOfModel}}{{{parentClassName}}}.of{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}(listOf({{#value}}{{> tests/param_value}}{{/value}})){{/oneOfModel}}{{^oneOfModel}}listOf({{#value}}{{> tests/param_value}}{{/value}}){{/oneOfModel}} \ No newline at end of file diff --git a/templates/kotlin/tests/param_map.mustache b/templates/kotlin/tests/param_map.mustache index 0efaa58a97..237dc8ee22 100644 --- a/templates/kotlin/tests/param_map.mustache +++ b/templates/kotlin/tests/param_map.mustache @@ -1 +1 @@ -mapOf({{#value}} "{{key}}" to {{> param_value}}{{/value}}) \ No newline at end of file +mapOf({{#value}} "{{key}}" to {{> tests/param_value}}{{/value}}) \ No newline at end of file diff --git a/templates/kotlin/tests/param_object.mustache b/templates/kotlin/tests/param_object.mustache index e405db9ca6..4c989974cc 100644 --- a/templates/kotlin/tests/param_object.mustache +++ b/templates/kotlin/tests/param_object.mustache @@ -1,5 +1,5 @@ {{{objectName}}}( {{#value}} -{{> request_param}} +{{> tests/request_param}} {{/value}} ) \ No newline at end of file diff --git a/templates/kotlin/tests/param_value.mustache b/templates/kotlin/tests/param_value.mustache index 7f558aa821..76c4c02be0 100644 --- a/templates/kotlin/tests/param_value.mustache +++ b/templates/kotlin/tests/param_value.mustache @@ -1 +1 @@ -{{#isNull}}empty(),{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}.of("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}},{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}L){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}},{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isBoolean}}{{#isEnum}}{{{objectName}}}.entries.first { it.value == "{{{value}}}" },{{/isEnum}}{{#isArray}}{{> param_list}},{{/isArray}}{{#isObject}}{{> param_object}},{{/isObject}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> param_json_object}},{{/isSimpleObject}}{{^isSimpleObject}}{{#isAnyType}}{{> param_json_any}},{{/isAnyType}}{{^isAnyType}}{{> param_map}},{{/isAnyType}}{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file +{{#isNull}}empty(),{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}.of("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}},{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}L){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}},{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}.of({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}},{{/isBoolean}}{{#isEnum}}{{{objectName}}}.entries.first { it.value == "{{{value}}}" },{{/isEnum}}{{#isArray}}{{> tests/param_list}},{{/isArray}}{{#isObject}}{{> tests/param_object}},{{/isObject}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> tests/param_json_object}},{{/isSimpleObject}}{{^isSimpleObject}}{{#isAnyType}}{{> tests/param_json_any}},{{/isAnyType}}{{^isAnyType}}{{> tests/param_map}},{{/isAnyType}}{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/kotlin/tests/request_param.mustache b/templates/kotlin/tests/request_param.mustache index 96a3c5853a..91f7021a46 100644 --- a/templates/kotlin/tests/request_param.mustache +++ b/templates/kotlin/tests/request_param.mustache @@ -1 +1 @@ -{{^isAdditionalProperty}}{{#isKeyAllUpperCase}}{{#lambda.lowercase}}{{&key}}{{/lambda.lowercase}}{{/isKeyAllUpperCase}}{{^isKeyAllUpperCase}}{{#lambda.camelcase}}{{&key}}{{/lambda.camelcase}}{{/isKeyAllUpperCase}} = {{> param_value}}{{/isAdditionalProperty}}{{#isAdditionalProperty}}additionalProperties = mapOf("{{key}}" to {{> param_json_element}}){{/isAdditionalProperty}} \ No newline at end of file +{{^isAdditionalProperty}}{{#isKeyAllUpperCase}}{{#lambda.lowercase}}{{&key}}{{/lambda.lowercase}}{{/isKeyAllUpperCase}}{{^isKeyAllUpperCase}}{{#lambda.camelcase}}{{&key}}{{/lambda.camelcase}}{{/isKeyAllUpperCase}} = {{> tests/param_value}}{{/isAdditionalProperty}}{{#isAdditionalProperty}}additionalProperties = mapOf("{{key}}" to {{> tests/param_json_element}}){{/isAdditionalProperty}} \ No newline at end of file diff --git a/templates/kotlin/tests/requests/requests.mustache b/templates/kotlin/tests/requests/requests.mustache index b05abf372a..1760e4f698 100644 --- a/templates/kotlin/tests/requests/requests.mustache +++ b/templates/kotlin/tests/requests/requests.mustache @@ -31,21 +31,21 @@ class {{clientPrefix}}Test { call = { {{method}}( {{#parametersWithDataType}} - {{> request_param}} + {{> tests/request_param}} {{/parametersWithDataType}} {{#hasRequestOptions}} requestOptions = RequestOptions( {{#requestOptions.queryParameters}} urlParameters = buildMap { {{#requestOptions.queryParameters.parametersWithDataType}} - put("{{{key}}}", {{> param_value}}) + put("{{{key}}}", {{> tests/param_value}}) {{/requestOptions.queryParameters.parametersWithDataType}} }, {{/requestOptions.queryParameters}} {{#requestOptions.headers}} headers = buildMap { {{#requestOptions.headers.parametersWithDataType}} - put("{{{key}}}", {{> param_value}}) + put("{{{key}}}", {{> tests/param_value}}) {{/requestOptions.headers.parametersWithDataType}} }, {{/requestOptions.headers}} diff --git a/templates/php/tests/client/method.mustache b/templates/php/tests/client/method.mustache index 514dd7bdfd..f9d8df41e5 100644 --- a/templates/php/tests/client/method.mustache +++ b/templates/php/tests/client/method.mustache @@ -1,3 +1,3 @@ $client->{{{path}}}{{^parametersWithDataType}}();{{/parametersWithDataType}}({{#parametersWithDataType}} -{{> generateParams}} -{{/parametersWithDataType}}); +{{> tests/generateParams}} +{{/parametersWithDataType}}); \ No newline at end of file diff --git a/templates/php/tests/client/suite.mustache b/templates/php/tests/client/suite.mustache index 0c15778135..1bdb9149ce 100644 --- a/templates/php/tests/client/suite.mustache +++ b/templates/php/tests/client/suite.mustache @@ -71,14 +71,14 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface {{#isError}} {{#isCreateClient}} try { - {{> client/createClient}} + {{> tests/client/createClient}} } catch (\Exception $e) { $this->assertEquals($e->getMessage(), '{{{expectedError}}}'); } {{/isCreateClient}} {{#isMethod}} try { - {{> client/method}} + {{> tests/client/method}} } catch (\Exception $e) { $this->assertEquals($e->getMessage(), '{{{expectedError}}}'); } @@ -86,12 +86,12 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface {{/isError}} {{^isError}} {{#isCreateClient}} - {{> client/createClient}} + {{> tests/client/createClient}} // Make sure everything went fine without errors $this->assertIsObject($client); {{/isCreateClient}} {{#isMethod}} - {{> client/method}} + {{> tests/client/method}} {{#match}} {{#testUserAgent}} $this->assertTrue( @@ -128,4 +128,4 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface {{/tests}} {{/blocksClient}} -} +} \ No newline at end of file diff --git a/templates/php/tests/generateParams.mustache b/templates/php/tests/generateParams.mustache index d82a30f08a..814384c3cc 100644 --- a/templates/php/tests/generateParams.mustache +++ b/templates/php/tests/generateParams.mustache @@ -21,16 +21,16 @@ {{{value}}}, {{/isBoolean}} {{#isArray}} - [{{#value}}{{> generateParams}}{{/value}}], + [{{#value}}{{> tests/generateParams}}{{/value}}], {{/isArray}} {{#isObject}} - [{{#value}}{{> generateParams}}{{/value}}], + [{{#value}}{{> tests/generateParams}}{{/value}}], {{/isObject}} {{#isFreeFormObject}} {{#isAnyType}} [{{#value}}{{#entrySet}}'{{{key}}}' => '{{{value}}}'{{^-last}},{{/-last}}{{/entrySet}}{{/value}}], {{/isAnyType}} {{^isAnyType}} - [{{#value}}{{> generateParams}}{{/value}}], + [{{#value}}{{> tests/generateParams}}{{/value}}], {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/php/tests/requests/requestOptionsParams.mustache b/templates/php/tests/requests/requestOptionsParams.mustache index fbfbfa4c17..3bbe369889 100644 --- a/templates/php/tests/requests/requestOptionsParams.mustache +++ b/templates/php/tests/requests/requestOptionsParams.mustache @@ -14,5 +14,5 @@ {{{value}}} {{/isBoolean}} {{#isArray}} - [{{#value}}{{> requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}}] + [{{#value}}{{> tests/requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}}] {{/isArray}} \ No newline at end of file diff --git a/templates/php/tests/requests/requests.mustache b/templates/php/tests/requests/requests.mustache index cbe41f68d8..093b7b12be 100644 --- a/templates/php/tests/requests/requests.mustache +++ b/templates/php/tests/requests/requests.mustache @@ -140,7 +140,7 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface $requestOptions = [ 'queryParameters' => [ {{#requestOptions.queryParameters.parametersWithDataType}} - '{{{key}}}' => {{> requests/requestOptionsParams}}, + '{{{key}}}' => {{> tests/requests/requestOptionsParams}}, {{/requestOptions.queryParameters.parametersWithDataType}} ], 'headers' => [ @@ -151,7 +151,7 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface ]; {{/hasRequestOptions}} $client->{{^hasParameters}}{{{method}}}();{{/hasParameters}}{{#hasParameters}}{{{method}}}( - {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}$requestOptions{{/hasRequestOptions}} + {{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}$requestOptions{{/hasRequestOptions}} );{{/hasParameters}} $this->assertRequests([ @@ -181,7 +181,7 @@ class {{clientPrefix}}Test extends TestCase implements HttpClientInterface {{#response}} $e2eClient = $this->getE2EClient(); $resp = $e2eClient->{{^hasParameters}}{{{method}}}();{{/hasParameters}}{{#hasParameters}}{{{method}}}( - {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}$requestOptions{{/hasRequestOptions}} + {{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}$requestOptions{{/hasRequestOptions}} );{{/hasParameters}} {{#body}} diff --git a/templates/ruby/tests/client/method.mustache b/templates/ruby/tests/client/method.mustache index c466b4f192..869c0a6e14 100644 --- a/templates/ruby/tests/client/method.mustache +++ b/templates/ruby/tests/client/method.mustache @@ -1 +1 @@ -{{^isError}}req = {{/isError}}client.{{#lambda.snakecase}}{{path}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file +{{^isError}}req = {{/isError}}client.{{#lambda.snakecase}}{{path}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) \ No newline at end of file diff --git a/templates/ruby/tests/client/step.mustache b/templates/ruby/tests/client/step.mustache index f82fb51582..854dc9aaf7 100644 --- a/templates/ruby/tests/client/step.mustache +++ b/templates/ruby/tests/client/step.mustache @@ -1,6 +1,6 @@ {{#isCreateClient}} -{{> client/createClient}} +{{> tests/client/createClient}} {{/isCreateClient}} {{#isMethod}} -{{> client/method}} -{{/isMethod}} +{{> tests/client/method}} +{{/isMethod}} \ No newline at end of file diff --git a/templates/ruby/tests/client/suite.mustache b/templates/ruby/tests/client/suite.mustache index 157e0192fa..66546ab0da 100644 --- a/templates/ruby/tests/client/suite.mustache +++ b/templates/ruby/tests/client/suite.mustache @@ -17,13 +17,13 @@ class TestClient{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} < Test: {{#steps}} {{#isError}} begin - {{> client/step}} + {{> tests/client/step}} rescue => e assert_equal({{#lambda.codeSnakeCase}}'{{{expectedError}}}'{{/lambda.codeSnakeCase}}, e.message) end {{/isError}} {{^isError}} - {{> client/step}} + {{> tests/client/step}} {{#match}} {{#testUserAgent}} assert(req.headers['user-agent'].match(/{{{match}}}/)) @@ -42,4 +42,4 @@ class TestClient{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} < Test: {{/tests}} {{/blocksClient}} -end +end \ No newline at end of file diff --git a/templates/ruby/tests/requests/generateParams.mustache b/templates/ruby/tests/requests/generateParams.mustache index 41a77d0761..75573c77d0 100644 --- a/templates/ruby/tests/requests/generateParams.mustache +++ b/templates/ruby/tests/requests/generateParams.mustache @@ -1 +1 @@ -{{#useAnonymousKey}}{{#lambda.escapeRubyKeywords}}{{{key}}}{{/lambda.escapeRubyKeywords}}: {{/useAnonymousKey}}{{#isNull}}nil, {{/isNull}}{{#isString}}"{{{value}}}", {{/isString}}{{#isInteger}}{{{value}}}, {{/isInteger}}{{#isLong}}{{{value}}}, {{/isLong}}{{#isDouble}}{{{value}}}, {{/isDouble}}{{#isBoolean}}{{{value}}}, {{/isBoolean}} {{#isEnum}}'{{{value}}}', {{/isEnum}}{{#isArray}} [ {{#value}}{{> requests/generateParams}}{{/value}} ], {{/isArray}}{{#isObject}} {{{objectName}}}.new({{#value}}{{> requests/generateParams}}{{/value}}), {{/isObject}}{{#isFreeFormObject}} {{#isAnyType}} { {{#value}}{{#entrySet}}'{{{key}}}':"{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}} }, {{/isAnyType}} {{^isAnyType}} { {{#value}}{{> requests/generateParams}}{{/value}} }, {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file +{{#useAnonymousKey}}{{#lambda.escapeRubyKeywords}}{{{key}}}{{/lambda.escapeRubyKeywords}}: {{/useAnonymousKey}}{{#isNull}}nil, {{/isNull}}{{#isString}}"{{{value}}}", {{/isString}}{{#isInteger}}{{{value}}}, {{/isInteger}}{{#isLong}}{{{value}}}, {{/isLong}}{{#isDouble}}{{{value}}}, {{/isDouble}}{{#isBoolean}}{{{value}}}, {{/isBoolean}} {{#isEnum}}'{{{value}}}', {{/isEnum}}{{#isArray}} [ {{#value}}{{> tests/requests/generateParams}}{{/value}} ], {{/isArray}}{{#isObject}} {{{objectName}}}.new({{#value}}{{> tests/requests/generateParams}}{{/value}}), {{/isObject}}{{#isFreeFormObject}} {{#isAnyType}} { {{#value}}{{#entrySet}}'{{{key}}}':"{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}} }, {{/isAnyType}} {{^isAnyType}} { {{#value}}{{> tests/requests/generateParams}}{{/value}} }, {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/ruby/tests/requests/requests.mustache b/templates/ruby/tests/requests/requests.mustache index 73ef56fe2f..21d3e59d30 100644 --- a/templates/ruby/tests/requests/requests.mustache +++ b/templates/ruby/tests/requests/requests.mustache @@ -28,7 +28,7 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} < Test::Unit: {{#tests}} # {{{testName}}} def test_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{testIndex}} - req = @client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + req = @client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) {{#request}} assert_equal(:{{#lambda.lowercase}}{{method}}{{/lambda.lowercase}}, req.method) @@ -44,7 +44,7 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} < Test::Unit: {{/request}} {{#response}} - res = @e2e_client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) + res = @e2e_client.{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}_with_http_info({{#parametersWithDataType}}{{> tests/requests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}{ {{#requestOptions.headers.parameters}}:header_params => JSON.parse('{{{.}}}', :symbolize_names => true),{{/requestOptions.headers.parameters}}{{#requestOptions.queryParameters.parameters}}:query_params => JSON.parse('{{{.}}}', :symbolize_names => true){{/requestOptions.queryParameters.parameters}} }{{/hasRequestOptions}}) {{#statusCode}} assert_equal(res.status, {{statusCode}}) @@ -58,4 +58,4 @@ class Test{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}} < Test::Unit: {{/tests}} {{/blocksRequests}} -end +end \ No newline at end of file diff --git a/templates/scala/tests/client/method.mustache b/templates/scala/tests/client/method.mustache index ae5c9fb2f8..3e27ddacb8 100644 --- a/templates/scala/tests/client/method.mustache +++ b/templates/scala/tests/client/method.mustache @@ -1,7 +1,7 @@ Await.ready( client.{{path}}{{#isCustom}}[Any]{{/isCustom}}( {{#parametersWithDataType}} - {{> request_param}}{{^-last}},{{/-last}} + {{> tests/request_param}}{{^-last}},{{/-last}} {{/parametersWithDataType}} ), Duration.Inf diff --git a/templates/scala/tests/client/step.mustache b/templates/scala/tests/client/step.mustache index d70255fbff..b3fc9d32a3 100644 --- a/templates/scala/tests/client/step.mustache +++ b/templates/scala/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} - {{> client/createClient}} + {{> tests/client/createClient}} {{/isCreateClient}} {{#isVariable}} - {{> client/variable}} + {{> tests/client/variable}} {{/isVariable}} {{#isMethod}} - {{> client/method}} + {{> tests/client/method}} {{/isMethod}} \ No newline at end of file diff --git a/templates/scala/tests/client/suite.mustache b/templates/scala/tests/client/suite.mustache index c178396dfc..1570c2401c 100644 --- a/templates/scala/tests/client/suite.mustache +++ b/templates/scala/tests/client/suite.mustache @@ -46,11 +46,11 @@ class {{clientPrefix}}Test extends AnyFunSuite { {{#isError}} assertError("{{{expectedError}}}") { - {{> client/step}} + {{> tests/client/step}} } {{/isError}} {{^isError}} - {{> client/step}} + {{> tests/client/step}} {{#match}} {{#testUserAgent}} val regexp = """{{{match}}}""".r diff --git a/templates/scala/tests/param_json_element.mustache b/templates/scala/tests/param_json_element.mustache index 50a806870a..a2500ec718 100644 --- a/templates/scala/tests/param_json_element.mustache +++ b/templates/scala/tests/param_json_element.mustache @@ -20,8 +20,8 @@ JBool({{{value}}}) JString("{{{value}}}") {{/isEnum}} {{#isArray}} -JArray({{#value}}{{> param_json_element}}{{^-last}},{{/-last}}{{/value}}) +JArray({{#value}}{{> tests/param_json_element}}{{^-last}},{{/-last}}{{/value}}) {{/isArray}} {{#isFreeFormObject}} -JObject(List({{#value}}JField("{{{key}}}", {{> param_json_element}}){{^-last}},{{/-last}}{{/value}})) +JObject(List({{#value}}JField("{{{key}}}", {{> tests/param_json_element}}){{^-last}},{{/-last}}{{/value}})) {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/scala/tests/param_json_object.mustache b/templates/scala/tests/param_json_object.mustache index 3e8f1b6214..43d0854aae 100644 --- a/templates/scala/tests/param_json_object.mustache +++ b/templates/scala/tests/param_json_object.mustache @@ -1 +1 @@ -JObject(List({{#value}}JField("{{{key}}}", {{> param_json_element}}){{^-last}},{{/-last}}{{/value}})) \ No newline at end of file +JObject(List({{#value}}JField("{{{key}}}", {{> tests/param_json_element}}){{^-last}},{{/-last}}{{/value}})) \ No newline at end of file diff --git a/templates/scala/tests/param_list.mustache b/templates/scala/tests/param_list.mustache index 93c1f0f783..7d92dc9e49 100644 --- a/templates/scala/tests/param_list.mustache +++ b/templates/scala/tests/param_list.mustache @@ -1 +1 @@ -{{#oneOfModel}}{{{parentClassName}}}{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}(Seq({{#value}}{{> param_value}}{{^-last}},{{/-last}}{{/value}})){{/oneOfModel}}{{^oneOfModel}}Seq({{#value}}{{> param_value}}{{^-last}},{{/-last}}{{/value}}){{/oneOfModel}} \ No newline at end of file +{{#oneOfModel}}{{{parentClassName}}}{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}(Seq({{#value}}{{> tests/param_value}}{{^-last}},{{/-last}}{{/value}})){{/oneOfModel}}{{^oneOfModel}}Seq({{#value}}{{> tests/param_value}}{{^-last}},{{/-last}}{{/value}}){{/oneOfModel}} \ No newline at end of file diff --git a/templates/scala/tests/param_map.mustache b/templates/scala/tests/param_map.mustache index 1599e9c66f..201f92ff2d 100644 --- a/templates/scala/tests/param_map.mustache +++ b/templates/scala/tests/param_map.mustache @@ -1 +1 @@ -Map({{#value}}"{{key}}" -> {{> param_value}}{{^-last}},{{/-last}}{{/value}}) \ No newline at end of file +Map({{#value}}"{{key}}" -> {{> tests/param_value}}{{^-last}},{{/-last}}{{/value}}) \ No newline at end of file diff --git a/templates/scala/tests/param_object.mustache b/templates/scala/tests/param_object.mustache index 47ac316d3c..abf1f9002e 100644 --- a/templates/scala/tests/param_object.mustache +++ b/templates/scala/tests/param_object.mustache @@ -1,5 +1,5 @@ {{{objectName}}}( {{#value}} -{{> request_param}}, +{{> tests/request_param}}, {{/value}} ) \ No newline at end of file diff --git a/templates/scala/tests/param_optional.mustache b/templates/scala/tests/param_optional.mustache index 9667eeb126..35b7ed799d 100644 --- a/templates/scala/tests/param_optional.mustache +++ b/templates/scala/tests/param_optional.mustache @@ -1,6 +1,6 @@ {{^isOptional}} -{{> param_value}} +{{> tests/param_value}} {{/isOptional}} {{#isOptional}} -Some({{> param_value}}) +Some({{> tests/param_value}}) {{/isOptional}} \ No newline at end of file diff --git a/templates/scala/tests/param_value.mustache b/templates/scala/tests/param_value.mustache index ee7d0dcc65..36f0e6bfb4 100644 --- a/templates/scala/tests/param_value.mustache +++ b/templates/scala/tests/param_value.mustache @@ -1 +1 @@ -{{#isNull}}null{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}}{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}L){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}}{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isBoolean}}{{#isEnum}}{{{objectName}}}.withName("{{{value}}}"){{/isEnum}}{{#isArray}}{{> param_list}}{{/isArray}}{{#isObject}}{{> param_object}}{{/isObject}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> param_json_object}}{{/isSimpleObject}}{{^isSimpleObject}}{{#isAnyType}}{{> param_json_any}}{{/isAnyType}}{{^isAnyType}}{{> param_map}}{{/isAnyType}}{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file +{{#isNull}}null{{/isNull}}{{#isString}}{{#oneOfModel}}{{{parentClassName}}}("{{{value}}}"){{/oneOfModel}}{{^oneOfModel}}"{{{value}}}"{{/oneOfModel}}{{/isString}}{{#isInteger}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isInteger}}{{#isLong}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}L){{/oneOfModel}}{{^oneOfModel}}{{{value}}}L{{/oneOfModel}}{{/isLong}}{{#isDouble}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isDouble}}{{#isBoolean}}{{#oneOfModel}}{{{parentClassName}}}({{{value}}}){{/oneOfModel}}{{^oneOfModel}}{{{value}}}{{/oneOfModel}}{{/isBoolean}}{{#isEnum}}{{{objectName}}}.withName("{{{value}}}"){{/isEnum}}{{#isArray}}{{> tests/param_list}}{{/isArray}}{{#isObject}}{{> tests/param_object}}{{/isObject}}{{#isFreeFormObject}}{{#isSimpleObject}}{{> tests/param_json_object}}{{/isSimpleObject}}{{^isSimpleObject}}{{#isAnyType}}{{> tests/param_json_any}}{{/isAnyType}}{{^isAnyType}}{{> tests/param_map}}{{/isAnyType}}{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/scala/tests/request_param.mustache b/templates/scala/tests/request_param.mustache index 634c6fb382..08e7ce575e 100644 --- a/templates/scala/tests/request_param.mustache +++ b/templates/scala/tests/request_param.mustache @@ -1 +1 @@ -{{^isAdditionalProperty}}{{#lambda.scalaIdentifier}}{{&key}}{{/lambda.scalaIdentifier}} = {{> param_optional}}{{/isAdditionalProperty}}{{#isAdditionalProperty}}additionalProperties = Some(List(JField("{{key}}", {{> param_json_element}}))){{/isAdditionalProperty}} \ No newline at end of file +{{^isAdditionalProperty}}{{#lambda.scalaIdentifier}}{{&key}}{{/lambda.scalaIdentifier}} = {{> tests/param_optional}}{{/isAdditionalProperty}}{{#isAdditionalProperty}}additionalProperties = Some(List(JField("{{key}}", {{> tests/param_json_element}}))){{/isAdditionalProperty}} \ No newline at end of file diff --git a/templates/scala/tests/requests/requestOptionsParams.mustache b/templates/scala/tests/requests/requestOptionsParams.mustache index 87136d906c..c5f5f7643c 100644 --- a/templates/scala/tests/requests/requestOptionsParams.mustache +++ b/templates/scala/tests/requests/requestOptionsParams.mustache @@ -17,5 +17,5 @@ {{{value}}} {{/isBoolean}} {{#isArray}} - Seq({{#value}}{{> requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}}) + Seq({{#value}}{{> tests/requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}}) {{/isArray}} \ No newline at end of file diff --git a/templates/scala/tests/requests/requests.mustache b/templates/scala/tests/requests/requests.mustache index ca963ea697..db8067ff36 100644 --- a/templates/scala/tests/requests/requests.mustache +++ b/templates/scala/tests/requests/requests.mustache @@ -40,12 +40,12 @@ class {{clientPrefix}}Test extends AnyFunSuite { val (client, echo) = testClient() val future = client.{{method}}{{#isCustomRequest}}[JObject]{{/isCustomRequest}}( {{#parametersWithDataType}} - {{> request_param}}{{^-last}},{{/-last}} + {{> tests/request_param}}{{^-last}},{{/-last}} {{/parametersWithDataType}} {{#hasRequestOptions}} , requestOptions = Some(RequestOptions.builder() {{#requestOptions.queryParameters.parametersWithDataType}} - .withQueryParameter("{{{key}}}", {{> requests/requestOptionsParams}}) + .withQueryParameter("{{{key}}}", {{> tests/requests/requestOptionsParams}}) {{/requestOptions.queryParameters.parametersWithDataType}} {{#requestOptions.headers.parametersWithDataType}} .withHeader("{{{key}}}", "{{{value}}}") @@ -95,4 +95,4 @@ class {{clientPrefix}}Test extends AnyFunSuite { {{/tests}} {{/blocksRequests}} -} +} \ No newline at end of file From fb026e955c94380696aab49a262271219a89f874 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 12:24:06 +0100 Subject: [PATCH 08/18] fix: paths to partial templates for java --- templates/java/tests/client/method.mustache | 2 +- templates/java/tests/client/step.mustache | 6 +++--- templates/java/tests/client/suite.mustache | 4 ++-- templates/java/tests/generateInnerParams.mustache | 8 ++++---- templates/java/tests/generateParams.mustache | 2 +- templates/java/tests/requests/requests.mustache | 6 +++--- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/templates/java/tests/client/method.mustache b/templates/java/tests/client/method.mustache index 75d1d239d5..37a979a05d 100644 --- a/templates/java/tests/client/method.mustache +++ b/templates/java/tests/client/method.mustache @@ -1,2 +1,2 @@ -client{{#path}}.{{.}}{{/path}}({{#parametersWithDataType}}{{> generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); +client{{#path}}.{{.}}{{/path}}({{#parametersWithDataType}}{{> tests/generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}); EchoResponse result = echo.getLastResponse(); \ No newline at end of file diff --git a/templates/java/tests/client/step.mustache b/templates/java/tests/client/step.mustache index d70255fbff..b3fc9d32a3 100644 --- a/templates/java/tests/client/step.mustache +++ b/templates/java/tests/client/step.mustache @@ -1,9 +1,9 @@ {{#isCreateClient}} - {{> client/createClient}} + {{> tests/client/createClient}} {{/isCreateClient}} {{#isVariable}} - {{> client/variable}} + {{> tests/client/variable}} {{/isVariable}} {{#isMethod}} - {{> client/method}} + {{> tests/client/method}} {{/isMethod}} \ No newline at end of file diff --git a/templates/java/tests/client/suite.mustache b/templates/java/tests/client/suite.mustache index c780dae781..2b8004bb0c 100644 --- a/templates/java/tests/client/suite.mustache +++ b/templates/java/tests/client/suite.mustache @@ -41,13 +41,13 @@ class {{client}}ClientTests { {{#isError}} { Exception exception = assertThrows(Exception.class, () -> { - {{> client/step}} + {{> tests/client/step}} }); assertEquals("{{{expectedError}}}", exception.getMessage()); } {{/isError}} {{^isError}} - {{> client/step}} + {{> tests/client/step}} {{#match}} {{#testUserAgent}} { String regexp = "{{#lambda.escapeSlash}}{{{match}}}{{/lambda.escapeSlash}}"; diff --git a/templates/java/tests/generateInnerParams.mustache b/templates/java/tests/generateInnerParams.mustache index b4f66b05d1..c101f9e0bb 100644 --- a/templates/java/tests/generateInnerParams.mustache +++ b/templates/java/tests/generateInnerParams.mustache @@ -20,17 +20,17 @@ {{{objectName}}}.fromValue("{{{value}}}") {{/isEnum}} {{#isArray}} - List.of({{#value}}{{> generateParams}}{{^-last}},{{/-last}}{{/value}}) + List.of({{#value}}{{> tests/generateParams}}{{^-last}},{{/-last}}{{/value}}) {{/isArray}} {{#isObject}} new {{{objectName}}}() - {{#value}}{{#isAdditionalProperty}}.setAdditionalProperty("{{{key}}}", {{> generateParams}}){{/isAdditionalProperty}}{{^isAdditionalProperty}}.set{{#lambda.pascalcase}}{{{key}}}{{/lambda.pascalcase}}({{> generateParams}}){{/isAdditionalProperty}}{{/value}} + {{#value}}{{#isAdditionalProperty}}.setAdditionalProperty("{{{key}}}", {{> tests/generateParams}}){{/isAdditionalProperty}}{{^isAdditionalProperty}}.set{{#lambda.pascalcase}}{{{key}}}{{/lambda.pascalcase}}({{> tests/generateParams}}){{/isAdditionalProperty}}{{/value}} {{/isObject}} {{#isFreeFormObject}} {{#isAnyType}} Map.of({{#value}}{{#entrySet}}"{{{key}}}", "{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}}) {{/isAnyType}} {{^isAnyType}} - Map.of({{#value}}"{{{key}}}", {{> generateParams}}{{^-last}},{{/-last}}{{/value}}) + Map.of({{#value}}"{{{key}}}", {{> tests/generateParams}}{{^-last}},{{/-last}}{{/value}}) {{/isAnyType}} -{{/isFreeFormObject}} +{{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/java/tests/generateParams.mustache b/templates/java/tests/generateParams.mustache index 65134a1c89..6ee9804264 100644 --- a/templates/java/tests/generateParams.mustache +++ b/templates/java/tests/generateParams.mustache @@ -1 +1 @@ -{{#oneOfModel}}{{^hasWrapper}}{{> generateInnerParams}}{{/hasWrapper}}{{#hasWrapper}}{{{parentClassName}}}.of{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}({{> generateInnerParams}}){{/hasWrapper}}{{/oneOfModel}}{{^oneOfModel}}{{> generateInnerParams}}{{/oneOfModel}} \ No newline at end of file +{{#oneOfModel}}{{^hasWrapper}}{{> tests/generateInnerParams}}{{/hasWrapper}}{{#hasWrapper}}{{{parentClassName}}}.of{{#x-one-of-explicit-name}}{{{type}}}{{/x-one-of-explicit-name}}({{> tests/generateInnerParams}}){{/hasWrapper}}{{/oneOfModel}}{{^oneOfModel}}{{> tests/generateInnerParams}}{{/oneOfModel}} \ No newline at end of file diff --git a/templates/java/tests/requests/requests.mustache b/templates/java/tests/requests/requests.mustache index cb0e7420d2..a7b39e179d 100644 --- a/templates/java/tests/requests/requests.mustache +++ b/templates/java/tests/requests/requests.mustache @@ -51,9 +51,9 @@ class {{client}}RequestsTests { @DisplayName("{{{testName}}}") void {{method}}Test{{testIndex}}() { assertDoesNotThrow(() -> { - client.{{method}}({{#parametersWithDataType}}{{> generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#isGeneric}}, Object.class{{/isGeneric}}{{#hasRequestOptions}}, new RequestOptions() + client.{{method}}({{#parametersWithDataType}}{{> tests/generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#isGeneric}}, Object.class{{/isGeneric}}{{#hasRequestOptions}}, new RequestOptions() {{#requestOptions.queryParameters.parametersWithDataType}} - .addExtraQueryParameters("{{{key}}}", {{> generateInnerParams}}) + .addExtraQueryParameters("{{{key}}}", {{> tests/generateInnerParams}}) {{/requestOptions.queryParameters.parametersWithDataType}} {{#requestOptions.headers.parametersWithDataType}} .addExtraHeader("{{{key}}}", "{{{value}}}") @@ -106,4 +106,4 @@ class {{client}}RequestsTests { } {{/tests}} {{/blocksRequests}} -} +} \ No newline at end of file From 39ae642d06aa5ac8595dee86cb9c2cfab0b7b28c Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 14:13:04 +0100 Subject: [PATCH 09/18] feat: js templates --- config/clients.config.json | 4 +++ config/generation.config.mjs | 3 ++- scripts/cts/generate.ts | 7 ++--- snippets/javascript/package.json | 18 +++++++++++++ snippets/javascript/tsconfig.json | 11 ++++++++ templates/javascript/snippets/method.mustache | 26 +++++++++++++++++++ templates/python/snippets/method.mustache | 2 ++ 7 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 snippets/javascript/package.json create mode 100644 snippets/javascript/tsconfig.json create mode 100644 templates/javascript/snippets/method.mustache diff --git a/config/clients.config.json b/config/clients.config.json index 96bfcdd232..2a738e834b 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -75,6 +75,10 @@ "tests": { "extension": ".test.ts", "outputFolder": "src" + }, + "snippets": { + "extension": ".ts", + "outputFolder": "src" } }, "php": { diff --git a/config/generation.config.mjs b/config/generation.config.mjs index 5bd35d40b9..879554cc84 100644 --- a/config/generation.config.mjs +++ b/config/generation.config.mjs @@ -3,6 +3,7 @@ export const patterns = [ 'specs/bundled/*.yml', 'clients/**', + 'snippets/**', '!clients/README.md', '!clients/**/.openapi-generator-ignore', @@ -16,6 +17,7 @@ export const patterns = [ 'tests/output/java/build.gradle', // JavaScript + '!snippets/javascript/*.json', '!clients/algoliasearch-client-javascript/*', '!clients/algoliasearch-client-javascript/.github/**', '!clients/algoliasearch-client-javascript/.yarn/**', @@ -78,7 +80,6 @@ export const patterns = [ '!clients/algoliasearch-client-dart/packages/algoliasearch/lib/algoliasearch.dart', // Python - 'snippets/python/**', '!snippets/python/pyproject.toml', 'clients/algoliasearch-client-python/**', '!clients/algoliasearch-client-python/algoliasearch/http/**', diff --git a/scripts/cts/generate.ts b/scripts/cts/generate.ts index be1f022168..1b41eb4d7f 100644 --- a/scripts/cts/generate.ts +++ b/scripts/cts/generate.ts @@ -1,5 +1,5 @@ import { buildSpecs } from '../buildSpecs.js'; -import { buildCustomGenerators, CI, run, toAbsolutePath } from '../common.js'; +import { buildCustomGenerators, CI, exists, run, toAbsolutePath } from '../common.js'; import { getTestOutputFolder } from '../config.js'; import { formatter } from '../formatter.js'; import { generateOpenapitools } from '../pre-gen/index.js'; @@ -60,8 +60,9 @@ export async function ctsGenerateMany(generators: Generator[]): Promise { await formatter(lang, toAbsolutePath(`tests/output/${lang}`)); - if (lang === 'python') { - await formatter(lang, toAbsolutePath(`snippets/${lang}`)); + const snippetsPath = toAbsolutePath(`snippets/${lang}`); + if (await exists(snippetsPath)) { + await formatter(lang, snippetsPath); } } } diff --git a/snippets/javascript/package.json b/snippets/javascript/package.json new file mode 100644 index 0000000000..13bb956c2c --- /dev/null +++ b/snippets/javascript/package.json @@ -0,0 +1,18 @@ +{ + "name": "javascript-snippets", + "version": "1.0.0", + "dependencies": { + "@algolia/client-abtesting": "link:../../clients/algoliasearch-client-javascript/packages/client-abtesting", + "@algolia/client-analytics": "link:../../clients/algoliasearch-client-javascript/packages/client-analytics", + "@algolia/client-common": "link:../../clients/algoliasearch-client-javascript/packages/client-common", + "@algolia/client-insights": "link:../../clients/algoliasearch-client-javascript/packages/client-insights", + "@algolia/client-personalization": "link:../../clients/algoliasearch-client-javascript/packages/client-personalization", + "@algolia/client-query-suggestions": "link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions", + "@algolia/client-search": "link:../../clients/algoliasearch-client-javascript/packages/client-search", + "@algolia/ingestion": "link:../../clients/algoliasearch-client-javascript/packages/ingestion", + "@algolia/monitoring": "link:../../clients/algoliasearch-client-javascript/packages/monitoring", + "@algolia/recommend": "link:../../clients/algoliasearch-client-javascript/packages/recommend", + "@algolia/requester-node-http": "link:../../clients/algoliasearch-client-javascript/packages/requester-node-http", + "algoliasearch": "link:../../clients/algoliasearch-client-javascript/packages/algoliasearch" + } +} diff --git a/snippets/javascript/tsconfig.json b/snippets/javascript/tsconfig.json new file mode 100644 index 0000000000..e3bf1dbcfa --- /dev/null +++ b/snippets/javascript/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../config/base.tsconfig.json", + "compilerOptions": { + "typeRoots": ["../../node_modules/@types"], + "types": ["node", "jest"], + "lib": ["dom", "esnext"], + "outDir": "dist" + }, + "include": ["src"], + "exclude": ["dist", "node_modules"] +} diff --git a/templates/javascript/snippets/method.mustache b/templates/javascript/snippets/method.mustache new file mode 100644 index 0000000000..e50dbc912f --- /dev/null +++ b/templates/javascript/snippets/method.mustache @@ -0,0 +1,26 @@ +/* eslint no-console: ["error", { allow: ["log"] }] */ + +import { {{client}} } from '{{{import}}}'; +import type { RequestOptions } from '{{{npmNamespace}}}/client-common'; + +{{#blocksRequests}} +{{#snippet}} +// Snippet for the {{method}} method. +// +// {{{description}}} +export async function snippetFor{{method}}(): Promise { + const client = {{client}}("YOUR_APP_ID", "YOUR_API_KEY", {{#hasRegionalHost}}'YOUR_APP_ID_REGION', {{/hasRegionalHost}}); + + {{#hasRequestOptions}}const requestOptions: RequestOptions = { + {{#requestOptions.queryParameters.parameters}}queryParameters: {{{.}}},{{/requestOptions.queryParameters.parameters}} + {{#requestOptions.headers.parameters}}headers: {{{.}}}{{/requestOptions.headers.parameters}} + };{{/hasRequestOptions}} + + const response = await client.{{method}}({{#hasParameters}}{{{parameters}}}{{/hasParameters}}{{#hasRequestOptions}}, requestOptions{{/hasRequestOptions}}); + + // use typed response + console.log(response); +} + +{{/snippet}} +{{/blocksRequests}} \ No newline at end of file diff --git a/templates/python/snippets/method.mustache b/templates/python/snippets/method.mustache index 161da143c3..1eb1e5332a 100644 --- a/templates/python/snippets/method.mustache +++ b/templates/python/snippets/method.mustache @@ -6,6 +6,8 @@ class Snippet{{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}: {{#snippet}} async def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}(): """ + Snippet for the {{method}} method. + {{{description}}} """ _client = {{#lambda.pascalcase}}{{{client}}}{{/lambda.pascalcase}}("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}) From 46c88a7a6067496ce24ecb27fadf9bd2619ac031 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 14:34:40 +0100 Subject: [PATCH 10/18] chore: java cleanup --- .../codegen/cts/snippets/SnippetsGenerator.java | 4 ---- .../algolia/codegen/cts/tests/TestsRequest.java | 15 ++++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java index 7fb1635994..4201db997b 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java @@ -14,10 +14,6 @@ public SnippetsGenerator(String language, String client) { super(language, client); } - protected Map loadRequestCTS() throws Exception { - return super.loadRequestCTS(); - } - @Override public boolean available() { File templates = new File("templates/" + language + "/snippets/method.mustache"); diff --git a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java index b40f608467..0ba837f776 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java +++ b/generators/src/main/java/com/algolia/codegen/cts/tests/TestsRequest.java @@ -35,7 +35,6 @@ public void addSupportingFiles(List supportingFiles, String outp if (!available()) { return; } - supportingFiles.add( new SupportingFile( "tests/requests/requests.mustache", @@ -71,13 +70,11 @@ public void run(Map models, Map Request[] op = cts.get(operationId); List tests = new ArrayList<>(); - Map snippet = new HashMap<>(); for (int i = 0; i < op.length; i++) { Map test = new HashMap<>(); Request req = op[i]; test.put("method", operationId); - String testName = req.testName == null ? operationId + i : req.testName; - test.put("testName", testName); + test.put("testName", req.testName == null ? operationId + i : req.testName); test.put("testIndex", i); try { @@ -148,10 +145,6 @@ public void run(Map models, Map paramsType.enhanceParameters(req.parameters, test, ope); tests.add(test); - if (i == 0) { - snippet = test; - snippet.put("description", testName); - } } catch (CTSException e) { e.setTestName((String) test.get("testName")); throw e; @@ -159,8 +152,12 @@ public void run(Map models, Map } Map testObj = new HashMap<>(); testObj.put("tests", tests); - testObj.put("snippet", snippet); testObj.put("operationId", operationId); + + Map snippet = (Map) tests.get(0); + snippet.put("description", snippet.get("testName")); + testObj.put("snippet", snippet); + blocks.add(testObj); } bundle.put("blocksRequests", blocks); From 74bbf79ba45908a0186e4f019fa5ca90ebdc46b7 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 14:35:10 +0100 Subject: [PATCH 11/18] dynamic artifact stuff --- .github/workflows/check.yml | 4 ++-- scripts/ci/githubActions/createMatrix.ts | 5 ++++- scripts/ci/githubActions/types.ts | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 9d4c4ffc42..b8cef7f7b7 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -289,7 +289,7 @@ jobs: run: yarn cli cts run javascript - name: Zip artifact before storing - run: zip -r -y clients-javascript.zip clients/algoliasearch-client-javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).testsToStore }} -x "**/node_modules**" "**/.yarn/cache/**" "**/.yarn/install-state.gz" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/.nx/**" + run: zip -r -y clients-javascript.zip clients/algoliasearch-client-javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).testsToStore }} ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).snippetsToStore }} -x "**/node_modules**" "**/.yarn/cache/**" "**/.yarn/install-state.gz" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/.nx/**" - name: Store javascript clients uses: actions/upload-artifact@v4 @@ -367,7 +367,7 @@ jobs: run: yarn cli cts run ${{ matrix.client.language }} - name: Zip artifact before storing - run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} -x "**/node_modules**" "**/__pycache__/**" "**/.yarn/cache/**" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" "**/target/**" "**/.dart_tool/**" + run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} ${{ matrix.client.snippetsToStore }} -x "**/node_modules**" "**/__pycache__/**" "**/.yarn/cache/**" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" "**/target/**" "**/.dart_tool/**" - name: Store ${{ matrix.client.language }} clients uses: actions/upload-artifact@v4 diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index 12d1fbb189..50dc0fb408 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -91,6 +91,8 @@ async function createClientMatrix(baseBranch: string): Promise { }) .join(' '); + const snippetsToStore = `snippets/${language}`; + const toRun = matrix[language].toRun.join(' '); let buildCommand = `yarn cli build clients ${language} ${toRun}`; @@ -118,7 +120,7 @@ async function createClientMatrix(baseBranch: string): Promise { testsToStore = `${testsToStore} ${testsRootFolder}/package.json`; break; case 'python': - testsToStore = `${testsToStore} ${testsRootFolder}/poetry.lock snippets/python`; + testsToStore = `${testsToStore} ${testsRootFolder}/poetry.lock`; break; case 'ruby': testsToStore = `${testsToStore} ${testsRootFolder}/Gemfile.lock`; @@ -136,6 +138,7 @@ async function createClientMatrix(baseBranch: string): Promise { testsRootFolder, testsToDelete, testsToStore, + snippetsToStore, }); } diff --git a/scripts/ci/githubActions/types.ts b/scripts/ci/githubActions/types.ts index bc83bf84f7..bef0b77201 100644 --- a/scripts/ci/githubActions/types.ts +++ b/scripts/ci/githubActions/types.ts @@ -45,6 +45,10 @@ export type ClientMatrix = BaseMatrix & { * The test output path to store in the artifact. */ testsToStore: string; + /** + * The snippets output path to store in the artifact. + */ + snippetsToStore: string; }; export type SpecMatrix = Pick & { From a02568ccf183570fd5abb701f5afd3cbcee8b536 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 15:01:54 +0100 Subject: [PATCH 12/18] feat: gen for php --- config/clients.config.json | 4 +++ scripts/formatter.ts | 2 +- templates/php/snippets/method.mustache | 43 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 templates/php/snippets/method.mustache diff --git a/config/clients.config.json b/config/clients.config.json index 2a738e834b..d9cfedd0e5 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -102,6 +102,10 @@ "tests": { "extension": "Test.php", "outputFolder": "src" + }, + "snippets": { + "extension": ".php", + "outputFolder": "src" } }, "go": { diff --git a/scripts/formatter.ts b/scripts/formatter.ts index 6bfec38f44..31b4c8c17a 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -19,7 +19,7 @@ export async function formatter(language: string, folder: string): Promise break; case 'php': await runComposerInstall(); - cmd = `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --rules=@PhpCsFixer --using-cache=no --allow-risky=yes`; + cmd = `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --verbose --rules=@PhpCsFixer --using-cache=no --allow-risky=yes`; break; case 'go': cmd = `cd ${folder} && goimports -w . && golangci-lint run --fix`; diff --git a/templates/php/snippets/method.mustache b/templates/php/snippets/method.mustache new file mode 100644 index 0000000000..e142a05491 --- /dev/null +++ b/templates/php/snippets/method.mustache @@ -0,0 +1,43 @@ +', ''{{#hasRegionalHost}}, 'YOUR_APP_ID_REGION'{{/hasRegionalHost}}); + + {{#hasRequestOptions}} + $requestOptions = [ + 'queryParameters' => [ + {{#requestOptions.queryParameters.parametersWithDataType}} + '{{{key}}}' => {{> tests/requests/requestOptionsParams}}, + {{/requestOptions.queryParameters.parametersWithDataType}} + ], + 'headers' => [ + {{#requestOptions.headers.parametersWithDataType}} + '{{{key}}}' => '{{{value}}}', + {{/requestOptions.headers.parametersWithDataType}} + ] + ]; + {{/hasRequestOptions}} + + $response = $client->{{^hasParameters}}{{{method}}}();{{/hasParameters}}{{#hasParameters}}{{{method}}}({{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}}{{#hasRequestOptions}}$requestOptions{{/hasRequestOptions}});{{/hasParameters}} + + // play with the response + var_dump($response); + } + + {{/snippet}} + {{/blocksRequests}} +} \ No newline at end of file From e47fca3d0ca6c333340687be6abdc4afe9264e20 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 15:06:30 +0100 Subject: [PATCH 13/18] fix: formatters --- scripts/formatter.ts | 35 ++++++++----- snippets/javascript/yarn.lock | 97 +++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 snippets/javascript/yarn.lock diff --git a/scripts/formatter.ts b/scripts/formatter.ts index 31b4c8c17a..505f513263 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -3,53 +3,60 @@ import { createSpinner } from './spinners.js'; export async function formatter(language: string, folder: string): Promise { const spinner = createSpinner(`running formatter for '${language}' in '${folder}'`); - let cmd = ''; switch (language) { case 'javascript': - cmd = `yarn eslint --ext=ts,json ${folder} --fix --no-error-on-unmatched-pattern`; + await run('yarn && yarn eslint --ext=ts,json . --fix --no-error-on-unmatched-pattern', { + cwd: folder, + }); break; case 'java': - cmd = `find ${folder} -type f -name "*.java" | xargs java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + await run(`find ${folder} -type f -name "*.java" | xargs java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ -jar /tmp/java-formatter.jar -r \ - && yarn prettier --no-error-on-unmatched-pattern --write ${folder}/**/*.java`; + && yarn prettier --no-error-on-unmatched-pattern --write ${folder}/**/*.java`); break; case 'php': await runComposerInstall(); - cmd = `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --verbose --rules=@PhpCsFixer --using-cache=no --allow-risky=yes`; + await run( + `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --verbose --rules=@PhpCsFixer --using-cache=no --allow-risky=yes` + ); break; case 'go': - cmd = `cd ${folder} && goimports -w . && golangci-lint run --fix`; + await run('goimports -w . && golangci-lint run --fix', { cwd: folder }); break; case 'kotlin': - cmd = `./gradle/gradlew -p ${folder} spotlessApply`; + await run(`./gradle/gradlew -p ${folder} spotlessApply`); break; case 'csharp': - cmd = `cd ${folder} && dotnet format`; + await run('dotnet format', { cwd: folder }); break; case 'dart': if (folder.includes('tests')) { - cmd = `(cd ${folder} && dart pub get && dart fix --apply && dart format .)`; + await run('dart pub get && dart fix --apply && dart format .', { cwd: folder }); } else { - cmd = `(cd ${folder} && dart pub get && melos bs && melos build --no-select && melos lint)`; + await run('dart pub get && melos bs && melos build --no-select && melos lint', { + cwd: folder, + }); } break; case 'python': - cmd = `(cd ${folder} && poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run autopep8 -r --in-place --aggressive . && poetry run autoflake -r --remove-unused-variables --remove-all-unused-imports --in-place . && poetry run isort . && poetry run black . && poetry run flake8 --ignore=E501,W503 .)`; + await run( + 'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run autopep8 -r --in-place --aggressive . && poetry run autoflake -r --remove-unused-variables --remove-all-unused-imports --in-place . && poetry run isort . && poetry run black . && poetry run flake8 --ignore=E501,W503 .', + { cwd: folder } + ); break; case 'ruby': - cmd = `cd ${folder} && bundle install && bundle exec rubocop -a --fail-level W`; + await run('bundle install && bundle exec rubocop -a --fail-level W', { cwd: folder }); break; case 'scala': - cmd = `(cd ${folder} && sbt -Dsbt.server.forcestart=true scalafmtAll scalafmtSbt)`; + await run('sbt -Dsbt.server.forcestart=true scalafmtAll scalafmtSbt', { cwd: folder }); break; default: spinner.warn(`no formatter for '${language}'`); return; } - await run(cmd); spinner.succeed(); } diff --git a/snippets/javascript/yarn.lock b/snippets/javascript/yarn.lock new file mode 100644 index 0000000000..cf65089acf --- /dev/null +++ b/snippets/javascript/yarn.lock @@ -0,0 +1,97 @@ +# This file is generated by running "yarn install" inside your project. +# Manual changes might be lost - proceed with caution! + +__metadata: + version: 8 + cacheKey: 10 + +"@algolia/client-abtesting@link:../../clients/algoliasearch-client-javascript/packages/client-abtesting::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-abtesting@link:../../clients/algoliasearch-client-javascript/packages/client-abtesting::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-analytics@link:../../clients/algoliasearch-client-javascript/packages/client-analytics::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-analytics@link:../../clients/algoliasearch-client-javascript/packages/client-analytics::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-common@link:../../clients/algoliasearch-client-javascript/packages/client-common::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-common@link:../../clients/algoliasearch-client-javascript/packages/client-common::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-insights@link:../../clients/algoliasearch-client-javascript/packages/client-insights::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-insights@link:../../clients/algoliasearch-client-javascript/packages/client-insights::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-personalization@link:../../clients/algoliasearch-client-javascript/packages/client-personalization::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-personalization@link:../../clients/algoliasearch-client-javascript/packages/client-personalization::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-query-suggestions@link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-query-suggestions@link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/client-search@link:../../clients/algoliasearch-client-javascript/packages/client-search::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/client-search@link:../../clients/algoliasearch-client-javascript/packages/client-search::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/ingestion@link:../../clients/algoliasearch-client-javascript/packages/ingestion::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/ingestion@link:../../clients/algoliasearch-client-javascript/packages/ingestion::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/monitoring@link:../../clients/algoliasearch-client-javascript/packages/monitoring::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/monitoring@link:../../clients/algoliasearch-client-javascript/packages/monitoring::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/recommend@link:../../clients/algoliasearch-client-javascript/packages/recommend::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/recommend@link:../../clients/algoliasearch-client-javascript/packages/recommend::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"@algolia/requester-node-http@link:../../clients/algoliasearch-client-javascript/packages/requester-node-http::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "@algolia/requester-node-http@link:../../clients/algoliasearch-client-javascript/packages/requester-node-http::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"algoliasearch@link:../../clients/algoliasearch-client-javascript/packages/algoliasearch::locator=javascript-snippets%40workspace%3A.": + version: 0.0.0-use.local + resolution: "algoliasearch@link:../../clients/algoliasearch-client-javascript/packages/algoliasearch::locator=javascript-snippets%40workspace%3A." + languageName: node + linkType: soft + +"javascript-snippets@workspace:.": + version: 0.0.0-use.local + resolution: "javascript-snippets@workspace:." + dependencies: + "@algolia/client-abtesting": "link:../../clients/algoliasearch-client-javascript/packages/client-abtesting" + "@algolia/client-analytics": "link:../../clients/algoliasearch-client-javascript/packages/client-analytics" + "@algolia/client-common": "link:../../clients/algoliasearch-client-javascript/packages/client-common" + "@algolia/client-insights": "link:../../clients/algoliasearch-client-javascript/packages/client-insights" + "@algolia/client-personalization": "link:../../clients/algoliasearch-client-javascript/packages/client-personalization" + "@algolia/client-query-suggestions": "link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions" + "@algolia/client-search": "link:../../clients/algoliasearch-client-javascript/packages/client-search" + "@algolia/ingestion": "link:../../clients/algoliasearch-client-javascript/packages/ingestion" + "@algolia/monitoring": "link:../../clients/algoliasearch-client-javascript/packages/monitoring" + "@algolia/recommend": "link:../../clients/algoliasearch-client-javascript/packages/recommend" + "@algolia/requester-node-http": "link:../../clients/algoliasearch-client-javascript/packages/requester-node-http" + algoliasearch: "link:../../clients/algoliasearch-client-javascript/packages/algoliasearch" + languageName: unknown + linkType: soft From 6f14852d7c76fabbad731161293c3466a9647e8c Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 15:20:26 +0100 Subject: [PATCH 14/18] feat: gen for java --- config/clients.config.json | 4 +++ .../codegen/cts/manager/JavaCTSManager.java | 1 + templates/java/snippets/method.mustache | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 templates/java/snippets/method.mustache diff --git a/config/clients.config.json b/config/clients.config.json index d9cfedd0e5..c31299aee9 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -20,6 +20,10 @@ "tests": { "extension": ".test.java", "outputFolder": "src/test/java/com/algolia" + }, + "snippets": { + "extension": ".java", + "outputFolder": "src/test/java/com/algolia" } }, "javascript": { diff --git a/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java b/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java index 86d9b8ab88..6422d6539e 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java +++ b/generators/src/main/java/com/algolia/codegen/cts/manager/JavaCTSManager.java @@ -16,6 +16,7 @@ public JavaCTSManager(String client) { @Override public void addSupportingFiles(List supportingFiles) { supportingFiles.add(new SupportingFile("tests/build.mustache", "tests/output/java", "build.gradle")); + supportingFiles.add(new SupportingFile("tests/build.mustache", "snippets/java", "build.gradle")); } @Override diff --git a/templates/java/snippets/method.mustache b/templates/java/snippets/method.mustache new file mode 100644 index 0000000000..8a9589dc12 --- /dev/null +++ b/templates/java/snippets/method.mustache @@ -0,0 +1,27 @@ +package com.algolia.methods.snippets; + +import com.algolia.model.{{import}}.*; +import com.algolia.api.{{client}}; + +class Snippet{{client}} { + {{#blocksRequests}} + {{#snippet}} + // Snippet for the {{method}} method. + // + // {{{description}}} + void SnippetFor{{#lambda.pascalcase}}{{method}}{{/lambda.pascalcase}}() { + {{client}} client = new {{client}}("YOUR_APP_ID", "YOUR_API_KEY"{{#hasRegionalHost}}, "YOUR_APP_ID_REGION"{{/hasRegionalHost}}); + + client.{{method}}({{#parametersWithDataType}}{{> tests/generateParams}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#isGeneric}}, Object.class{{/isGeneric}}{{#hasRequestOptions}}, new RequestOptions() + {{#requestOptions.queryParameters.parametersWithDataType}} + .addExtraQueryParameters("{{{key}}}", {{> tests/generateInnerParams}}) + {{/requestOptions.queryParameters.parametersWithDataType}} + {{#requestOptions.headers.parametersWithDataType}} + .addExtraHeader("{{{key}}}", "{{{value}}}") + {{/requestOptions.headers.parametersWithDataType}} + {{/hasRequestOptions}}); + } + + {{/snippet}} + {{/blocksRequests}} +} \ No newline at end of file From e29d9aa26ec4e922773472b43607a293071e9ac3 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 15:22:42 +0100 Subject: [PATCH 15/18] fix: formatter --- scripts/formatter.ts | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/scripts/formatter.ts b/scripts/formatter.ts index 505f513263..2cdcea0f31 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -3,60 +3,53 @@ import { createSpinner } from './spinners.js'; export async function formatter(language: string, folder: string): Promise { const spinner = createSpinner(`running formatter for '${language}' in '${folder}'`); + let cmd = ''; switch (language) { case 'javascript': - await run('yarn && yarn eslint --ext=ts,json . --fix --no-error-on-unmatched-pattern', { - cwd: folder, - }); + cmd = `YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn eslint --ext=ts,json ${folder} --fix --no-error-on-unmatched-pattern`; break; case 'java': - await run(`find ${folder} -type f -name "*.java" | xargs java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + cmd = `find ${folder} -type f -name "*.java" | xargs java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ -jar /tmp/java-formatter.jar -r \ - && yarn prettier --no-error-on-unmatched-pattern --write ${folder}/**/*.java`); + && yarn prettier --no-error-on-unmatched-pattern --write ${folder}/**/*.java`; break; case 'php': await runComposerInstall(); - await run( - `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --verbose --rules=@PhpCsFixer --using-cache=no --allow-risky=yes` - ); + cmd = `PHP_CS_FIXER_IGNORE_ENV=1 php clients/algoliasearch-client-php/vendor/bin/php-cs-fixer fix ${folder} --rules=@PhpCsFixer --using-cache=no --allow-risky=yes`; break; case 'go': - await run('goimports -w . && golangci-lint run --fix', { cwd: folder }); + cmd = `cd ${folder} && goimports -w . && golangci-lint run --fix`; break; case 'kotlin': - await run(`./gradle/gradlew -p ${folder} spotlessApply`); + cmd = `./gradle/gradlew -p ${folder} spotlessApply`; break; case 'csharp': - await run('dotnet format', { cwd: folder }); + cmd = `cd ${folder} && dotnet format`; break; case 'dart': if (folder.includes('tests')) { - await run('dart pub get && dart fix --apply && dart format .', { cwd: folder }); + cmd = `(cd ${folder} && dart pub get && dart fix --apply && dart format .)`; } else { - await run('dart pub get && melos bs && melos build --no-select && melos lint', { - cwd: folder, - }); + cmd = `(cd ${folder} && dart pub get && melos bs && melos build --no-select && melos lint)`; } break; case 'python': - await run( - 'poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run autopep8 -r --in-place --aggressive . && poetry run autoflake -r --remove-unused-variables --remove-all-unused-imports --in-place . && poetry run isort . && poetry run black . && poetry run flake8 --ignore=E501,W503 .', - { cwd: folder } - ); + cmd = `(cd ${folder} && poetry lock --no-update && poetry install --sync && pip freeze > requirements.txt && poetry run autopep8 -r --in-place --aggressive . && poetry run autoflake -r --remove-unused-variables --remove-all-unused-imports --in-place . && poetry run isort . && poetry run black . && poetry run flake8 --ignore=E501,W503 .)`; break; case 'ruby': - await run('bundle install && bundle exec rubocop -a --fail-level W', { cwd: folder }); + cmd = `cd ${folder} && bundle install && bundle exec rubocop -a --fail-level W`; break; case 'scala': - await run('sbt -Dsbt.server.forcestart=true scalafmtAll scalafmtSbt', { cwd: folder }); + cmd = `(cd ${folder} && sbt -Dsbt.server.forcestart=true scalafmtAll scalafmtSbt)`; break; default: spinner.warn(`no formatter for '${language}'`); return; } + await run(cmd); spinner.succeed(); } From e406deedccb203df649b3f8add7f17880ed939fa Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 15:28:46 +0100 Subject: [PATCH 16/18] fix: formatter for js snippets --- scripts/cts/generate.ts | 3 +++ scripts/formatter.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/cts/generate.ts b/scripts/cts/generate.ts index 1b41eb4d7f..4ba8c52a2e 100644 --- a/scripts/cts/generate.ts +++ b/scripts/cts/generate.ts @@ -43,6 +43,9 @@ export async function ctsGenerateMany(generators: Generator[]): Promise { await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', { cwd: 'tests/output/javascript', }); + await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', { + cwd: 'snippets/javascript', + }); } if (lang === 'go') { diff --git a/scripts/formatter.ts b/scripts/formatter.ts index 2cdcea0f31..6bfec38f44 100644 --- a/scripts/formatter.ts +++ b/scripts/formatter.ts @@ -6,7 +6,7 @@ export async function formatter(language: string, folder: string): Promise let cmd = ''; switch (language) { case 'javascript': - cmd = `YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install && yarn eslint --ext=ts,json ${folder} --fix --no-error-on-unmatched-pattern`; + cmd = `yarn eslint --ext=ts,json ${folder} --fix --no-error-on-unmatched-pattern`; break; case 'java': cmd = `find ${folder} -type f -name "*.java" | xargs java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ From c96601c483bce6a16f11e982600ca1874c987bb6 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 16:53:40 +0100 Subject: [PATCH 17/18] fix: move logic in generator --- .../algolia/codegen/cts/AlgoliaCTSGenerator.java | 14 +------------- .../codegen/cts/snippets/SnippetsGenerator.java | 3 +++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java index 099428bb36..288d8bf0d0 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java @@ -59,23 +59,11 @@ public void processOpts() { testsGenerators.add(new TestsRequest(language, client)); testsGenerators.add(new TestsClient(language, client)); + testsGenerators.add(new SnippetsGenerator(language, client)); for (TestsGenerator testGen : testsGenerators) { testGen.addSupportingFiles(supportingFiles, outputFolder, extension); } - - SnippetsGenerator snippetGenerator = new SnippetsGenerator(language, client); - - if (!snippetGenerator.available()) { - return; - } - - String snippetsExtension = Helpers.getClientConfigField(language, "snippets", "extension"); - String snippetsOutputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); - - snippetGenerator.addSupportingFiles(supportingFiles, snippetsOutputFolder, snippetsExtension); - - testsGenerators.add(snippetGenerator); } @Override diff --git a/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java index 4201db997b..6034ea9dad 100644 --- a/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/cts/snippets/SnippetsGenerator.java @@ -26,6 +26,9 @@ public void addSupportingFiles(List supportingFiles, String outp return; } + extension = Helpers.getClientConfigField(language, "snippets", "extension"); + outputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder"); + if (!outputFolder.equals("")) { outputFolder = "/" + outputFolder + "/"; } else { From 1624f043bdefc84a693574edf028a3d8ff2d35ac Mon Sep 17 00:00:00 2001 From: shortcuts Date: Wed, 10 Jan 2024 17:30:01 +0100 Subject: [PATCH 18/18] fix: csharp --- templates/csharp/tests/forceMapGenerics.mustache | 2 +- templates/csharp/tests/generateGenerics.mustache | 2 +- templates/csharp/tests/generateParams.mustache | 10 +++++----- .../tests/requests/requestOptionsParams.mustache | 2 +- templates/csharp/tests/requests/requests.mustache | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/templates/csharp/tests/forceMapGenerics.mustache b/templates/csharp/tests/forceMapGenerics.mustache index 3020766220..1f1d6a9d18 100644 --- a/templates/csharp/tests/forceMapGenerics.mustache +++ b/templates/csharp/tests/forceMapGenerics.mustache @@ -1 +1 @@ -{{#isFreeFormObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}{{^value.0}}object{{/value.0}}>{{/isFreeFormObject}} \ No newline at end of file +{{#isFreeFormObject}} tests/generateGenerics}}{{/isAnyType}}{{/value.0}}{{^value.0}}object{{/value.0}}>{{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/csharp/tests/generateGenerics.mustache b/templates/csharp/tests/generateGenerics.mustache index 21368de4a3..ee5f5d12fa 100644 --- a/templates/csharp/tests/generateGenerics.mustache +++ b/templates/csharp/tests/generateGenerics.mustache @@ -1 +1 @@ -{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> generateGenerics}}>{{/value.0}}{{/isArray}}{{#isFreeFormObject}}{{^isSimpleObject}} generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file +{{#isArray}}{{#value.0}}<{{#oneOfModel}}{{parentClassName}}{{/oneOfModel}}{{^oneOfModel}}{{objectName}}{{/oneOfModel}}{{> tests/generateGenerics}}>{{/value.0}}{{/isArray}}{{#isFreeFormObject}}{{^isSimpleObject}} tests/generateGenerics}}{{/isAnyType}}{{/value.0}}>{{/isSimpleObject}}{{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/csharp/tests/generateParams.mustache b/templates/csharp/tests/generateParams.mustache index b8a4406ce1..cf34a97df4 100644 --- a/templates/csharp/tests/generateParams.mustache +++ b/templates/csharp/tests/generateParams.mustache @@ -20,13 +20,13 @@ var {{{key}}}{{suffix}} = ({{{objectName}}})Enum.Parse(typeof({{{objectName}}}), "{{#lambda.pascalcase}}{{{value}}}{{/lambda.pascalcase}}"); {{/isEnum}} {{#isArray}} - var {{{key}}}{{suffix}} = new List{{> generateGenerics}}(); - {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.Add({{> maybeConvertOneOf}});{{/value}} + var {{{key}}}{{suffix}} = new List{{> tests/generateGenerics}}(); + {{#value}}{{> tests/generateParams}}{{parent}}{{parentSuffix}}.Add({{> tests/maybeConvertOneOf}});{{/value}} {{/isArray}} {{#isObject}} var {{{key}}}{{suffix}} = new {{{objectName}}}(); { - {{#value}}{{> generateParams}}{{#isAdditionalProperty}}{{parent}}{{parentSuffix}}.AdditionalProperties.Add("{{{key}}}", {{> maybeConvertOneOf}});{{/isAdditionalProperty}}{{^isAdditionalProperty}}{{parent}}{{parentSuffix}}.{{#lambda.pascalcase}}{{#lambda.csharpIdentifier}}{{&key}}{{/lambda.csharpIdentifier}}{{/lambda.pascalcase}} = {{> maybeConvertOneOf}};{{/isAdditionalProperty}}{{/value}} + {{#value}}{{> tests/generateParams}}{{#isAdditionalProperty}}{{parent}}{{parentSuffix}}.AdditionalProperties.Add("{{{key}}}", {{> tests/maybeConvertOneOf}});{{/isAdditionalProperty}}{{^isAdditionalProperty}}{{parent}}{{parentSuffix}}.{{#lambda.pascalcase}}{{#lambda.csharpIdentifier}}{{&key}}{{/lambda.csharpIdentifier}}{{/lambda.pascalcase}} = {{> tests/maybeConvertOneOf}};{{/isAdditionalProperty}}{{/value}} } {{/isObject}} {{#isFreeFormObject}} @@ -34,9 +34,9 @@ var {{{key}}}{{suffix}} = new Dictionary {{ {{#value}}{{#entrySet}}"{{{key}}}", "{{{value}}}"{{^-last}},{{/-last}}{{/entrySet}}{{/value}} }}; {{/isAnyType}} {{^isAnyType}} - var {{{key}}}{{suffix}} = new Dictionary{{> forceMapGenerics}}(); + var {{{key}}}{{suffix}} = new Dictionary{{> tests/forceMapGenerics}}(); { - {{#value}}{{> generateParams}}{{parent}}{{parentSuffix}}.Add("{{{key}}}", {{> maybeConvertOneOf}});{{/value}} + {{#value}}{{> tests/generateParams}}{{parent}}{{parentSuffix}}.Add("{{{key}}}", {{> tests/maybeConvertOneOf}});{{/value}} } {{/isAnyType}} {{/isFreeFormObject}} \ No newline at end of file diff --git a/templates/csharp/tests/requests/requestOptionsParams.mustache b/templates/csharp/tests/requests/requestOptionsParams.mustache index a765a50357..5635ba7fce 100644 --- a/templates/csharp/tests/requests/requestOptionsParams.mustache +++ b/templates/csharp/tests/requests/requestOptionsParams.mustache @@ -17,5 +17,5 @@ {{{value}}} {{/isBoolean}} {{#isArray}} - new List{ {{#value}}{{> requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}} } + new List{ {{#value}}{{> tests/requests/requestOptionsParams}}{{^-last}},{{/-last}}{{/value}} } {{/isArray}} \ No newline at end of file diff --git a/templates/csharp/tests/requests/requests.mustache b/templates/csharp/tests/requests/requests.mustache index a0179fa94e..e42cb48af4 100644 --- a/templates/csharp/tests/requests/requests.mustache +++ b/templates/csharp/tests/requests/requests.mustache @@ -28,17 +28,17 @@ public class {{client}}RequestTests [Fact(DisplayName = "{{{testName}}}")] public async Task {{#lambda.pascalcase}}{{method}}Test{{testIndex}}{{/lambda.pascalcase}}() { - {{#parametersWithDataType}}{{> generateParams}}{{/parametersWithDataType}} + {{#parametersWithDataType}}{{> tests/generateParams}}{{/parametersWithDataType}} {{#hasRequestOptions}} var requestOptions = new RequestOptions(); {{#requestOptions.queryParameters.parametersWithDataType}} - requestOptions.QueryParameters.Add("{{{key}}}", {{> requests/requestOptionsParams}}); + requestOptions.QueryParameters.Add("{{{key}}}", {{> tests/requests/requestOptionsParams}}); {{/requestOptions.queryParameters.parametersWithDataType}} {{#requestOptions.headers.parametersWithDataType}} requestOptions.Headers.Add("{{{key}}}", "{{{value}}}"); {{/requestOptions.headers.parametersWithDataType}} {{/hasRequestOptions}} - await _client.{{#lambda.pascalcase}}{{method}}{{/lambda.pascalcase}}Async{{#isGeneric}}{{/isGeneric}}({{#parametersWithDataType}}{{> maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#hasRequestOptions}}, requestOptions{{/hasRequestOptions}}); + await _client.{{#lambda.pascalcase}}{{method}}{{/lambda.pascalcase}}Async{{#isGeneric}}{{/isGeneric}}({{#parametersWithDataType}}{{> tests/maybeConvertOneOf}}{{^-last}},{{/-last}}{{/parametersWithDataType}}{{#hasRequestOptions}}, requestOptions{{/hasRequestOptions}}); EchoResponse req = _echo.LastResponse; {{#request}}