Skip to content

Commit

Permalink
Initialize config-customized mustache compiler only once
Browse files Browse the repository at this point in the history
  • Loading branch information
jimschubert authored and rienafairefr committed Mar 11, 2019
1 parent 1732281 commit 96dbb43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,7 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
}

if (ignoreProcessor.allowsFile(new File(outputFilename))) {
if (Arrays.stream(templatingEngine.getFileExtensions())
.anyMatch(templateFile::endsWith)) {
configPostProcessMustacheCompiler();
if (Arrays.stream(templatingEngine.getFileExtensions()).anyMatch(templateFile::endsWith)) {
String templateContent = templatingEngine.compileTemplate(this, bundle, support.templateFile);
writeToFile(outputFilename, templateContent);
File written = new File(outputFilename);
Expand Down Expand Up @@ -890,6 +888,9 @@ public List<File> generate() {
configureGeneratorProperties();
configureOpenAPIInfo();

// If the template adapter is mustache, we'll set the config-modified Compiler.
configPostProcessMustacheCompiler();

List<File> files = new ArrayList<File>();
// models
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
Expand Down Expand Up @@ -918,7 +919,6 @@ public String getFullTemplateContents(String templateName) {
protected File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename) throws IOException {
String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar);
if (ignoreProcessor.allowsFile(new File(adjustedOutputFilename))) {
configPostProcessMustacheCompiler();
String templateContent = templatingEngine.compileTemplate(this, templateData, templateName);
writeToFile(adjustedOutputFilename, templateContent);
return new File(adjustedOutputFilename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ public ClientOptInput toClientOptInput() {
config.setLibrary(library);
}

// Built-in templates are mustache, but allow users to use a simplified handlebars engine for their custom templates.
if (isEmpty(templatingEngineName) || templatingEngineName.equals("mustache")) {
config.setTemplatingEngine(new MustacheEngineAdapter());
} else if (templatingEngineName.equals("handlebars")) {
Expand Down

0 comments on commit 96dbb43

Please sign in to comment.