Skip to content

Commit 031d951

Browse files
authored
Merge branch 'main' into docs/analytics/update_max_pagination_query_limit
2 parents 0770e79 + 3a3b794 commit 031d951

File tree

248 files changed

+1385
-62330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+1385
-62330
lines changed

.eslintrc.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ module.exports = {
209209

210210
plugins: ['@vitest/eslint-plugin'],
211211
},
212+
{
213+
files: ['guides/**/*.ts'],
214+
215+
rules: {
216+
'no-console': 0,
217+
218+
// TODO: remove this after https://algolia.atlassian.net/browse/DI-2984
219+
'@typescript-eslint/no-unused-vars': 0,
220+
'@typescript-eslint/explicit-function-return-type': 0,
221+
},
222+
},
212223
{
213224
files: ['*.json'],
214225
parserOptions: {

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ runs:
4545

4646
- name: Install JavaScript dependencies
4747
shell: bash
48-
run: YARN_ENABLE_HARDENED_MODE=0 yarn install
48+
run: YARN_ENABLE_HARDENED_MODE=0 YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
4949

5050
- name: Build scripts
5151
shell: bash

.github/workflows/check.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
path: ${{ fromJSON(needs.setup.outputs.SPECS_MATRIX).bundledPath }}
175175

176176
client_gen_javascript:
177-
timeout-minutes: 10
177+
timeout-minutes: 15
178178
runs-on: ubuntu-22.04
179179
needs:
180180
- setup
@@ -275,11 +275,20 @@ jobs:
275275
- name: Run benchmarks
276276
run: yarn cli cts run javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }} --benchmark --no-client --no-requests --no-e2e
277277

278-
- name: Generate code snippets for documentation
278+
- name: Generate code snippets
279279
run: yarn cli snippets javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }}
280+
281+
- name: Build the snippets to check validity
282+
run: yarn cli build snippets javascript
283+
284+
- name: Generate code guides
285+
run: yarn cli guides javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun }}
286+
287+
- name: Build the guides to check validity
288+
run: yarn cli build guides javascript
280289

281290
- name: Zip artifact before storing
282-
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/**"
291+
run: zip -r -y clients-javascript.zip clients/algoliasearch-client-javascript ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).testsToStore }} ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).guidesToStore }} -x "**/node_modules**" "**/.yarn/cache/**" "**/.yarn/install-state.gz" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/.nx/**"
283292

284293
- name: Store javascript clients
285294
uses: actions/upload-artifact@v4
@@ -381,15 +390,21 @@ jobs:
381390
if: ${{ matrix.client.isMainVersion }}
382391
run: yarn cli cts run ${{ matrix.client.language }} ${{ matrix.client.toRun }} --benchmark --no-client --no-requests --no-e2e
383392

384-
- name: Generate code snippets for documentation
393+
- name: Generate code snippets
385394
run: yarn cli snippets ${{ matrix.client.language }} ${{ matrix.client.toRun }}
386395

387396
- name: Build the snippets to check validity
388397
run: yarn cli build snippets ${{ matrix.client.language }}
389398

399+
- name: Generate code guides
400+
run: yarn cli guides ${{ matrix.client.language }} ${{ matrix.client.toRun }}
401+
402+
- name: Build the guides to check validity
403+
run: yarn cli build guides ${{ matrix.client.language }}
404+
390405
- name: Zip artifact before storing
391406
if: ${{ matrix.client.isMainVersion }}
392-
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/**" "**/.build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" "**/target/**" "**/.dart_tool/**"
407+
run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} ${{ matrix.client.guidesToStore }} -x "**/node_modules**" "**/__pycache__/**" "**/.yarn/cache/**" "**/build/**" "**/.build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**" "**/target/**" "**/.dart_tool/**"
393408

394409
- name: Store ${{ matrix.client.language }} clients
395410
if: ${{ matrix.client.isMainVersion }}

.github/workflows/pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
- name: Pull Request title rules
1717
uses: Slashgear/[email protected]
1818
with:
19-
regexp: '^(docs|chore|snippets)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|playground|csharp|dart|go|java|javascript|kotlin|php|python|ruby|scala|swift|cts|specs|scripts|ci|templates|deps)\)): .+'
19+
regexp: '^(docs|chore|snippets|guides)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|playground|csharp|dart|go|java|javascript|kotlin|php|python|ruby|scala|swift|cts|specs|scripts|ci|templates|deps)\)): .+'

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ pubspec.lock
5555
swiftformat
5656

5757
foo
58+
59+
/snippets

config/generation.config.mjs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ export const patterns = [
44
'specs/bundled/*.json',
55

66
'clients/**',
7-
'snippets/**',
8-
'snippets/guides/**',
7+
'guides/**',
98
'!clients/README.md',
109
'!clients/**/.openapi-generator-ignore',
1110
'clients/**/.github/**',
@@ -23,13 +22,8 @@ export const patterns = [
2322
'!clients/algoliasearch-client-csharp/algoliasearch/Models/Common/**',
2423

2524
'tests/output/csharp/global.json',
26-
'!snippets/csharp/**',
27-
'snippets/csharp/src/**.cs',
28-
'!snippets/csharp/src/Program.cs',
2925

3026
// Dart
31-
'!snippets/dart/**',
32-
'snippets/dart/lib/**',
3327
'!clients/algoliasearch-client-dart/**',
3428
'clients/algoliasearch-client-dart/packages/*/pubspec.yaml',
3529
'clients/algoliasearch-client-dart/packages/*/lib/*.dart',
@@ -53,7 +47,6 @@ export const patterns = [
5347
'!clients/algoliasearch-client-go/algolia/utils/*',
5448

5549
'!tests/output/go/go.*',
56-
'!snippets/go/go.*',
5750

5851
// Java
5952
'!clients/algoliasearch-client-java/**',
@@ -63,10 +56,8 @@ export const patterns = [
6356
'clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/BuildConfig.java',
6457

6558
'tests/output/java/build.gradle',
66-
'!snippets/java/settings.gradle',
6759

6860
// JavaScript
69-
'!snippets/javascript/*.json',
7061
'!clients/algoliasearch-client-javascript/*',
7162
'!clients/algoliasearch-client-javascript/.yarn/**',
7263
'!clients/algoliasearch-client-javascript/scripts/**',
@@ -84,8 +75,6 @@ export const patterns = [
8475
'tests/output/javascript/package.json',
8576

8677
// Kotlin
87-
'!snippets/kotlin/**',
88-
'snippets/kotlin/src/**',
8978
'!clients/algoliasearch-client-kotlin/**',
9079
'clients/algoliasearch-client-kotlin/gradle.properties',
9180
'clients/algoliasearch-client-kotlin/client/README.md',
@@ -106,7 +95,6 @@ export const patterns = [
10695
'clients/algoliasearch-client-php/composer.json',
10796

10897
// Python
109-
'!snippets/python/pyproject.toml',
11098
'clients/algoliasearch-client-python/**',
11199
'!clients/algoliasearch-client-python/algoliasearch/http/**',
112100
'!clients/algoliasearch-client-python/algoliasearch/py.typed',
@@ -121,7 +109,6 @@ export const patterns = [
121109
'!tests/output/python/**/__init__.py',
122110

123111
// Ruby
124-
'!snippets/ruby/Gemfile',
125112
'!clients/algoliasearch-client-ruby/**',
126113
'clients/algoliasearch-client-ruby/Gemfile.lock',
127114
'clients/algoliasearch-client-ruby/lib/algolia/**',
@@ -136,8 +123,6 @@ export const patterns = [
136123
'tests/output/ruby/Gemfile.lock',
137124

138125
// Scala
139-
'!snippets/scala/**',
140-
'snippets/scala/src/**',
141126
'!clients/algoliasearch-client-scala/**',
142127
'clients/algoliasearch-client-scala/version.sbt',
143128
'clients/algoliasearch-client-scala/src/main/scala/algoliasearch/**',
@@ -148,9 +133,6 @@ export const patterns = [
148133
'!clients/algoliasearch-client-scala/src/main/scala/algoliasearch/extension/**',
149134

150135
// Swift
151-
'!snippets/swift/**',
152-
'snippets/swift/Package.swift',
153-
'snippets/swift/Sources/**',
154136
'clients/algoliasearch-client-swift/**',
155137
'!clients/algoliasearch-client-swift/*',
156138
'clients/algoliasearch-client-swift/AlgoliaSearchClient.podspec',

generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.algolia.codegen.cts;
22

3+
import com.algolia.codegen.cts.guides.GuidesGenerator;
34
import com.algolia.codegen.cts.lambda.*;
45
import com.algolia.codegen.cts.manager.CTSManager;
56
import com.algolia.codegen.cts.manager.CTSManagerFactory;
@@ -21,8 +22,7 @@ public class AlgoliaCTSGenerator extends DefaultCodegen {
2122

2223
// cache the models
2324
private final Map<String, CodegenModel> models = new HashMap<>();
24-
private String language;
25-
private String client;
25+
private String language, client, mode;
2626
private CTSManager ctsManager;
2727
private List<TestsGenerator> testsGenerators = new ArrayList<>();
2828

@@ -42,7 +42,7 @@ public void processOpts() {
4242

4343
language = (String) additionalProperties.get("language");
4444
client = (String) additionalProperties.get("client");
45-
String mode = (String) additionalProperties.get("mode");
45+
mode = (String) additionalProperties.get("mode");
4646
ctsManager = CTSManagerFactory.getManager(language, client);
4747

4848
if (ctsManager == null) {
@@ -63,9 +63,13 @@ public void processOpts() {
6363
testsGenerators.add(new TestsClient(ctsManager, true));
6464
testsGenerators.add(new TestsClient(ctsManager, false));
6565
} else if (mode.equals("snippets")) {
66-
ctsManager.addSnippetsSupportingFiles(supportingFiles);
66+
ctsManager.addSnippetsSupportingFiles(supportingFiles, mode);
6767

6868
testsGenerators.add(new SnippetsGenerator(ctsManager));
69+
} else if (mode.equals("guides")) {
70+
ctsManager.addSnippetsSupportingFiles(supportingFiles, mode);
71+
72+
testsGenerators.add(new GuidesGenerator(ctsManager));
6973
} else {
7074
throw new RuntimeException("Unknown mode: " + mode);
7175
}
@@ -142,6 +146,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
142146
}
143147

144148
// We can put whatever we want in the bundle, and it will be accessible in the template
149+
bundle.put("mode", mode);
145150
bundle.put("client", Helpers.createClientName(importClientName, language) + "Client");
146151
bundle.put("clientPrefix", Helpers.createClientName(importClientName, language));
147152
bundle.put("hasRegionalHost", hasRegionalHost);
@@ -151,6 +156,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
151156
bundle.put("isSyncClient", false);
152157
// special lambda for dynamic templates
153158
bundle.put("dynamicTemplate", new DynamicTemplateLambda(this));
159+
bundle.put("dynamicSnippet", new DynamicSnippetLambda(this, models, operations, language, client));
154160
bundle.put("lambda", lambda);
155161

156162
String languageVersion = ctsManager.getLanguageVersion((String) additionalProperties.getOrDefault("languageVersion", ""));
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.algolia.codegen.cts.guides;
2+
3+
import com.algolia.codegen.cts.manager.CTSManager;
4+
import com.algolia.codegen.cts.tests.TestsGenerator;
5+
import com.algolia.codegen.utils.*;
6+
import java.io.File;
7+
import java.util.*;
8+
import org.openapitools.codegen.CodegenModel;
9+
import org.openapitools.codegen.CodegenOperation;
10+
import org.openapitools.codegen.SupportingFile;
11+
12+
public class GuidesGenerator extends TestsGenerator {
13+
14+
public GuidesGenerator(CTSManager ctsManager) {
15+
super(ctsManager);
16+
}
17+
18+
@Override
19+
public boolean available() {
20+
File templates = new File("templates/" + language + "/guides/" + client);
21+
return templates.exists();
22+
}
23+
24+
@Override
25+
public void addSupportingFiles(List<SupportingFile> supportingFiles, String outputFolder, String extension) {
26+
if (!available()) {
27+
return;
28+
}
29+
30+
// same extension as the snippets
31+
extension = Helpers.getClientConfigField(language, "snippets", "extension");
32+
outputFolder = Helpers.getClientConfigField(language, "snippets", "outputFolder");
33+
34+
if (!outputFolder.equals("")) {
35+
outputFolder = "/" + outputFolder + "/";
36+
} else {
37+
outputFolder = "/";
38+
}
39+
40+
File templates = new File("templates/" + language + "/guides/" + client);
41+
for (File f : templates.listFiles()) {
42+
supportingFiles.add(
43+
new SupportingFile(
44+
"guides/" + client + "/" + f.getName(),
45+
"guides/" + language + outputFolder + f.getName().replace(".mustache", "") + extension
46+
)
47+
);
48+
}
49+
}
50+
51+
@Override
52+
public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation> operations, Map<String, Object> bundle) throws Exception {
53+
// nothing to do here, the mustache uses dynamicSnippets lambda
54+
}
55+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.algolia.codegen.cts.lambda;
2+
3+
import com.algolia.codegen.cts.tests.ParametersWithDataType;
4+
import com.algolia.codegen.cts.tests.Snippet;
5+
import com.algolia.codegen.exceptions.CTSException;
6+
import com.algolia.codegen.utils.Helpers;
7+
import com.fasterxml.jackson.core.type.TypeReference;
8+
import com.fasterxml.jackson.databind.*;
9+
import com.samskivert.mustache.Mustache;
10+
import com.samskivert.mustache.Template;
11+
import io.swagger.v3.core.util.Json;
12+
import java.io.IOException;
13+
import java.io.Writer;
14+
import java.util.Map;
15+
import org.openapitools.codegen.CodegenModel;
16+
import org.openapitools.codegen.CodegenOperation;
17+
import org.openapitools.codegen.DefaultCodegen;
18+
import org.openapitools.codegen.TemplateManager;
19+
import org.openapitools.codegen.api.TemplatePathLocator;
20+
import org.openapitools.codegen.api.TemplatingEngineAdapter;
21+
import org.openapitools.codegen.api.TemplatingExecutor;
22+
import org.openapitools.codegen.templating.CommonTemplateContentLocator;
23+
import org.openapitools.codegen.templating.GeneratorTemplateContentLocator;
24+
import org.openapitools.codegen.templating.TemplateManagerOptions;
25+
26+
public class DynamicSnippetLambda implements Mustache.Lambda {
27+
28+
private final TemplatingExecutor executor;
29+
private final TemplatingEngineAdapter adaptor;
30+
31+
private final ParametersWithDataType paramsType;
32+
private final Map<String, CodegenOperation> operations;
33+
34+
private final Map<String, Snippet> snippets;
35+
36+
public DynamicSnippetLambda(
37+
DefaultCodegen generator,
38+
Map<String, CodegenModel> models,
39+
Map<String, CodegenOperation> operations,
40+
String language,
41+
String client
42+
) {
43+
this.operations = operations;
44+
this.paramsType = new ParametersWithDataType(models, language, client, true);
45+
46+
JsonNode snippetsFile = Helpers.readJsonFile("tests/CTS/guides/search.json");
47+
this.snippets = Json.mapper().convertValue(snippetsFile, new TypeReference<Map<String, Snippet>>() {});
48+
49+
// we can't access the default template manager, so we have to create our own
50+
TemplateManager templateManager = new TemplateManager(
51+
new TemplateManagerOptions(generator.isEnableMinimalUpdate(), generator.isSkipOverwrite()),
52+
generator.getTemplatingEngine(),
53+
new TemplatePathLocator[] { new GeneratorTemplateContentLocator(generator), new CommonTemplateContentLocator() }
54+
);
55+
56+
this.executor = templateManager;
57+
this.adaptor = generator.getTemplatingEngine();
58+
}
59+
60+
@Override
61+
public void execute(Template.Fragment fragment, Writer writer) throws IOException, CTSException {
62+
String snippetName = fragment.execute();
63+
Snippet snippet = snippets.get(snippetName);
64+
if (snippet == null) {
65+
throw new CTSException("Cannot find snippet: " + snippetName);
66+
}
67+
68+
String operationId = snippet.method;
69+
70+
CodegenOperation operation = operations.get(operationId);
71+
if (operation == null) {
72+
throw new CTSException("Cannot find operation for method: " + operationId);
73+
}
74+
75+
// set the method attributes
76+
Map<String, Object> context = (Map<String, Object>) fragment.context();
77+
snippet.addMethodCall(context, paramsType, operation);
78+
79+
writer.write(adaptor.compileTemplate(executor, context, "tests/method.mustache"));
80+
}
81+
}

generators/src/main/java/com/algolia/codegen/cts/manager/CSharpCTSManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ public void addTestsSupportingFiles(List<SupportingFile> supportingFiles) {
2626
supportingFiles.add(new SupportingFile("globaljson.mustache", "tests/output/csharp", "global.json"));
2727
}
2828

29+
@Override
30+
public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, String output) {
31+
supportingFiles.add(new SupportingFile("snippets/src.csproj.mustache", output + "/csharp/src/src.csproj"));
32+
supportingFiles.add(new SupportingFile("snippets/.gitignore.mustache", output + "/csharp/.gitignore"));
33+
supportingFiles.add(new SupportingFile("snippets/Algolia.mustache", output + "/csharp/Algolia.sln"));
34+
supportingFiles.add(new SupportingFile("snippets/dotnet-tools.mustache", output + "/csharp/.config/dotnet-tools.json"));
35+
36+
if (output.equals("snippets")) {
37+
supportingFiles.add(new SupportingFile("snippets/Program.mustache", output + "/csharp/src/Program.cs"));
38+
}
39+
}
40+
2941
@Override
3042
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
3143
bundle.put("packageVersion", getVersion());

0 commit comments

Comments
 (0)