mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-06 15:40:54 +00:00
fix generateAliasAsModels in default generator (#3951)
This commit is contained in:
parent
e20af77944
commit
bd992a4218
@ -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
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user