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
|
||||||
@ -1062,21 +1064,21 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
|||||||
if (authMethods != null && !authMethods.isEmpty()) {
|
if (authMethods != null && !authMethods.isEmpty()) {
|
||||||
codegenOperation.authMethods = config.fromSecurity(authMethods);
|
codegenOperation.authMethods = config.fromSecurity(authMethods);
|
||||||
List<Map<String, Object>> scopes = new ArrayList<Map<String, Object>>();
|
List<Map<String, Object>> scopes = new ArrayList<Map<String, Object>>();
|
||||||
if (codegenOperation.authMethods != null){
|
if (codegenOperation.authMethods != null) {
|
||||||
for (CodegenSecurity security : codegenOperation.authMethods){
|
for (CodegenSecurity security : codegenOperation.authMethods) {
|
||||||
if (security != null && security.isBasicBearer != null && security.isBasicBearer &&
|
if (security != null && security.isBasicBearer != null && security.isBasicBearer &&
|
||||||
securities != null){
|
securities != null) {
|
||||||
for (SecurityRequirement req : securities){
|
for (SecurityRequirement req : securities) {
|
||||||
if (req == null) continue;
|
if (req == null) continue;
|
||||||
for (String key : req.keySet()){
|
for (String key : req.keySet()) {
|
||||||
if (security.name != null && key.equals(security.name)){
|
if (security.name != null && key.equals(security.name)) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (String sc : req.get(key)){
|
for (String sc : req.get(key)) {
|
||||||
Map<String, Object> scope = new HashMap<String, Object>();
|
Map<String, Object> scope = new HashMap<String, Object>();
|
||||||
scope.put("scope", sc);
|
scope.put("scope", sc);
|
||||||
scope.put("description", "");
|
scope.put("description", "");
|
||||||
count++;
|
count++;
|
||||||
if (req.get(key) != null && count < req.get(key).size()){
|
if (req.get(key) != null && count < req.get(key).size()) {
|
||||||
scope.put("hasMore", "true");
|
scope.put("hasMore", "true");
|
||||||
} else {
|
} else {
|
||||||
scope.put("hasMore", null);
|
scope.put("hasMore", null);
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
@ -568,7 +566,7 @@ public class PythonClientExperimentalCodegen extends PythonClientCodegen {
|
|||||||
|
|
||||||
// fix all property references to non-object models, make those properties non-primitive and
|
// fix all property references to non-object models, make those properties non-primitive and
|
||||||
// set their dataType and complexType to the model name, so documentation will refer to the correct model
|
// set their dataType and complexType to the model name, so documentation will refer to the correct model
|
||||||
ArrayList<List<CodegenProperty>> listOfLists= new ArrayList<List<CodegenProperty>>();
|
ArrayList<List<CodegenProperty>> listOfLists = new ArrayList<List<CodegenProperty>>();
|
||||||
listOfLists.add(result.vars);
|
listOfLists.add(result.vars);
|
||||||
listOfLists.add(result.allVars);
|
listOfLists.add(result.allVars);
|
||||||
listOfLists.add(result.requiredVars);
|
listOfLists.add(result.requiredVars);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user