Has generators set default template engine (#11245)

* Adds default template engine to generators

* Fixes sample batch generation
This commit is contained in:
Justin Black 2022-01-10 08:59:20 -08:00 committed by GitHub
parent a4325ec520
commit dd3bba8c94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 6 deletions

View File

@ -2,7 +2,6 @@ generatorName: python-experimental
outputDir: samples/openapi3/client/petstore/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 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 templateDir: modules/openapi-generator/src/main/resources/python-experimental
templatingEngineName: handlebars
additionalProperties: additionalProperties:
packageName: petstore_api packageName: petstore_api
recursionLimit: "1234" recursionLimit: "1234"

View File

@ -46,7 +46,7 @@ public class WorkflowSettings {
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false; public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true; public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
public static final boolean DEFAULT_GENERATE_ALIAS_AS_MODEL = false; 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<>()); public static final Map<String, String> DEFAULT_GLOBAL_PROPERTIES = Collections.unmodifiableMap(new HashMap<>());
private String inputSpec; private String inputSpec;

View File

@ -304,4 +304,6 @@ public interface CodegenConfig {
void setRemoveEnumValuePrefix(boolean removeEnumValuePrefix); void setRemoveEnumValuePrefix(boolean removeEnumValuePrefix);
Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings); Schema unaliasSchema(Schema schema, Map<String, String> usedImportMappings);
public String defaultTemplatingEngine();
} }

View File

@ -7356,4 +7356,9 @@ public class DefaultCodegen implements CodegenConfig {
} }
return xOf; return xOf;
} }
@Override
public String defaultTemplatingEngine() {
return "mustache";
}
} }

View File

@ -91,11 +91,18 @@ public class CodegenConfigurator {
WorkflowSettings workflowSettings = settings.getWorkflowSettings(); WorkflowSettings workflowSettings = settings.getWorkflowSettings();
List<TemplateDefinition> userDefinedTemplateSettings = settings.getFiles(); 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. // 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. // FIXME: target is to eventually move away from CodegenConfigurator properties except gen/workflow settings.
configurator.generatorName = generatorSettings.getGeneratorName(); configurator.generatorName = generatorSettings.getGeneratorName();
configurator.inputSpec = workflowSettings.getInputSpec(); configurator.inputSpec = workflowSettings.getInputSpec();
configurator.templatingEngineName = workflowSettings.getTemplatingEngineName(); configurator.templatingEngineName = templatingEngineName;
if (workflowSettings.getGlobalProperties() != null) { if (workflowSettings.getGlobalProperties() != null) {
configurator.globalProperties.putAll(workflowSettings.getGlobalProperties()); configurator.globalProperties.putAll(workflowSettings.getGlobalProperties());
} }
@ -482,15 +489,17 @@ public class CodegenConfigurator {
Validate.notEmpty(generatorName, "generator name must be specified"); Validate.notEmpty(generatorName, "generator name must be specified");
Validate.notEmpty(inputSpec, "input spec must be specified"); Validate.notEmpty(inputSpec, "input spec must be specified");
GeneratorSettings generatorSettings = generatorSettingsBuilder.build();
CodegenConfig config = CodegenConfigLoader.forName(generatorSettings.getGeneratorName());
if (isEmpty(templatingEngineName)) { if (isEmpty(templatingEngineName)) {
// Built-in templates are mustache, but allow users to use a simplified handlebars engine for their custom templates. // if templatingEngineName is empty check the config for a default
workflowSettingsBuilder.withTemplatingEngineName("mustache"); String defaultTemplatingEngine = config.defaultTemplatingEngine();
workflowSettingsBuilder.withTemplatingEngineName(defaultTemplatingEngine);
} else { } else {
workflowSettingsBuilder.withTemplatingEngineName(templatingEngineName); workflowSettingsBuilder.withTemplatingEngineName(templatingEngineName);
} }
// at this point, all "additionalProperties" are set, and are now immutable per GeneratorSettings instance. // at this point, all "additionalProperties" are set, and are now immutable per GeneratorSettings instance.
GeneratorSettings generatorSettings = generatorSettingsBuilder.build();
WorkflowSettings workflowSettings = workflowSettingsBuilder.build(); WorkflowSettings workflowSettings = workflowSettingsBuilder.build();
if (workflowSettings.isVerbose()) { if (workflowSettings.isVerbose()) {

View File

@ -2075,4 +2075,9 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
} }
return co; return co;
} }
@Override
public String defaultTemplatingEngine() {
return "handlebars";
}
} }