forked from loafle/openapi-generator-original
Expose Handlebars infiniteLoops setting (#7926)
This commit is contained in:
parent
a2e5d274d6
commit
129881d04a
@ -45,6 +45,7 @@ public class HandlebarsEngineAdapter extends AbstractTemplatingEngineAdapter {
|
||||
|
||||
// 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
|
||||
private final String[] canCompileFromExtensions = new String[]{".handlebars",".hbs",".mustache"};
|
||||
private boolean infiniteLoops = false;
|
||||
|
||||
/**
|
||||
* Provides an identifier used to load the adapter. This could be a name, uuid, or any other string.
|
||||
@ -82,6 +83,7 @@ public class HandlebarsEngineAdapter extends AbstractTemplatingEngineAdapter {
|
||||
StringHelpers.register(handlebars);
|
||||
handlebars.registerHelpers(ConditionalHelpers.class);
|
||||
handlebars.registerHelpers(org.openapitools.codegen.templating.handlebars.StringHelpers.class);
|
||||
handlebars.setInfiniteLoops(infiniteLoops);
|
||||
Template tmpl = handlebars.compile(templateFile);
|
||||
return tmpl.apply(context);
|
||||
}
|
||||
@ -121,5 +123,16 @@ public class HandlebarsEngineAdapter extends AbstractTemplatingEngineAdapter {
|
||||
// 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)
|
||||
return Arrays.stream(canCompileFromExtensions).anyMatch(suffix -> !suffix.equalsIgnoreCase(filename) && filename.endsWith(suffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable infiniteLoops setting for the Handlebars engine. Enabling this allows for recursive partial inclusion.
|
||||
*
|
||||
* @param infiniteLoops Whether to enable (true) or disable (false)
|
||||
* @return this object
|
||||
*/
|
||||
public HandlebarsEngineAdapter infiniteLoops(boolean infiniteLoops) {
|
||||
this.infiniteLoops = infiniteLoops;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user