From 0c878938cd9055398f555d0e7e0b753b2ffd18d3 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Wed, 15 Oct 2025 00:00:54 +0200 Subject: [PATCH 1/4] snippets: remove all the >LOG --- scripts/specs/__tests__/snippets.test.ts | 107 ++++++++++------------ scripts/specs/snippets.ts | 11 +++ templates/csharp/snippets/method.mustache | 4 + templates/dart/snippets/method.mustache | 4 + templates/java/snippets/method.mustache | 4 + templates/scala/snippets/method.mustache | 6 +- templates/swift/snippets/method.mustache | 4 + 7 files changed, 81 insertions(+), 59 deletions(-) diff --git a/scripts/specs/__tests__/snippets.test.ts b/scripts/specs/__tests__/snippets.test.ts index 1c24bd8b8ff..b3ec98a4d42 100644 --- a/scripts/specs/__tests__/snippets.test.ts +++ b/scripts/specs/__tests__/snippets.test.ts @@ -4,15 +4,20 @@ import { generateSnippetsJSON } from '../snippets.ts'; import type { CodeSamples } from '../types.ts'; describe('init', () => { - it('parses a multi line import', () => { + it('parses a multi line init', () => { expect( JSON.stringify( generateSnippetsJSON({ - foo: { - default: ` + csharp: { + ope: { + default: ` // Initialize the client var client = new QuerySuggestionsClient( - new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") + new QuerySuggestionsConfig( + "ALGOLIA_APPLICATION_ID", + "ALGOLIA_API_KEY", + "ALGOLIA_APPLICATION_REGION" + ) ); // Call the API @@ -38,7 +43,10 @@ var response = await client.CreateConfigAsync( } ); // >LOG +// print the response +Console.WriteLine(response); `, + }, }, } as unknown as CodeSamples), null, @@ -46,46 +54,35 @@ var response = await client.CreateConfigAsync( ), ).toMatchInlineSnapshot(` "{ - "foo": { - "default": "\\n // Initialize the client\\nvar client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"\\",\\n SourceIndices = new List\\n {\\n new SourceIndex\\n {\\n IndexName = \\"\\",\\n Facets = new List { new Facet { Attribute = \\"test\\" } },\\n Generate = new List>\\n {\\n new List { \\"facetA\\", \\"facetB\\" },\\n new List { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List { \\"french\\" }),\\n Exclude = new List { \\"test\\" },\\n }\\n);\\n// >LOG\\n " + "csharp": { + "ope": { + "default": "var response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"\\",\\n SourceIndices = new List\\n {\\n new SourceIndex\\n {\\n IndexName = \\"\\",\\n Facets = new List { new Facet { Attribute = \\"test\\" } },\\n Generate = new List>\\n {\\n new List { \\"facetA\\", \\"facetB\\" },\\n new List { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List { \\"french\\" }),\\n Exclude = new List { \\"test\\" },\\n }\\n);" + }, + "init": { + "default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\n \\"ALGOLIA_APPLICATION_ID\\",\\n \\"ALGOLIA_API_KEY\\",\\n \\"ALGOLIA_APPLICATION_REGION\\"\\n )\\n);" + } } }" `); }); - it('parses a single line import', () => { + it('parses a single line init', () => { expect( JSON.stringify( generateSnippetsJSON({ - foo: { - default: ` + csharp: { + ope: { + default: ` // Initialize the client -var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")); +var client = new QuerySuggestionsClient(new QuerySuggestionsConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION")); // Call the API -var response = await client.CreateConfigAsync( - new ConfigurationWithIndex - { - IndexName = "", - SourceIndices = new List - { - new SourceIndex - { - IndexName = "", - Facets = new List { new Facet { Attribute = "test" } }, - Generate = new List> - { - new List { "facetA", "facetB" }, - new List { "facetC" }, - }, - }, - }, - Languages = new Languages(new List { "french" }), - Exclude = new List { "test" }, - } -); +var response = await client.CreateConfigAsync(); // >LOG +// print the response +Console.WriteLine(response); `, + }, }, } as unknown as CodeSamples), null, @@ -93,8 +90,13 @@ var response = await client.CreateConfigAsync( ), ).toMatchInlineSnapshot(` "{ - "foo": { - "default": "\\n // Initialize the client\\nvar client = new QuerySuggestionsClient(new Client(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\"));\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"\\",\\n SourceIndices = new List\\n {\\n new SourceIndex\\n {\\n IndexName = \\"\\",\\n Facets = new List { new Facet { Attribute = \\"test\\" } },\\n Generate = new List>\\n {\\n new List { \\"facetA\\", \\"facetB\\" },\\n new List { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List { \\"french\\" }),\\n Exclude = new List { \\"test\\" },\\n }\\n);\\n// >LOG\\n " + "csharp": { + "ope": { + "default": "var response = await client.CreateConfigAsync();" + }, + "init": { + "default": "var client = new QuerySuggestionsClient(new QuerySuggestionsConfig(\\"ALGOLIA_APPLICATION_ID\\", \\"ALGOLIA_API_KEY\\", \\"ALGOLIA_APPLICATION_REGION\\"));" + } } }" `); @@ -106,37 +108,21 @@ describe('initialize', () => { expect( JSON.stringify( generateSnippetsJSON({ - foo: { - default: ` + csharp: { + ope: { + default: ` // Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ var client = new QuerySuggestionsClient( new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION") ); // Call the API -var response = await client.CreateConfigAsync( - new ConfigurationWithIndex - { - IndexName = "", - SourceIndices = new List - { - new SourceIndex - { - IndexName = "", - Facets = new List { new Facet { Attribute = "test" } }, - Generate = new List> - { - new List { "facetA", "facetB" }, - new List { "facetC" }, - }, - }, - }, - Languages = new Languages(new List { "french" }), - Exclude = new List { "test" }, - } -); +var response = await client.CreateConfigAsync(); // >LOG +// print the response +Console.WriteLine(response); `, + }, }, } as unknown as CodeSamples), null, @@ -144,8 +130,13 @@ var response = await client.CreateConfigAsync( ), ).toMatchInlineSnapshot(` "{ - "foo": { - "default": "\\n // Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ\\nvar client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);\\n\\n// Call the API\\nvar response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"\\",\\n SourceIndices = new List\\n {\\n new SourceIndex\\n {\\n IndexName = \\"\\",\\n Facets = new List { new Facet { Attribute = \\"test\\" } },\\n Generate = new List>\\n {\\n new List { \\"facetA\\", \\"facetB\\" },\\n new List { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List { \\"french\\" }),\\n Exclude = new List { \\"test\\" },\\n }\\n);\\n// >LOG\\n " + "csharp": { + "ope": { + "default": "var response = await client.CreateConfigAsync();" + }, + "init": { + "default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);" + } } }" `); diff --git a/scripts/specs/snippets.ts b/scripts/specs/snippets.ts index 7e31f308af2..53b49469969 100644 --- a/scripts/specs/snippets.ts +++ b/scripts/specs/snippets.ts @@ -116,5 +116,16 @@ export async function transformGeneratedSnippetsToCodeSamples(clientName: string JSON.stringify(jsonSnippets, null, 2), ); + // remove all the `>LOG` comments from the snippets + for (const lang of Object.keys(codeSamples) as Language[]) { + for (const operationId of Object.keys(codeSamples[lang])) { + for (const sampleName of Object.keys(codeSamples[lang][operationId])) { + codeSamples[lang][operationId][sampleName] = codeSamples[lang][operationId][sampleName] + .replace(/(#|\/\/) >LOG/g, '') + .trim(); + } + } + } + return codeSamples; } diff --git a/templates/csharp/snippets/method.mustache b/templates/csharp/snippets/method.mustache index f9d519782fa..f04d126d3e9 100644 --- a/templates/csharp/snippets/method.mustache +++ b/templates/csharp/snippets/method.mustache @@ -32,6 +32,10 @@ public class Snippet{{client}} // Call the API {{#hasResponse}}var response = {{/hasResponse}}{{> tests/method}}; // >LOG + {{#hasResponse}} + // print the response + Console.WriteLine(response); + {{/hasResponse}} // SEPARATOR< } diff --git a/templates/dart/snippets/method.mustache b/templates/dart/snippets/method.mustache index 5172abcd941..3250df58233 100644 --- a/templates/dart/snippets/method.mustache +++ b/templates/dart/snippets/method.mustache @@ -39,6 +39,10 @@ void snippetFor{{method}}{{testIndex}}() async { {{/hasRequestOptions}} ); // >LOG + {{#hasResponse}} + // print the response + print(response); + {{/hasResponse}} // SEPARATOR< } diff --git a/templates/java/snippets/method.mustache b/templates/java/snippets/method.mustache index 0f6c9a65de4..d21ccf86414 100644 --- a/templates/java/snippets/method.mustache +++ b/templates/java/snippets/method.mustache @@ -20,6 +20,10 @@ class Snippet{{client}} { // Call the API {{> tests/method}}; // >LOG + {{#hasResponse}} + // print the response + System.out.println(response); + {{/hasResponse}} // SEPARATOR< } diff --git a/templates/scala/snippets/method.mustache b/templates/scala/snippets/method.mustache index ce2d70ba0aa..ec3a2bae9fd 100644 --- a/templates/scala/snippets/method.mustache +++ b/templates/scala/snippets/method.mustache @@ -33,7 +33,11 @@ class Snippet{{client}} { Duration(100, "sec") ) {{/isAsyncMethod}} - // >LOG + // + {{#hasResponse}} + // print the response + println(response) + {{/hasResponse}} // SEPARATOR< } diff --git a/templates/swift/snippets/method.mustache b/templates/swift/snippets/method.mustache index 8be9b154f1c..b7ec86f81a7 100644 --- a/templates/swift/snippets/method.mustache +++ b/templates/swift/snippets/method.mustache @@ -23,6 +23,10 @@ final class {{client}}Snippet { queryParameters: [{{#parametersWithDataType}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/parametersWithDataType}}]{{/requestOptions.queryParameters}} ){{/hasRequestOptions}}) // >LOG + {{#hasResponse}} + // print the response + print(response) + {{/hasResponse}} // SEPARATOR< } {{/snippets}} From 1f9e6675dd2c8415d69c716ed100af4a552a0d50 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Wed, 15 Oct 2025 00:03:06 +0200 Subject: [PATCH 2/4] same log --- templates/go/snippets/method.mustache | 2 +- templates/javascript/snippets/method.mustache | 2 +- templates/kotlin/snippets/method.mustache | 2 +- templates/php/snippets/method.mustache | 2 +- templates/python/snippets/method.mustache | 2 +- templates/ruby/snippets/method.mustache | 5 +---- 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/templates/go/snippets/method.mustache b/templates/go/snippets/method.mustache index 3788cb4dfef..3a6a2bc8b7c 100644 --- a/templates/go/snippets/method.mustache +++ b/templates/go/snippets/method.mustache @@ -27,7 +27,7 @@ func SnippetFor{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}Of{{#lambda.p // >LOG {{#hasResponse}} - // use the model directly + // print the response print(response) {{/hasResponse}} // SEPARATOR< diff --git a/templates/javascript/snippets/method.mustache b/templates/javascript/snippets/method.mustache index 9ee2b42b2a2..2bd9aa0fde1 100644 --- a/templates/javascript/snippets/method.mustache +++ b/templates/javascript/snippets/method.mustache @@ -23,7 +23,7 @@ export {{#isAsyncMethod}}async{{/isAsyncMethod}} function snippetFor{{#lambda.pa // >LOG {{#hasResponse}} - // use typed response + // print the response console.log(response); {{/hasResponse}} // SEPARATOR< diff --git a/templates/kotlin/snippets/method.mustache b/templates/kotlin/snippets/method.mustache index 8a79adcd939..4a6baa63d91 100644 --- a/templates/kotlin/snippets/method.mustache +++ b/templates/kotlin/snippets/method.mustache @@ -21,7 +21,7 @@ class Snippet{{client}} { // >LOG {{#hasResponse}} - // Use the response + // print the response println(response) {{/hasResponse}} // SEPARATOR< diff --git a/templates/php/snippets/method.mustache b/templates/php/snippets/method.mustache index 1f987c822bf..2aa6ab86482 100644 --- a/templates/php/snippets/method.mustache +++ b/templates/php/snippets/method.mustache @@ -28,7 +28,7 @@ class Snippet{{client}} // >LOG {{#hasResponse}} - // play with the response + // print the response var_dump($response); {{/hasResponse}} // SEPARATOR< diff --git a/templates/python/snippets/method.mustache b/templates/python/snippets/method.mustache index 87c0b469a7b..723e58f5c2a 100644 --- a/templates/python/snippets/method.mustache +++ b/templates/python/snippets/method.mustache @@ -21,7 +21,7 @@ def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{testIndex} # >LOG {{#hasResponse}} - # use the class directly + # print the response print(response) {{/hasResponse}} # SEPARATOR< diff --git a/templates/ruby/snippets/method.mustache b/templates/ruby/snippets/method.mustache index cd5dc6fd129..de08515d8a1 100644 --- a/templates/ruby/snippets/method.mustache +++ b/templates/ruby/snippets/method.mustache @@ -18,11 +18,8 @@ def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{testIndex} # >LOG {{#hasResponse}} - # use the class directly + # print the response puts response - - # print the JSON response - puts response.to_json {{/hasResponse}} # SEPARATOR< end From 4caee6f211725dfaef6bba277e52cce1cfa9b825 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Wed, 15 Oct 2025 00:18:59 +0200 Subject: [PATCH 3/4] fix java --- templates/java/snippets/method.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/java/snippets/method.mustache b/templates/java/snippets/method.mustache index d21ccf86414..c7b282ea4ce 100644 --- a/templates/java/snippets/method.mustache +++ b/templates/java/snippets/method.mustache @@ -18,7 +18,7 @@ class Snippet{{client}} { {{> snippets/init}} // Call the API - {{> tests/method}}; + {{#hasResponse}}{{{returnType}}} response ={{/hasResponse}}{{> tests/method}}; // >LOG {{#hasResponse}} // print the response From 6217fa1f4f983481f6c9530f0a34570334797511 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Wed, 15 Oct 2025 11:25:49 +0200 Subject: [PATCH 4/4] missed scala --- templates/scala/snippets/method.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/scala/snippets/method.mustache b/templates/scala/snippets/method.mustache index ec3a2bae9fd..6d0a166b8a0 100644 --- a/templates/scala/snippets/method.mustache +++ b/templates/scala/snippets/method.mustache @@ -33,7 +33,7 @@ class Snippet{{client}} { Duration(100, "sec") ) {{/isAsyncMethod}} - // + // >LOG {{#hasResponse}} // print the response println(response)