Skip to content

chore(deps): upgrade openapi-generator to v6 APIC-502 #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ module.exports = {
'no-continue': 0,
'@typescript-eslint/prefer-enum-initializers': 0,

'@typescript-eslint/no-unused-vars': 2,
'unused-imports/no-unused-imports-ts': 2,
'@typescript-eslint/no-unused-vars': 2,
'@typescript-eslint/consistent-indexed-object-style': 2,
'@typescript-eslint/member-ordering': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion config/openapitools.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"generator-cli": {
"version": "5.4.0",
"version": "6.0.0",
"generators": {
"javascript-search": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-search",
Expand Down
2 changes: 1 addition & 1 deletion generators/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

dependencies {
compileOnly 'org.openapitools:openapi-generator:5.4.0'
compileOnly 'org.openapitools:openapi-generator:6.0.0'
compileOnly 'org.yaml:snakeyaml:1.30'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.*;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.JavaClientCodegen;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.ModelUtils;

@SuppressWarnings("unchecked")
Expand All @@ -21,8 +22,6 @@ public String getName() {
public void processOpts() {
// generator specific options
String client = (String) additionalProperties.get("client");
setDateLibrary("java8");
setLibrary("okhttp-gson");
setSourceFolder("algoliasearch-core/src/main/java");
setGroupId("com.algolia");
setModelPackage("com.algolia.model." + Utils.camelize(client));
Expand All @@ -45,23 +44,14 @@ public void processOpts() {
file.getTemplateFile().equals("ApiClient.mustache") ||
file.getTemplateFile().equals("ApiCallback.mustache") ||
file.getTemplateFile().equals("ApiResponse.mustache") ||
file.getTemplateFile().equals("AbstractOpenApiSchema.mustache") ||
file.getTemplateFile().equals("maven.yml.mustache") ||
file.getTemplateFile().equals("JSON.mustache") ||
file.getTemplateFile().equals("ProgressRequestBody.mustache") ||
file.getTemplateFile().equals("ProgressResponseBody.mustache") ||
file.getTemplateFile().equals("Pair.mustache")
);
}

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
}

@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);

String client = (String) additionalProperties.get("client");
additionalProperties.put("isSearchClient", client.equals("search"));

try {
Expand All @@ -72,16 +62,24 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
e.printStackTrace();
System.exit(1);
}
}

@Override
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Schema schema) {
super.addParentContainer(codegenModel, codegenModel.name, schema);
}

return results;
@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
}

@Override
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
Map<String, Object> models = super.postProcessAllModels(objs);
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
Map<String, ModelsMap> models = super.postProcessAllModels(objs);

for (Object modelContainer : models.values()) {
CodegenModel model = ((Map<String, List<Map<String, CodegenModel>>>) modelContainer).get("models").get(0).get("model");
for (ModelsMap modelContainer : models.values()) {
CodegenModel model = modelContainer.getModels().get(0).getModel();
if (!model.oneOf.isEmpty()) {
List<HashMap<String, String>> oneOfList = new ArrayList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import com.algolia.codegen.exceptions.*;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.servers.Server;
import java.util.List;
import java.util.Map;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.OperationsMap;

public class AlgoliaJavaScriptGenerator extends TypeScriptNodeClientCodegen {

Expand All @@ -30,6 +29,9 @@ public void processOpts() {
setSupportsES6(true);
setModelPropertyNaming("original");
setApiPackage("src");

languageSpecificPrimitives.add("Record");
instantiationTypes.put("map", "Record");
// clear all supported files to avoid unwanted ones
supportingFiles.clear();

Expand Down Expand Up @@ -64,8 +66,8 @@ private void setDefaultGeneratorOptions() {

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

setDefaultGeneratorOptions();
try {
Expand All @@ -77,7 +79,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
System.exit(1);
}

List<CodegenOperation> operations = ((Map<String, List<CodegenOperation>>) results.get("operations")).get("operation");
List<CodegenOperation> operations = results.getOperations().getOperation();

// We read operations and detect if we should wrap parameters under an object.
// We only wrap if there is a mix between body parameters and other parameters.
Expand Down Expand Up @@ -139,21 +141,4 @@ public String toApiFilename(String name) {
public String apiFilename(String templateName, String tag) {
return super.apiFilename(templateName, toApiFilename(CLIENT));
}

@Override
protected String getParameterDataType(Parameter parameter, Schema p) {
String type = super.getParameterDataType(parameter, p);
// openapi generator is wrong, 'object' is not a fit all object, we need 'any'
// we use replace because there might be more to this type, like '| undefined'
return type.replace("{ [key: string]: object; }", "Record<string, any>");
}

@Override
public String toInstantiationType(Schema schema) {
String type = super.toInstantiationType(schema);

// Same as the `getParameterDataType` but for the models, the generator
// consider `object` as a fit all which is wrong in TypeScript
return type.replace("null<String, object>", "Record<string, any>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.servers.Server;
import java.util.List;
import java.util.Map;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.languages.PhpClientCodegen;
Expand All @@ -31,6 +30,15 @@ public void processOpts() {
supportingFiles.removeIf(file -> file.getTemplateFile().equals("Configuration.mustache"));

supportingFiles.add(new SupportingFile("Configuration.mustache", "lib/Configuration", "Configuration.php"));

setDefaultGeneratorOptions(client);
try {
Utils.generateServer(client, additionalProperties);
additionalProperties.put("packageVersion", Utils.getClientConfigField("php", "packageVersion"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
}
}

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

/** Provides an opportunity to inspect and modify operation data before the code is generated. */
@Override
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
Map<String, Object> results = super.postProcessOperationsWithModels(objs, allModels);

String client = (String) additionalProperties.get("client");

setDefaultGeneratorOptions(client);
try {
Utils.generateServer(client, additionalProperties);
additionalProperties.put("packageVersion", Utils.getClientConfigField("php", "packageVersion"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
}

return results;
}

public String getComposerPackageName() {
return "algolia/algoliasearch-client-php";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Map.Entry;
import java.util.TreeMap;
import org.openapitools.codegen.*;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;

@SuppressWarnings("unchecked")
public class AlgoliaCTSGenerator extends DefaultCodegen {
Expand Down Expand Up @@ -56,12 +58,12 @@ public void processOpts() {
}

@Override
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
Map<String, Object> mod = super.postProcessAllModels(objs);
for (Entry<String, Object> entry : mod.entrySet()) {
List<Object> innerModel = ((Map<String, List<Object>>) entry.getValue()).get("models");
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
Map<String, ModelsMap> mod = super.postProcessAllModels(objs);
for (Entry<String, ModelsMap> entry : mod.entrySet()) {
List<ModelMap> innerModel = entry.getValue().getModels();
if (!innerModel.isEmpty()) {
models.put(entry.getKey(), (CodegenModel) ((Map<String, Object>) innerModel.get(0)).get("model"));
models.put(entry.getKey(), innerModel.get(0).getModel());
}
}
return mod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private void handlePrimitive(Object param, Map<String, Object> testOutput, IJson
transferPrimitiveData(spec, testOutput);
} else {
inferDataType(param, null, testOutput);
if (spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType) {
if (isAnyType(spec)) {
testOutput.put("isAnyType", true);
}
}
Expand All @@ -395,6 +395,19 @@ private String getTypeName(IJsonSchemaValidationProperties param) {
return null;
}

private boolean isAnyType(IJsonSchemaValidationProperties param) {
if (param instanceof CodegenParameter) {
return ((CodegenParameter) param).isAnyType;
}
if (param instanceof CodegenProperty) {
return ((CodegenProperty) param).isAnyType;
}
if (param instanceof CodegenResponse) {
return ((CodegenResponse) param).isAnyType;
}
return false;
}

private boolean isEnum(IJsonSchemaValidationProperties param) {
if (param instanceof CodegenParameter) {
return ((CodegenParameter) param).isEnum;
Expand Down
2 changes: 2 additions & 0 deletions specs/analytics/common/schemas/getTopHits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ topHitsResponse:
description: A list of top hits with their count.
items:
type: object
title: topHit
additionalProperties: false
required:
- hit
Expand All @@ -30,6 +31,7 @@ topHitsResponseWithAnalytics:
description: A list of top hits with their count and analytics.
items:
type: object
title: topHitWithAnalytics
additionalProperties: false
required:
- hit
Expand Down
2 changes: 2 additions & 0 deletions specs/analytics/common/schemas/getTopSearches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ topSearchesResponse:
description: A list of top searches with their count.
items:
type: object
title: topSearch
additionalProperties: false
required:
- search
Expand All @@ -33,6 +34,7 @@ topSearchesResponseWithAnalytics:
description: A list of top searches with their count and analytics.
items:
type: object
title: topSearchWithAnalytics
additionalProperties: false
required:
- search
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/click/getAverageClickPosition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ get:
description: A list of average click position with their date.
items:
type: object
title: averageClickEvent
additionalProperties: false
required:
- average
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/click/getClickPositions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ get:
maxItems: 2
items:
type: object
title: clickPosition
additionalProperties: false
required:
- position
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/click/getClickThroughRate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ get:
description: A list of click-through rate events with their date.
items:
type: object
title: clickThroughRateEvent
additionalProperties: false
required:
- rate
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/click/getConversionRate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ get:
description: A list of conversion events with their date.
items:
type: object
title: conversionRateEvent
additionalProperties: false
required:
- rate
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getNoClickRate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ get:
description: A list of searches without clicks with their date, rate and counts.
items:
type: object
title: noClickRateEvent
additionalProperties: false
required:
- rate
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getNoResultsRate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ get:
description: A list of searches without results with their date, rate and counts.
items:
type: object
title: noResultsRateEvent
additionalProperties: false
required:
- date
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getSearchesCount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ get:
description: A list of search events with their date and count.
items:
type: object
title: searchEvent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searchCountEvent ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we say A list of search events in the description, not sure what search count event mean

additionalProperties: false
required:
- date
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getSearchesNoClicks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get:
description: A list of searches with no clicks and their count.
items:
type: object
title: searchNoClickEvent
additionalProperties: false
required:
- search
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getSearchesNoResults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get:
description: A list of searches with no results and their count.
items:
type: object
title: searchNoResultEvent
additionalProperties: false
required:
- search
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getTopCountries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ get:
description: A list of countries with their count.
items:
type: object
title: topCountry
additionalProperties: false
required:
- country
Expand Down
1 change: 1 addition & 0 deletions specs/analytics/paths/search/getUsersCount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ get:
description: A list of users count with their date.
items:
type: object
title: userWithDate
additionalProperties: false
required:
- date
Expand Down
Loading