Skip to content

Commit 129881d

Browse files
author
Slavek Kabrda
authored
Expose Handlebars infiniteLoops setting (#7926)
1 parent a2e5d27 commit 129881d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class HandlebarsEngineAdapter extends AbstractTemplatingEngineAdapter {
4545

4646
// We use this as a simple lookup for valid file name extensions. This adapter will inspect .mustache (built-in) and infer the relevant handlebars filename
4747
private final String[] canCompileFromExtensions = new String[]{".handlebars",".hbs",".mustache"};
48+
private boolean infiniteLoops = false;
4849

4950
/**
5051
* Provides an identifier used to load the adapter. This could be a name, uuid, or any other string.
@@ -82,6 +83,7 @@ public TemplateSource sourceAt(String location) {
8283
StringHelpers.register(handlebars);
8384
handlebars.registerHelpers(ConditionalHelpers.class);
8485
handlebars.registerHelpers(org.openapitools.codegen.templating.handlebars.StringHelpers.class);
86+
handlebars.setInfiniteLoops(infiniteLoops);
8587
Template tmpl = handlebars.compile(templateFile);
8688
return tmpl.apply(context);
8789
}
@@ -121,5 +123,16 @@ public boolean handlesFile(String filename) {
121123
// disallow any extension-only files like ".hbs" or ".mustache", and only consider a file compilable if it's handlebars or mustache (from which we later infer the handlebars filename)
122124
return Arrays.stream(canCompileFromExtensions).anyMatch(suffix -> !suffix.equalsIgnoreCase(filename) && filename.endsWith(suffix));
123125
}
126+
127+
/**
128+
* Enable/disable infiniteLoops setting for the Handlebars engine. Enabling this allows for recursive partial inclusion.
129+
*
130+
* @param infiniteLoops Whether to enable (true) or disable (false)
131+
* @return this object
132+
*/
133+
public HandlebarsEngineAdapter infiniteLoops(boolean infiniteLoops) {
134+
this.infiniteLoops = infiniteLoops;
135+
return this;
136+
}
124137
}
125138

0 commit comments

Comments
 (0)