Skip to content

Commit 96dbb43

Browse files
jimschubertrienafairefr
authored and
rienafairefr
committed
Initialize config-customized mustache compiler only once
1 parent 1732281 commit 96dbb43

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,7 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
708708
}
709709

710710
if (ignoreProcessor.allowsFile(new File(outputFilename))) {
711-
if (Arrays.stream(templatingEngine.getFileExtensions())
712-
.anyMatch(templateFile::endsWith)) {
713-
configPostProcessMustacheCompiler();
711+
if (Arrays.stream(templatingEngine.getFileExtensions()).anyMatch(templateFile::endsWith)) {
714712
String templateContent = templatingEngine.compileTemplate(this, bundle, support.templateFile);
715713
writeToFile(outputFilename, templateContent);
716714
File written = new File(outputFilename);
@@ -890,6 +888,9 @@ public List<File> generate() {
890888
configureGeneratorProperties();
891889
configureOpenAPIInfo();
892890

891+
// If the template adapter is mustache, we'll set the config-modified Compiler.
892+
configPostProcessMustacheCompiler();
893+
893894
List<File> files = new ArrayList<File>();
894895
// models
895896
List<String> filteredSchemas = ModelUtils.getSchemasUsedOnlyInFormParam(openAPI);
@@ -918,7 +919,6 @@ public String getFullTemplateContents(String templateName) {
918919
protected File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename) throws IOException {
919920
String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar);
920921
if (ignoreProcessor.allowsFile(new File(adjustedOutputFilename))) {
921-
configPostProcessMustacheCompiler();
922922
String templateContent = templatingEngine.compileTemplate(this, templateData, templateName);
923923
writeToFile(adjustedOutputFilename, templateContent);
924924
return new File(adjustedOutputFilename);

modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ public ClientOptInput toClientOptInput() {
544544
config.setLibrary(library);
545545
}
546546

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

0 commit comments

Comments
 (0)