Skip to content

Commit

Permalink
fix: no error on unmatched
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Jul 11, 2023
1 parent be4dca0 commit fce9eb9
Show file tree
Hide file tree
Showing 22 changed files with 665 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,39 @@ public void processOpts() {
libName = "algoliasearch";
packageFolder = libName;
setPubDescription(
"A Dart package for Algolia. Enables seamless integration for instant search, typo" +
" tolerance & user insights, and more, in Dart/Flutter apps."
);
"A Dart package for Algolia. Enables seamless integration for instant search, typo"
+ " tolerance & user insights, and more, in Dart/Flutter apps.");
} else {
libName = "algolia_client_" + client;
packageFolder = "client_" + client;
setApiNameSuffix(Utils.API_SUFFIX);
setPubDescription(
"A sub-package of the AlgoliaSearch library, offering " +
client +
"-specific functionalities for enhanced search and discovery in Dart/Flutter" +
" apps."
);
"A sub-package of the AlgoliaSearch library, offering "
+ client
+ "-specific functionalities for enhanced search and discovery in Dart/Flutter"
+ " apps.");
}
setPubName(libName);
setPubLibrary(libName);
setPubRepository("https://github.com/algolia/algoliasearch-client-dart/tree/main/packages/" + packageFolder);
setPubRepository(
"https://github.com/algolia/algoliasearch-client-dart/tree/main/packages/" + packageFolder);

// configs
additionalProperties.put(CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_JSON_SERIALIZABLE);
additionalProperties.put(
CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_JSON_SERIALIZABLE);

super.processOpts();

Arrays.asList("source", "get", "hide").forEach(reservedWords::remove); // reserved words from dart-keywords.txt
Arrays.asList("source", "get", "hide")
.forEach(reservedWords::remove); // reserved words from dart-keywords.txt

if (isAlgoliasearchClient) {
supportingFiles.removeIf(file -> file.getTemplateFile().contains("lib"));
supportingFiles.add(new SupportingFile("lib.mustache", libPath, "algoliasearch_lite.dart"));
additionalProperties.put("searchVersion", Utils.getOpenApiToolsField("dart", "search", "packageVersion"));
additionalProperties.put("insightsVersion", Utils.getOpenApiToolsField("dart", "insights", "packageVersion"));
additionalProperties.put(
"searchVersion", Utils.getOpenApiToolsField("dart", "search", "packageVersion"));
additionalProperties.put(
"insightsVersion", Utils.getOpenApiToolsField("dart", "insights", "packageVersion"));
}

// disable documentation and tests
Expand All @@ -93,7 +96,8 @@ public void processOpts() {

// Search config
additionalProperties.put("isSearchClient", client.equals("search"));
additionalProperties.put("packageVersion", Utils.getClientConfigField("dart", "packageVersion"));
additionalProperties.put(
"packageVersion", Utils.getClientConfigField("dart", "packageVersion"));

// typeMapping.put("object", "Map<String, dynamic>"); // from kotlinx.serialization

Expand All @@ -113,14 +117,16 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
}

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

@Override
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
public OperationsMap postProcessOperationsWithModels(
OperationsMap objs, List<ModelMap> allModels) {
OperationsMap operationsMap = super.postProcessOperationsWithModels(objs, allModels);
return support.clearOneOfFromApiImports(operationsMap);
}
Expand All @@ -135,7 +141,8 @@ class SchemaSupport {

private static final String GENERIC_TYPE = "dynamic";

private final Map<String, String> oneOfs = new HashMap<>(); // Maintain a list of deleted class names
private final Map<String, String> oneOfs =
new HashMap<>(); // Maintain a list of deleted class names

public Set<String> classnames() {
return oneOfs.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ public void processOpts() {

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

@Override
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
public CodegenOperation fromOperation(
String path, String httpMethod, Operation operation, List<Server> servers) {
return Utils.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,28 @@ public void processOpts() {
apiDocTemplateFiles.clear();
modelDocTemplateFiles.clear();

supportingFiles.removeIf(file ->
file.getTemplateFile().equals("build.gradle.mustache") ||
file.getTemplateFile().equals("settings.gradle.mustache") ||
file.getTemplateFile().equals("gitignore.mustache") ||
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")
);
supportingFiles.removeIf(
file ->
file.getTemplateFile().equals("build.gradle.mustache")
|| file.getTemplateFile().equals("settings.gradle.mustache")
|| file.getTemplateFile().equals("gitignore.mustache")
|| 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"));

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

try {
Utils.generateServer(client, additionalProperties);

additionalProperties.put("packageVersion", Utils.getClientConfigField("java", "packageVersion"));
additionalProperties.put(
"packageVersion", Utils.getClientConfigField("java", "packageVersion"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
Expand All @@ -75,7 +76,8 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc
}

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

Expand All @@ -102,7 +104,8 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
model.vendorExtensions.put("x-is-one-of-interface", true);
model.vendorExtensions.put("x-one-of-list", oneOfList);

model.vendorExtensions.put("x-one-of-explicit-name", Utils.shouldUseExplicitOneOfName(model.oneOf));
model.vendorExtensions.put(
"x-one-of-explicit-name", Utils.shouldUseExplicitOneOfName(model.oneOf));
}
}

Expand Down Expand Up @@ -134,7 +137,10 @@ public String toEnumVarName(String value, String datatype) {

if (!value.matches("[A-Z0-9_]+")) {
// convert camelCase77String to CAMEL_CASE_77_STRING
return value.replaceAll("-", "_").replaceAll("(.+?)([A-Z]|[0-9])", "$1_$2").toUpperCase(Locale.ROOT);
return value
.replaceAll("-", "_")
.replaceAll("(.+?)([A-Z]|[0-9])", "$1_$2")
.toUpperCase(Locale.ROOT);
}

return super.toEnumVarName(value, datatype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,45 @@ public void processOpts() {
// `client` related files, `algoliasearch` have it's own logic below
if (!isAlgoliasearchClient) {
// models
supportingFiles.add(new SupportingFile("client/model/clientMethodProps.mustache", "model", "clientMethodProps.ts"));
supportingFiles.add(new SupportingFile("client/model/modelBarrel.mustache", "model", "index.ts"));
supportingFiles.add(
new SupportingFile(
"client/model/clientMethodProps.mustache", "model", "clientMethodProps.ts"));
supportingFiles.add(
new SupportingFile("client/model/modelBarrel.mustache", "model", "index.ts"));

// builds
supportingFiles.add(new SupportingFile("client/builds/browser.mustache", "builds", "browser.ts"));
supportingFiles.add(
new SupportingFile("client/builds/browser.mustache", "builds", "browser.ts"));
supportingFiles.add(new SupportingFile("client/builds/node.mustache", "builds", "node.ts"));
}
// `algoliasearch` related files
else {
// `algoliasearch` builds
supportingFiles.add(new SupportingFile("algoliasearch/builds/browser.mustache", "builds", "browser.ts"));
supportingFiles.add(new SupportingFile("algoliasearch/builds/node.mustache", "builds", "node.ts"));
supportingFiles.add(new SupportingFile("algoliasearch/builds/models.mustache", "builds", "models.ts"));
supportingFiles.add(
new SupportingFile("algoliasearch/builds/browser.mustache", "builds", "browser.ts"));
supportingFiles.add(
new SupportingFile("algoliasearch/builds/node.mustache", "builds", "node.ts"));
supportingFiles.add(
new SupportingFile("algoliasearch/builds/models.mustache", "builds", "models.ts"));

// `lite` builds
supportingFiles.add(new SupportingFile("client/builds/browser.mustache", "lite/builds", "browser.ts"));
supportingFiles.add(new SupportingFile("client/builds/node.mustache", "lite/builds", "node.ts"));
supportingFiles.add(
new SupportingFile("client/builds/browser.mustache", "lite/builds", "browser.ts"));
supportingFiles.add(
new SupportingFile("client/builds/node.mustache", "lite/builds", "node.ts"));

// `lite` models
supportingFiles.add(new SupportingFile("client/model/clientMethodProps.mustache", "lite/model", "clientMethodProps.ts"));
supportingFiles.add(new SupportingFile("client/model/modelBarrel.mustache", "lite/model", "index.ts"));
supportingFiles.add(
new SupportingFile(
"client/model/clientMethodProps.mustache", "lite/model", "clientMethodProps.ts"));
supportingFiles.add(
new SupportingFile("client/model/modelBarrel.mustache", "lite/model", "index.ts"));

// `lite root export files
supportingFiles.add(new SupportingFile("algoliasearch/lite.mustache", "", "lite.js"));
supportingFiles.add(new SupportingFile("algoliasearch/lite.d.mustache", "", "lite.d.ts"));
supportingFiles.add(new SupportingFile("algoliasearch/lite.tsconfig.mustache", "", "lite/tsconfig.json"));
supportingFiles.add(
new SupportingFile("algoliasearch/lite.tsconfig.mustache", "", "lite/tsconfig.json"));
}
}

Expand All @@ -106,7 +119,8 @@ public String modelFileFolder() {
}

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

Expand All @@ -124,10 +138,17 @@ private void setDefaultGeneratorOptions() {

if (isAlgoliasearchClient) {
// Files used to create the package.json of the algoliasearch package
additionalProperties.put("analyticsVersion", Utils.getOpenApiToolsField("javascript", "analytics", "packageVersion"));
additionalProperties.put("abtestingVersion", Utils.getOpenApiToolsField("javascript", "abtesting", "packageVersion"));
additionalProperties.put("personalizationVersion", Utils.getOpenApiToolsField("javascript", "personalization", "packageVersion"));
additionalProperties.put("searchVersion", Utils.getOpenApiToolsField("javascript", "search", "packageVersion"));
additionalProperties.put(
"analyticsVersion",
Utils.getOpenApiToolsField("javascript", "analytics", "packageVersion"));
additionalProperties.put(
"abtestingVersion",
Utils.getOpenApiToolsField("javascript", "abtesting", "packageVersion"));
additionalProperties.put(
"personalizationVersion",
Utils.getOpenApiToolsField("javascript", "personalization", "packageVersion"));
additionalProperties.put(
"searchVersion", Utils.getOpenApiToolsField("javascript", "search", "packageVersion"));

// Files used to generate the `lite` client
apiName = "lite" + Utils.API_SUFFIX;
Expand All @@ -146,14 +167,17 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)

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

setDefaultGeneratorOptions();
try {
Utils.generateServer((String) additionalProperties.get("client"), additionalProperties);
additionalProperties.put("utilsPackageVersion", Utils.getClientConfigField("javascript", "utilsPackageVersion"));
additionalProperties.put("npmNamespace", Utils.getClientConfigField("javascript", "npmNamespace"));
additionalProperties.put(
"utilsPackageVersion", Utils.getClientConfigField("javascript", "utilsPackageVersion"));
additionalProperties.put(
"npmNamespace", Utils.getClientConfigField("javascript", "npmNamespace"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
Expand Down
Loading

0 comments on commit fce9eb9

Please sign in to comment.