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

Issue 178 #187

Merged
merged 5 commits into from
Sep 27, 2018
Merged
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
Next Next commit
Issue #178: select template engine according option.
  • Loading branch information
HugoMario committed Sep 26, 2018
commit dbc860177322c871e537a19a107cb1731b0d5670
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.swagger.codegen.v3.generators.handlebars.NotEmptyHelper;
import io.swagger.codegen.v3.generators.handlebars.StringUtilHelper;
import io.swagger.codegen.v3.templates.HandlebarTemplateEngine;
import io.swagger.codegen.v3.templates.MustacheTemplateEngine;
import io.swagger.codegen.v3.templates.TemplateEngine;
import io.swagger.codegen.v3.utils.ModelUtils;
import io.swagger.v3.core.util.Json;
Expand Down Expand Up @@ -150,6 +151,7 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
protected String gitUserId, gitRepoId, releaseNote;
protected String httpUserAgent;
protected Boolean hideGenerationTimestamp = true;
protected TemplateEngine templateEngine;
// How to encode special characters like $
// They are translated to words like "Dollar" and prefixed with '
// Then translated back during JSON encoding and decoding
Expand Down Expand Up @@ -229,6 +231,8 @@ public void processOpts() {
if (additionalProperties.containsKey(CodegenConstants.USE_OAS2)) {
this.setUseOas2(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_OAS2).toString()));
}

setTemplateEngine();
}

public Map<String, Object> postProcessAllModels(Map<String, Object> processedModels) {
Expand Down Expand Up @@ -3607,6 +3611,8 @@ public void setUseOas2(boolean useOas2) {
this.useOas2 = useOas2;
}

public abstract String getDefaultTemplateDir();

public boolean convertPropertyToBoolean(String propertyKey) {
boolean booleanValue = false;
if (additionalProperties.containsKey(propertyKey)) {
Expand Down Expand Up @@ -3651,6 +3657,24 @@ protected Parameter getParameterFromRef(String ref, OpenAPI openAPI) {
return parameterMap.get(parameterName);
}

protected void setTemplateEngine() {
String templateEngineKey = additionalProperties.get(CodegenConstants.TEMPLATE_ENGINE) != null ? additionalProperties.get(CodegenConstants.TEMPLATE_ENGINE).toString() : null;

if (templateEngineKey == null) {
templateEngine = new MustacheTemplateEngine(this);
} else {
if (CodegenConstants.HANDLEBARS_TEMPLATE_ENGINE.equalsIgnoreCase(templateEngineKey)) {
templateEngine = new HandlebarTemplateEngine(this);
} else {
templateEngine = new MustacheTemplateEngine(this);
}
}
}

protected String getTemplateDir() {
return templateEngine.getName() + File.separator + getDefaultTemplateDir();
}

private void setOauth2Info(CodegenSecurity codegenSecurity, OAuthFlow flow) {
codegenSecurity.authorizationUrl = flow.getAuthorizationUrl();
codegenSecurity.tokenUrl = flow.getTokenUrl();
Expand Down