Skip to content
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

Renamed template source directory #180

Merged
merged 3 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Issue #177: updated resource template dir for generators.
  • Loading branch information
HugoMario committed Sep 22, 2018
commit 477b877104335a8c73761a151c36e612885da4c7
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {

public static final String DEFAULT_CONTENT_TYPE = "application/json";
public static final String REQUEST_BODY_NAME = "body";
public static final String DEFAULT_TEMPLATE_VERSION = "v2";
public static final String DEFAULT_TEMPLATE_DIR = "handlebars";

protected String inputSpec;
protected String outputFolder = StringUtils.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,7 @@ public String getHelp() {
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/swagger-static", templateVersion);
}
else {
embeddedTemplateDir = templateDir = String.format("%s/swagger-static", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/swagger-static", DEFAULT_TEMPLATE_DIR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs2", templateVersion);
}
else {
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs2", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs2", DEFAULT_TEMPLATE_DIR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs", templateVersion);
}
else {
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/htmlDocs", DEFAULT_TEMPLATE_DIR);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", DEFAULT_TEMPLATE_DIR);
}

// clear model and api doc template as this codegen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf", DEFAULT_TEMPLATE_DIR);
}

apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ public void processOpts() {
super.processOpts();
if (StringUtils.isBlank(templateDir)) {
String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "Java", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "Java", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "Java", DEFAULT_TEMPLATE_DIR);
}

if (additionalProperties.containsKey(USE_RX_JAVA) && additionalProperties.containsKey(USE_RX_JAVA2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/JavaInflector", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/JavaInflector", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/JavaInflector", DEFAULT_TEMPLATE_DIR);
}
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public void processOpts() {
// Set the template dir first, before super.processOpts(), otherwise it is going to
// be set to /spec location.
if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf-cdi", templateVersion);
}
else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf-cdi", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/cxf-cdi", DEFAULT_TEMPLATE_DIR);
}

super.processOpts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/spec", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/spec", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/spec", DEFAULT_TEMPLATE_DIR);
}

modelTemplateFiles.put("model.mustache", ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME, templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME, DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME, DEFAULT_TEMPLATE_DIR);
}

addTemplateFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy/eap", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy/eap", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy/eap", DEFAULT_TEMPLATE_DIR);
}

apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s/" + JAXRS_TEMPLATE_DIRECTORY_NAME + "/resteasy", DEFAULT_TEMPLATE_DIR);
}

apiTemplateFiles.put("apiService.mustache", ".java");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ public void setDateLibrary(String library) {
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-client", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-client", DEFAULT_TEMPLATE_VERSION);
if (StringUtils.isBlank(templateDir)) {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-client", DEFAULT_TEMPLATE_DIR);
}

if (additionalProperties.containsKey(DATE_LIBRARY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-server", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-server", DEFAULT_TEMPLATE_VERSION);
if (StringUtils.isBlank(templateDir)) {
embeddedTemplateDir = templateDir = String.format("%s/kotlin-server", DEFAULT_TEMPLATE_DIR);
}

if (!additionalProperties.containsKey(GENERATE_APIS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,7 @@ public void processOpts() {

super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = String.format("%s" + File.separator + "php", templateVersion);
} else {
embeddedTemplateDir = String.format("%s" + File.separator + "php", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = String.format("%s" + File.separator + "php", DEFAULT_TEMPLATE_DIR);
if (StringUtils.isBlank(templateDir)) {
templateDir = embeddedTemplateDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,8 @@ protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, Sc
public void processOpts() {
super.processOpts();

String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s/%s", templateVersion, getName());
} else {
embeddedTemplateDir = templateDir = String.format("%s/%s", DEFAULT_TEMPLATE_VERSION, getName());
if (StringUtils.isNotBlank(templateDir)) {
embeddedTemplateDir = templateDir = String.format("%s/%s", DEFAULT_TEMPLATE_DIR, getName());
}

// Setup project name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ public void processOpts() {
super.processOpts();

if (StringUtils.isBlank(templateDir)) {
String templateVersion = getTemplateVersion();
if (StringUtils.isNotBlank(templateVersion)) {
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "typescript-angular", templateVersion);
} else {
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "typescript-angular", DEFAULT_TEMPLATE_VERSION);
}
embeddedTemplateDir = templateDir = String.format("%s" + File.separator + "typescript-angular", DEFAULT_TEMPLATE_DIR);
}

modelTemplateFiles.put("model.mustache", ".ts");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testPackageNamesSetInvokerDerivedFromModel() throws Exception {
public void customTemplates() throws Exception {
final JavaClientCodegen codegen = new JavaClientCodegen();
codegen.processOpts();
Assert.assertEquals(codegen.templateDir(), "v2" + File.separator + "Java");
Assert.assertEquals(codegen.templateDir(), "handlebars" + File.separator + "Java");

codegen.additionalProperties().put(CodegenConstants.TEMPLATE_DIR, String.join(File.separator,"user", "custom", "location"));
codegen.processOpts();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void testInitialValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG), Boolean.TRUE);
Assert.assertEquals(codegen.getHideGenerationTimestamp(), Boolean.TRUE);
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
Assert.assertEquals(codegen.templateDir(), "v2/php");
Assert.assertEquals(codegen.embeddedTemplateDir(), "v2/php");
Assert.assertEquals(codegen.templateDir(), "handlebars/php");
Assert.assertEquals(codegen.embeddedTemplateDir(), "handlebars/php");
}

@Test
Expand Down Expand Up @@ -74,7 +74,7 @@ public void testPutTemplateDirProperty() throws Exception {
codegen.processOpts();

Assert.assertEquals(codegen.templateDir(), "/absolute/path");
Assert.assertEquals(codegen.embeddedTemplateDir(), "v2/php");
Assert.assertEquals(codegen.embeddedTemplateDir(), "handlebars/php");
}


Expand Down