Skip to content

Commit ccb9c37

Browse files
authored
snippets: remove all the >LOG (#5479)
1 parent eafef18 commit ccb9c37

File tree

13 files changed

+87
-68
lines changed

13 files changed

+87
-68
lines changed

scripts/specs/__tests__/snippets.test.ts

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import { generateSnippetsJSON } from '../snippets.ts';
44
import type { CodeSamples } from '../types.ts';
55

66
describe('init', () => {
7-
it('parses a multi line import', () => {
7+
it('parses a multi line init', () => {
88
expect(
99
JSON.stringify(
1010
generateSnippetsJSON({
11-
foo: {
12-
default: `
11+
csharp: {
12+
ope: {
13+
default: `
1314
// Initialize the client
1415
var client = new QuerySuggestionsClient(
15-
new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")
16+
new QuerySuggestionsConfig(
17+
"ALGOLIA_APPLICATION_ID",
18+
"ALGOLIA_API_KEY",
19+
"ALGOLIA_APPLICATION_REGION"
20+
)
1621
);
1722
1823
// Call the API
@@ -38,63 +43,60 @@ var response = await client.CreateConfigAsync(
3843
}
3944
);
4045
// >LOG
46+
// print the response
47+
Console.WriteLine(response);
4148
`,
49+
},
4250
},
4351
} as unknown as CodeSamples),
4452
null,
4553
2,
4654
),
4755
).toMatchInlineSnapshot(`
4856
"{
49-
"foo": {
50-
"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 = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n "
57+
"csharp": {
58+
"ope": {
59+
"default": "var response = await client.CreateConfigAsync(\\n new ConfigurationWithIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);"
60+
},
61+
"init": {
62+
"default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\n \\"ALGOLIA_APPLICATION_ID\\",\\n \\"ALGOLIA_API_KEY\\",\\n \\"ALGOLIA_APPLICATION_REGION\\"\\n )\\n);"
63+
}
5164
}
5265
}"
5366
`);
5467
});
5568

56-
it('parses a single line import', () => {
69+
it('parses a single line init', () => {
5770
expect(
5871
JSON.stringify(
5972
generateSnippetsJSON({
60-
foo: {
61-
default: `
73+
csharp: {
74+
ope: {
75+
default: `
6276
// Initialize the client
63-
var client = new QuerySuggestionsClient(new Client("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION"));
77+
var client = new QuerySuggestionsClient(new QuerySuggestionsConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY", "ALGOLIA_APPLICATION_REGION"));
6478
6579
// Call the API
66-
var response = await client.CreateConfigAsync(
67-
new ConfigurationWithIndex
68-
{
69-
IndexName = "<YOUR_INDEX_NAME>",
70-
SourceIndices = new List<SourceIndex>
71-
{
72-
new SourceIndex
73-
{
74-
IndexName = "<YOUR_INDEX_NAME>",
75-
Facets = new List<Facet> { new Facet { Attribute = "test" } },
76-
Generate = new List<List<string>>
77-
{
78-
new List<string> { "facetA", "facetB" },
79-
new List<string> { "facetC" },
80-
},
81-
},
82-
},
83-
Languages = new Languages(new List<string> { "french" }),
84-
Exclude = new List<string> { "test" },
85-
}
86-
);
80+
var response = await client.CreateConfigAsync();
8781
// >LOG
82+
// print the response
83+
Console.WriteLine(response);
8884
`,
85+
},
8986
},
9087
} as unknown as CodeSamples),
9188
null,
9289
2,
9390
),
9491
).toMatchInlineSnapshot(`
9592
"{
96-
"foo": {
97-
"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 = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n "
93+
"csharp": {
94+
"ope": {
95+
"default": "var response = await client.CreateConfigAsync();"
96+
},
97+
"init": {
98+
"default": "var client = new QuerySuggestionsClient(new QuerySuggestionsConfig(\\"ALGOLIA_APPLICATION_ID\\", \\"ALGOLIA_API_KEY\\", \\"ALGOLIA_APPLICATION_REGION\\"));"
99+
}
98100
}
99101
}"
100102
`);
@@ -106,46 +108,35 @@ describe('initialize', () => {
106108
expect(
107109
JSON.stringify(
108110
generateSnippetsJSON({
109-
foo: {
110-
default: `
111+
csharp: {
112+
ope: {
113+
default: `
111114
// Initialize the client foo bar BAAAAAAAAAAAAAAAAAAAAAZ
112115
var client = new QuerySuggestionsClient(
113116
new QuerySuggestionsConfig("YOUR_APP_ID", "YOUR_API_KEY", "YOUR_APP_ID_REGION")
114117
);
115118
116119
// Call the API
117-
var response = await client.CreateConfigAsync(
118-
new ConfigurationWithIndex
119-
{
120-
IndexName = "<YOUR_INDEX_NAME>",
121-
SourceIndices = new List<SourceIndex>
122-
{
123-
new SourceIndex
124-
{
125-
IndexName = "<YOUR_INDEX_NAME>",
126-
Facets = new List<Facet> { new Facet { Attribute = "test" } },
127-
Generate = new List<List<string>>
128-
{
129-
new List<string> { "facetA", "facetB" },
130-
new List<string> { "facetC" },
131-
},
132-
},
133-
},
134-
Languages = new Languages(new List<string> { "french" }),
135-
Exclude = new List<string> { "test" },
136-
}
137-
);
120+
var response = await client.CreateConfigAsync();
138121
// >LOG
122+
// print the response
123+
Console.WriteLine(response);
139124
`,
125+
},
140126
},
141127
} as unknown as CodeSamples),
142128
null,
143129
2,
144130
),
145131
).toMatchInlineSnapshot(`
146132
"{
147-
"foo": {
148-
"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 = \\"<YOUR_INDEX_NAME>\\",\\n SourceIndices = new List<SourceIndex>\\n {\\n new SourceIndex\\n {\\n IndexName = \\"<YOUR_INDEX_NAME>\\",\\n Facets = new List<Facet> { new Facet { Attribute = \\"test\\" } },\\n Generate = new List<List<string>>\\n {\\n new List<string> { \\"facetA\\", \\"facetB\\" },\\n new List<string> { \\"facetC\\" },\\n },\\n },\\n },\\n Languages = new Languages(new List<string> { \\"french\\" }),\\n Exclude = new List<string> { \\"test\\" },\\n }\\n);\\n// >LOG\\n "
133+
"csharp": {
134+
"ope": {
135+
"default": "var response = await client.CreateConfigAsync();"
136+
},
137+
"init": {
138+
"default": "var client = new QuerySuggestionsClient(\\n new QuerySuggestionsConfig(\\"YOUR_APP_ID\\", \\"YOUR_API_KEY\\", \\"YOUR_APP_ID_REGION\\")\\n);"
139+
}
149140
}
150141
}"
151142
`);

scripts/specs/snippets.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,16 @@ export async function transformGeneratedSnippetsToCodeSamples(clientName: string
116116
JSON.stringify(jsonSnippets, null, 2),
117117
);
118118

119+
// remove all the `>LOG` comments from the snippets
120+
for (const lang of Object.keys(codeSamples) as Language[]) {
121+
for (const operationId of Object.keys(codeSamples[lang])) {
122+
for (const sampleName of Object.keys(codeSamples[lang][operationId])) {
123+
codeSamples[lang][operationId][sampleName] = codeSamples[lang][operationId][sampleName]
124+
.replace(/(#|\/\/) >LOG/g, '')
125+
.trim();
126+
}
127+
}
128+
}
129+
119130
return codeSamples;
120131
}

templates/csharp/snippets/method.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class Snippet{{client}}
3232
// Call the API
3333
{{#hasResponse}}var response = {{/hasResponse}}{{> tests/method}};
3434
// >LOG
35+
{{#hasResponse}}
36+
// print the response
37+
Console.WriteLine(response);
38+
{{/hasResponse}}
3539
// SEPARATOR<
3640
}
3741

templates/dart/snippets/method.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ void snippetFor{{method}}{{testIndex}}() async {
3939
{{/hasRequestOptions}}
4040
);
4141
// >LOG
42+
{{#hasResponse}}
43+
// print the response
44+
print(response);
45+
{{/hasResponse}}
4246
// SEPARATOR<
4347
}
4448

templates/go/snippets/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func SnippetFor{{#lambda.titlecase}}{{method}}{{/lambda.titlecase}}Of{{#lambda.p
2727

2828
// >LOG
2929
{{#hasResponse}}
30-
// use the model directly
30+
// print the response
3131
print(response)
3232
{{/hasResponse}}
3333
// SEPARATOR<

templates/java/snippets/method.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ class Snippet{{client}} {
1818
{{> snippets/init}}
1919

2020
// Call the API
21-
{{> tests/method}};
21+
{{#hasResponse}}{{{returnType}}} response ={{/hasResponse}}{{> tests/method}};
2222
// >LOG
23+
{{#hasResponse}}
24+
// print the response
25+
System.out.println(response);
26+
{{/hasResponse}}
2327
// SEPARATOR<
2428
}
2529

templates/javascript/snippets/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export {{#isAsyncMethod}}async{{/isAsyncMethod}} function snippetFor{{#lambda.pa
2323

2424
// >LOG
2525
{{#hasResponse}}
26-
// use typed response
26+
// print the response
2727
console.log(response);
2828
{{/hasResponse}}
2929
// SEPARATOR<

templates/kotlin/snippets/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Snippet{{client}} {
2121

2222
// >LOG
2323
{{#hasResponse}}
24-
// Use the response
24+
// print the response
2525
println(response)
2626
{{/hasResponse}}
2727
// SEPARATOR<

templates/php/snippets/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Snippet{{client}}
2828

2929
// >LOG
3030
{{#hasResponse}}
31-
// play with the response
31+
// print the response
3232
var_dump($response);
3333
{{/hasResponse}}
3434
// SEPARATOR<

templates/python/snippets/method.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def snippet_for_{{#lambda.snakecase}}{{method}}{{/lambda.snakecase}}{{testIndex}
2121

2222
# >LOG
2323
{{#hasResponse}}
24-
# use the class directly
24+
# print the response
2525
print(response)
2626
{{/hasResponse}}
2727
# SEPARATOR<

0 commit comments

Comments
 (0)