fix generateAliasAsModels in default generator (#3951)

This commit is contained in:
William Cheng 2019-09-26 11:31:25 +08:00 committed by GitHub
parent e20af77944
commit bd992a4218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 20 deletions

View File

@ -35,6 +35,7 @@ import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.config.GlobalSettings;
import org.openapitools.codegen.api.TemplatingEngineAdapter; import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.ignore.CodegenIgnoreProcessor; import org.openapitools.codegen.ignore.CodegenIgnoreProcessor;
import org.openapitools.codegen.languages.PythonClientExperimentalCodegen;
import org.openapitools.codegen.meta.GeneratorMetadata; import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.serializer.SerializerUtils; import org.openapitools.codegen.serializer.SerializerUtils;
@ -492,7 +493,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0); Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
if (modelTemplate != null && modelTemplate.containsKey("model")) { if (modelTemplate != null && modelTemplate.containsKey("model")) {
CodegenModel m = (CodegenModel) modelTemplate.get("model"); CodegenModel m = (CodegenModel) modelTemplate.get("model");
if (m.isAlias && !ModelUtils.isGenerateAliasAsModel()) { if (m.isAlias && !(config instanceof PythonClientExperimentalCodegen)) {
// alias to number, string, enum, etc, which should not be generated as model
// for PythonClientExperimentalCodegen, all aliases are generated as models
continue; // Don't create user-defined classes for aliases continue; // Don't create user-defined classes for aliases
} }
} }
@ -942,7 +945,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
* Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible. * Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.
* *
* @param name the template name (e.g. model.mustache) * @param name the template name (e.g. model.mustache)
*
* @return The {@link Path} to the template * @return The {@link Path} to the template
*/ */
@Override @Override

View File

@ -78,12 +78,9 @@ public class PythonClientExperimentalCodegen extends PythonClientCodegen {
// default this to true so the python ModelSimple models will be generated // default this to true so the python ModelSimple models will be generated
ModelUtils.setGenerateAliasAsModel(true); ModelUtils.setGenerateAliasAsModel(true);
if (additionalProperties.containsKey(CodegenConstants.GENERATE_ALIAS_AS_MODEL)) {
LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums"); LOGGER.info(CodegenConstants.GENERATE_ALIAS_AS_MODEL + " is hard coded to true in this generator. Alias models will only be generated if they contain validations or enums");
} }
}
/** /**
* Configures a friendly name for the generator. This will be used by the * Configures a friendly name for the generator. This will be used by the
* generator to select the library with the -g flag. * generator to select the library with the -g flag.
@ -108,6 +105,7 @@ public class PythonClientExperimentalCodegen extends PythonClientCodegen {
/** /**
* Return the default value of the property * Return the default value of the property
*
* @param p OpenAPI property object * @param p OpenAPI property object
* @return string presentation of the default value of the property * @return string presentation of the default value of the property
*/ */