Skip to content

Commit 1e27a28

Browse files
authored
chore(deps): upgrade openapi-generator to v6 APIC-502 (#685)
1 parent cdf2e70 commit 1e27a28

26 files changed

+82
-70
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ module.exports = {
101101
'no-continue': 0,
102102
'@typescript-eslint/prefer-enum-initializers': 0,
103103

104-
'@typescript-eslint/no-unused-vars': 2,
105104
'unused-imports/no-unused-imports-ts': 2,
105+
'@typescript-eslint/no-unused-vars': 2,
106+
'@typescript-eslint/consistent-indexed-object-style': 2,
106107
'@typescript-eslint/member-ordering': [
107108
'error',
108109
{

config/openapitools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"generator-cli": {
3-
"version": "5.4.0",
3+
"version": "6.0.0",
44
"generators": {
55
"javascript-search": {
66
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-search",

generators/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repositories {
1212
}
1313

1414
dependencies {
15-
compileOnly 'org.openapitools:openapi-generator:5.4.0'
15+
compileOnly 'org.openapitools:openapi-generator:6.0.0'
1616
compileOnly 'org.yaml:snakeyaml:1.30'
1717
}
1818

generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.*;
88
import org.openapitools.codegen.*;
99
import org.openapitools.codegen.languages.JavaClientCodegen;
10+
import org.openapitools.codegen.model.ModelsMap;
1011
import org.openapitools.codegen.utils.ModelUtils;
1112

1213
@SuppressWarnings("unchecked")
@@ -21,8 +22,6 @@ public String getName() {
2122
public void processOpts() {
2223
// generator specific options
2324
String client = (String) additionalProperties.get("client");
24-
setDateLibrary("java8");
25-
setLibrary("okhttp-gson");
2625
setSourceFolder("algoliasearch-core/src/main/java");
2726
setGroupId("com.algolia");
2827
setModelPackage("com.algolia.model." + Utils.camelize(client));
@@ -45,23 +44,14 @@ public void processOpts() {
4544
file.getTemplateFile().equals("ApiClient.mustache") ||
4645
file.getTemplateFile().equals("ApiCallback.mustache") ||
4746
file.getTemplateFile().equals("ApiResponse.mustache") ||
47+
file.getTemplateFile().equals("AbstractOpenApiSchema.mustache") ||
48+
file.getTemplateFile().equals("maven.yml.mustache") ||
4849
file.getTemplateFile().equals("JSON.mustache") ||
4950
file.getTemplateFile().equals("ProgressRequestBody.mustache") ||
5051
file.getTemplateFile().equals("ProgressResponseBody.mustache") ||
5152
file.getTemplateFile().equals("Pair.mustache")
5253
);
53-
}
54-
55-
@Override
56-
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
57-
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
58-
}
59-
60-
@Override
61-
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
62-
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);
6354

64-
String client = (String) additionalProperties.get("client");
6555
additionalProperties.put("isSearchClient", client.equals("search"));
6656

6757
try {
@@ -72,16 +62,24 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
7262
e.printStackTrace();
7363
System.exit(1);
7464
}
65+
}
66+
67+
@Override
68+
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
69+
super.addParentContainer(codegenModel, codegenModel.name, schema);
70+
}
7571

76-
return results;
72+
@Override
73+
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
74+
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
7775
}
7876

7977
@Override
80-
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
81-
Map<String, Object> models = super.postProcessAllModels(objs);
78+
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
79+
Map<String, ModelsMap> models = super.postProcessAllModels(objs);
8280

83-
for (Object modelContainer : models.values()) {
84-
CodegenModel model = ((Map<String, List<Map<String, CodegenModel>>>) modelContainer).get("models").get(0).get("model");
81+
for (ModelsMap modelContainer : models.values()) {
82+
CodegenModel model = modelContainer.getModels().get(0).getModel();
8583
if (!model.oneOf.isEmpty()) {
8684
List<HashMap<String, String>> oneOfList = new ArrayList();
8785

generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import com.algolia.codegen.exceptions.*;
44
import io.swagger.v3.oas.models.Operation;
5-
import io.swagger.v3.oas.models.media.Schema;
6-
import io.swagger.v3.oas.models.parameters.Parameter;
75
import io.swagger.v3.oas.models.servers.Server;
86
import java.util.List;
9-
import java.util.Map;
107
import org.openapitools.codegen.CodegenOperation;
118
import org.openapitools.codegen.SupportingFile;
129
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
10+
import org.openapitools.codegen.model.ModelMap;
11+
import org.openapitools.codegen.model.OperationsMap;
1312

1413
public class AlgoliaJavaScriptGenerator extends TypeScriptNodeClientCodegen {
1514

@@ -30,6 +29,9 @@ public void processOpts() {
3029
setSupportsES6(true);
3130
setModelPropertyNaming("original");
3231
setApiPackage("src");
32+
33+
languageSpecificPrimitives.add("Record");
34+
instantiationTypes.put("map", "Record");
3335
// clear all supported files to avoid unwanted ones
3436
supportingFiles.clear();
3537

@@ -64,8 +66,8 @@ private void setDefaultGeneratorOptions() {
6466

6567
/** Provides an opportunity to inspect and modify operation data before the code is generated. */
6668
@Override
67-
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
68-
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);
69+
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
70+
OperationsMap results = super.postProcessOperationsWithModels(objs, allModels);
6971

7072
setDefaultGeneratorOptions();
7173
try {
@@ -77,7 +79,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
7779
System.exit(1);
7880
}
7981

80-
List<CodegenOperation> operations = ((Map<String, List<CodegenOperation>>) results.get("operations")).get("operation");
82+
List<CodegenOperation> operations = results.getOperations().getOperation();
8183

8284
// We read operations and detect if we should wrap parameters under an object.
8385
// We only wrap if there is a mix between body parameters and other parameters.
@@ -139,21 +141,4 @@ public String toApiFilename(String name) {
139141
public String apiFilename(String templateName, String tag) {
140142
return super.apiFilename(templateName, toApiFilename(CLIENT));
141143
}
142-
143-
@Override
144-
protected String getParameterDataType(Parameter parameter, Schema p) {
145-
String type = super.getParameterDataType(parameter, p);
146-
// openapi generator is wrong, 'object' is not a fit all object, we need 'any'
147-
// we use replace because there might be more to this type, like '| undefined'
148-
return type.replace("{ [key: string]: object; }", "Record<string, any>");
149-
}
150-
151-
@Override
152-
public String toInstantiationType(Schema schema) {
153-
String type = super.toInstantiationType(schema);
154-
155-
// Same as the `getParameterDataType` but for the models, the generator
156-
// consider `object` as a fit all which is wrong in TypeScript
157-
return type.replace("null<String, object>", "Record<string, any>");
158-
}
159144
}

generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.swagger.v3.oas.models.Operation;
55
import io.swagger.v3.oas.models.servers.Server;
66
import java.util.List;
7-
import java.util.Map;
87
import org.openapitools.codegen.CodegenOperation;
98
import org.openapitools.codegen.SupportingFile;
109
import org.openapitools.codegen.languages.PhpClientCodegen;
@@ -31,6 +30,15 @@ public void processOpts() {
3130
supportingFiles.removeIf(file -> file.getTemplateFile().equals("Configuration.mustache"));
3231

3332
supportingFiles.add(new SupportingFile("Configuration.mustache", "lib/Configuration", "Configuration.php"));
33+
34+
setDefaultGeneratorOptions(client);
35+
try {
36+
Utils.generateServer(client, additionalProperties);
37+
additionalProperties.put("packageVersion", Utils.getClientConfigField("php", "packageVersion"));
38+
} catch (GeneratorException e) {
39+
e.printStackTrace();
40+
System.exit(1);
41+
}
3442
}
3543

3644
@Override
@@ -47,25 +55,6 @@ public void setDefaultGeneratorOptions(String client) {
4755
additionalProperties.put("configClassname", Utils.createClientName(client, "php") + "Config");
4856
}
4957

50-
/** Provides an opportunity to inspect and modify operation data before the code is generated. */
51-
@Override
52-
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
53-
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);
54-
55-
String client = (String) additionalProperties.get("client");
56-
57-
setDefaultGeneratorOptions(client);
58-
try {
59-
Utils.generateServer(client, additionalProperties);
60-
additionalProperties.put("packageVersion", Utils.getClientConfigField("php", "packageVersion"));
61-
} catch (GeneratorException e) {
62-
e.printStackTrace();
63-
System.exit(1);
64-
}
65-
66-
return results;
67-
}
68-
6958
public String getComposerPackageName() {
7059
return "algolia/algoliasearch-client-php";
7160
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.Map.Entry;
1212
import java.util.TreeMap;
1313
import org.openapitools.codegen.*;
14+
import org.openapitools.codegen.model.ModelMap;
15+
import org.openapitools.codegen.model.ModelsMap;
1416

1517
@SuppressWarnings("unchecked")
1618
public class AlgoliaCTSGenerator extends DefaultCodegen {
@@ -56,12 +58,12 @@ public void processOpts() {
5658
}
5759

5860
@Override
59-
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
60-
Map<String, Object> mod = super.postProcessAllModels(objs);
61-
for (Entry<String, Object> entry : mod.entrySet()) {
62-
List<Object> innerModel = ((Map<String, List<Object>>) entry.getValue()).get("models");
61+
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
62+
Map<String, ModelsMap> mod = super.postProcessAllModels(objs);
63+
for (Entry<String, ModelsMap> entry : mod.entrySet()) {
64+
List<ModelMap> innerModel = entry.getValue().getModels();
6365
if (!innerModel.isEmpty()) {
64-
models.put(entry.getKey(), (CodegenModel) ((Map<String, Object>) innerModel.get(0)).get("model"));
66+
models.put(entry.getKey(), innerModel.get(0).getModel());
6567
}
6668
}
6769
return mod;

generators/src/main/java/com/algolia/codegen/cts/tests/ParametersWithDataType.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ private void handlePrimitive(Object param, Map<String, Object> testOutput, IJson
372372
transferPrimitiveData(spec, testOutput);
373373
} else {
374374
inferDataType(param, null, testOutput);
375-
if (spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType) {
375+
if (isAnyType(spec)) {
376376
testOutput.put("isAnyType", true);
377377
}
378378
}
@@ -395,6 +395,19 @@ private String getTypeName(IJsonSchemaValidationProperties param) {
395395
return null;
396396
}
397397

398+
private boolean isAnyType(IJsonSchemaValidationProperties param) {
399+
if (param instanceof CodegenParameter) {
400+
return ((CodegenParameter) param).isAnyType;
401+
}
402+
if (param instanceof CodegenProperty) {
403+
return ((CodegenProperty) param).isAnyType;
404+
}
405+
if (param instanceof CodegenResponse) {
406+
return ((CodegenResponse) param).isAnyType;
407+
}
408+
return false;
409+
}
410+
398411
private boolean isEnum(IJsonSchemaValidationProperties param) {
399412
if (param instanceof CodegenParameter) {
400413
return ((CodegenParameter) param).isEnum;

specs/analytics/common/schemas/getTopHits.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ topHitsResponse:
99
description: A list of top hits with their count.
1010
items:
1111
type: object
12+
title: topHit
1213
additionalProperties: false
1314
required:
1415
- hit
@@ -30,6 +31,7 @@ topHitsResponseWithAnalytics:
3031
description: A list of top hits with their count and analytics.
3132
items:
3233
type: object
34+
title: topHitWithAnalytics
3335
additionalProperties: false
3436
required:
3537
- hit

specs/analytics/common/schemas/getTopSearches.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ topSearchesResponse:
99
description: A list of top searches with their count.
1010
items:
1111
type: object
12+
title: topSearch
1213
additionalProperties: false
1314
required:
1415
- search
@@ -33,6 +34,7 @@ topSearchesResponseWithAnalytics:
3334
description: A list of top searches with their count and analytics.
3435
items:
3536
type: object
37+
title: topSearchWithAnalytics
3638
additionalProperties: false
3739
required:
3840
- search

specs/analytics/paths/click/getAverageClickPosition.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ get:
3232
description: A list of average click position with their date.
3333
items:
3434
type: object
35+
title: averageClickEvent
3536
additionalProperties: false
3637
required:
3738
- average

specs/analytics/paths/click/getClickPositions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ get:
3232
maxItems: 2
3333
items:
3434
type: object
35+
title: clickPosition
3536
additionalProperties: false
3637
required:
3738
- position

specs/analytics/paths/click/getClickThroughRate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ get:
3535
description: A list of click-through rate events with their date.
3636
items:
3737
type: object
38+
title: clickThroughRateEvent
3839
additionalProperties: false
3940
required:
4041
- rate

specs/analytics/paths/click/getConversionRate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ get:
3535
description: A list of conversion events with their date.
3636
items:
3737
type: object
38+
title: conversionRateEvent
3839
additionalProperties: false
3940
required:
4041
- rate

specs/analytics/paths/search/getNoClickRate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ get:
3535
description: A list of searches without clicks with their date, rate and counts.
3636
items:
3737
type: object
38+
title: noClickRateEvent
3839
additionalProperties: false
3940
required:
4041
- rate

specs/analytics/paths/search/getNoResultsRate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ get:
3535
description: A list of searches without results with their date, rate and counts.
3636
items:
3737
type: object
38+
title: noResultsRateEvent
3839
additionalProperties: false
3940
required:
4041
- date

specs/analytics/paths/search/getSearchesCount.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ get:
2929
description: A list of search events with their date and count.
3030
items:
3131
type: object
32+
title: searchEvent
3233
additionalProperties: false
3334
required:
3435
- date

specs/analytics/paths/search/getSearchesNoClicks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ get:
2828
description: A list of searches with no clicks and their count.
2929
items:
3030
type: object
31+
title: searchNoClickEvent
3132
additionalProperties: false
3233
required:
3334
- search

specs/analytics/paths/search/getSearchesNoResults.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ get:
2828
description: A list of searches with no results and their count.
2929
items:
3030
type: object
31+
title: searchNoResultEvent
3132
additionalProperties: false
3233
required:
3334
- search

specs/analytics/paths/search/getTopCountries.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ get:
2828
description: A list of countries with their count.
2929
items:
3030
type: object
31+
title: topCountry
3132
additionalProperties: false
3233
required:
3334
- country

specs/analytics/paths/search/getUsersCount.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ get:
2929
description: A list of users count with their date.
3030
items:
3131
type: object
32+
title: userWithDate
3233
additionalProperties: false
3334
required:
3435
- date

0 commit comments

Comments
 (0)