forked from loafle/openapi-generator-original
Has generators set default template engine (#11245)
* Adds default template engine to generators * Fixes sample batch generation
This commit is contained in:
parent
a4325ec520
commit
dd3bba8c94
@ -2,7 +2,6 @@ generatorName: python-experimental
|
||||
outputDir: samples/openapi3/client/petstore/python-experimental
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/python-experimental
|
||||
templatingEngineName: handlebars
|
||||
additionalProperties:
|
||||
packageName: petstore_api
|
||||
recursionLimit: "1234"
|
||||
|
@ -46,7 +46,7 @@ public class WorkflowSettings {
|
||||
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
|
||||
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
|
||||
public static final boolean DEFAULT_GENERATE_ALIAS_AS_MODEL = false;
|
||||
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = "mustache";
|
||||
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = null; // this is set by the generator
|
||||
public static final Map<String, String> DEFAULT_GLOBAL_PROPERTIES = Collections.unmodifiableMap(new HashMap<>());
|
||||
|
||||
private String inputSpec;
|
||||
|
@ -304,4 +304,6 @@ public interface CodegenConfig {
|
||||
void setRemoveEnumValuePrefix(boolean removeEnumValuePrefix);
|
||||
|
||||
Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings);
|
||||
|
||||
public String defaultTemplatingEngine();
|
||||
}
|
||||
|
@ -7356,4 +7356,9 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
return xOf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String defaultTemplatingEngine() {
|
||||
return "mustache";
|
||||
}
|
||||
}
|
||||
|
@ -91,11 +91,18 @@ public class CodegenConfigurator {
|
||||
WorkflowSettings workflowSettings = settings.getWorkflowSettings();
|
||||
List<TemplateDefinition> userDefinedTemplateSettings = settings.getFiles();
|
||||
|
||||
CodegenConfig config = CodegenConfigLoader.forName(generatorSettings.getGeneratorName());
|
||||
String templatingEngineName = workflowSettings.getTemplatingEngineName();
|
||||
if (isEmpty(templatingEngineName)) {
|
||||
// if templatingEngineName is empty check the config for a default
|
||||
templatingEngineName = config.defaultTemplatingEngine();
|
||||
}
|
||||
|
||||
// We copy "cached" properties into configurator so it is appropriately configured with all settings in external files.
|
||||
// FIXME: target is to eventually move away from CodegenConfigurator properties except gen/workflow settings.
|
||||
configurator.generatorName = generatorSettings.getGeneratorName();
|
||||
configurator.inputSpec = workflowSettings.getInputSpec();
|
||||
configurator.templatingEngineName = workflowSettings.getTemplatingEngineName();
|
||||
configurator.templatingEngineName = templatingEngineName;
|
||||
if (workflowSettings.getGlobalProperties() != null) {
|
||||
configurator.globalProperties.putAll(workflowSettings.getGlobalProperties());
|
||||
}
|
||||
@ -482,15 +489,17 @@ public class CodegenConfigurator {
|
||||
Validate.notEmpty(generatorName, "generator name must be specified");
|
||||
Validate.notEmpty(inputSpec, "input spec must be specified");
|
||||
|
||||
GeneratorSettings generatorSettings = generatorSettingsBuilder.build();
|
||||
CodegenConfig config = CodegenConfigLoader.forName(generatorSettings.getGeneratorName());
|
||||
if (isEmpty(templatingEngineName)) {
|
||||
// Built-in templates are mustache, but allow users to use a simplified handlebars engine for their custom templates.
|
||||
workflowSettingsBuilder.withTemplatingEngineName("mustache");
|
||||
// if templatingEngineName is empty check the config for a default
|
||||
String defaultTemplatingEngine = config.defaultTemplatingEngine();
|
||||
workflowSettingsBuilder.withTemplatingEngineName(defaultTemplatingEngine);
|
||||
} else {
|
||||
workflowSettingsBuilder.withTemplatingEngineName(templatingEngineName);
|
||||
}
|
||||
|
||||
// at this point, all "additionalProperties" are set, and are now immutable per GeneratorSettings instance.
|
||||
GeneratorSettings generatorSettings = generatorSettingsBuilder.build();
|
||||
WorkflowSettings workflowSettings = workflowSettingsBuilder.build();
|
||||
|
||||
if (workflowSettings.isVerbose()) {
|
||||
|
@ -2075,4 +2075,9 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
|
||||
}
|
||||
return co;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String defaultTemplatingEngine() {
|
||||
return "handlebars";
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user