Skip to content

Commit

Permalink
feat: common mustache helper
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Sep 26, 2024
1 parent 1b3a1a8 commit a589dfa
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("netcore_project.mustache", "Algolia.Search.csproj"));
supportingFiles.add(new SupportingFile("Configuration.mustache", "Clients", packageName + "Configuration.cs"));

supportingFiles.add(new SupportingFile("LICENSE", "../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", "../.github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "../");

reservedWords.removeIf(word -> word.equals("Configuration"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,9 @@ public void processOpts() {

supportingFiles.add(new SupportingFile("version.mustache", srcFolder, "version.dart"));
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));

supportingFiles.add(new SupportingFile("LICENSE", "../client_core/", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(
new SupportingFile("do-not-edit-this-repository.yml", "../../.github/workflows", "do-not-edit-this-repository.yml")
);

Helpers.addCommonSupportingFiles(supportingFiles, "../../");

// Search config
additionalProperties.put("isSearchClient", client.equals("search"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
supportingFiles.add(new SupportingFile("client.mustache", "", "client.go"));

supportingFiles.add(new SupportingFile("LICENSE", "../../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(
new SupportingFile("do-not-edit-this-repository.yml", "../../.github/workflows", "do-not-edit-this-repository.yml")
);
Helpers.addCommonSupportingFiles(supportingFiles, "../../");

try {
additionalProperties.put("packageVersion", Helpers.getClientConfigField("go", "packageVersion"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
additionalProperties.put("isSearchClient", client.equals("search"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

reservedWords.removeIf(word -> word.equals("configuration"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ public void processOpts() {
// root export files
supportingFiles.add(new SupportingFile("index.mustache", "", "index.js"));
supportingFiles.add(new SupportingFile("index.d.mustache", "", "index.d.ts"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("LICENSE", "", "../../LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(
new SupportingFile("do-not-edit-this-repository.yml", "../../.github/workflows", "do-not-edit-this-repository.yml")
);

Helpers.addCommonSupportingFiles(supportingFiles, "../../");

supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
supportingFiles.add(new SupportingFile("README_BOM.mustache", "client-bom", "README.md"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("packageVersion", Helpers.getClientConfigField("kotlin", "packageVersion"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("client_config.mustache", "lib/Configuration", getClientName(client) + "Config.php"));
supportingFiles.add(new SupportingFile("Algolia.mustache", "lib", "Algolia.php"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("isSearchClient", client.equals("search"));
additionalProperties.put("configClassname", getClientName(client) + "Config");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("__init__.mustache", "http", "__init__.py"));
supportingFiles.add(new SupportingFile("config.mustache", packageName, "config.py"));

supportingFiles.add(new SupportingFile("LICENSE", "../", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", "../.github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", "../.github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", "../.github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "../");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public void processOpts() {
apiTestTemplateFiles.clear();
modelTestTemplateFiles.clear();

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

// Remove some files we don't want to output or change their paths
supportingFiles.removeIf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("version.mustache", "", "version.sbt"));
supportingFiles.add(new SupportingFile("jsonSupport.mustache", modelFolder, "JsonSupport.scala"));

supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

additionalProperties.put("isSearchClient", client.equals("search"));
typeMapping.put("AnyType", "Any");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ public void processOpts() {
supportingFiles.add(
new SupportingFile("client_configuration.mustache", sourceFolder, getClientName(CLIENT) + "ClientConfiguration.swift")
);
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(new SupportingFile("do-not-edit-this-repository.yml", ".github/workflows", "do-not-edit-this-repository.yml"));
Helpers.addCommonSupportingFiles(supportingFiles, "");

supportingFiles.add(new SupportingFile("Package.mustache", "Package.swift"));
supportingFiles.add(new SupportingFile("podspec.mustache", projectName + ".podspec"));
Expand Down
10 changes: 10 additions & 0 deletions generators/src/main/java/com/algolia/codegen/utils/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenServer;
import org.openapitools.codegen.CodegenServerVariable;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.model.OperationsMap;

public class Helpers {
Expand Down Expand Up @@ -258,6 +259,15 @@ public static void prettyPrint(Object o) {
Json.prettyPrint(o);
}

public static void addCommonSupportingFiles(List<SupportingFile> supportingFiles, String root) {
supportingFiles.add(new SupportingFile("LICENSE", "", root + "LICENSE"));
supportingFiles.add(new SupportingFile("issue.yml", root + ".github/workflows", "issue.yml"));
supportingFiles.add(new SupportingFile("Bug_report.yml", root + ".github/ISSUE_TEMPLATE", "Bug_report.yml"));
supportingFiles.add(
new SupportingFile("do-not-edit-this-repository.yml", root + ".github/workflows", "do-not-edit-this-repository.yml")
);
}

public static String getLanguageVersion(String language) throws IOException {
String versionFile = language.equals("javascript")
? ".nvmrc"
Expand Down

0 comments on commit a589dfa

Please sign in to comment.