diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 515b34dc1dfc..98a0226afa28 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -35,6 +35,7 @@ import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.api.TemplatingEngineAdapter; import org.openapitools.codegen.ignore.CodegenIgnoreProcessor; +import org.openapitools.codegen.languages.PythonClientExperimentalCodegen; import org.openapitools.codegen.meta.GeneratorMetadata; import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.serializer.SerializerUtils; @@ -492,7 +493,9 @@ private Model getParent(Model model) { Map modelTemplate = (Map) ((List) models.get("models")).get(0); if (modelTemplate != null && modelTemplate.containsKey("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 } } @@ -942,7 +945,6 @@ public String getFullTemplateContents(String templateName) { * 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) - * * @return The {@link Path} to the template */ @Override @@ -1062,21 +1064,21 @@ private void processOperation(String resourcePath, String httpMethod, Operation if (authMethods != null && !authMethods.isEmpty()) { codegenOperation.authMethods = config.fromSecurity(authMethods); List> scopes = new ArrayList>(); - if (codegenOperation.authMethods != null){ - for (CodegenSecurity security : codegenOperation.authMethods){ + if (codegenOperation.authMethods != null) { + for (CodegenSecurity security : codegenOperation.authMethods) { if (security != null && security.isBasicBearer != null && security.isBasicBearer && - securities != null){ - for (SecurityRequirement req : securities){ + securities != null) { + for (SecurityRequirement req : securities) { if (req == null) continue; - for (String key : req.keySet()){ - if (security.name != null && key.equals(security.name)){ + for (String key : req.keySet()) { + if (security.name != null && key.equals(security.name)) { int count = 0; - for (String sc : req.get(key)){ + for (String sc : req.get(key)) { Map scope = new HashMap(); scope.put("scope", sc); scope.put("description", ""); 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"); } else { scope.put("hasMore", null); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index d19b7b83f953..71dd5d61133e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -78,10 +78,7 @@ public void processOpts() { // default this to true so the python ModelSimple models will be generated 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"); } /** @@ -108,6 +105,7 @@ public String dateToString(Schema p, Date date, DateFormat dateFormatter, DateFo /** * Return the default value of the property + * * @param p OpenAPI property object * @return string presentation of the default value of the property */ @@ -194,7 +192,7 @@ public String toDefaultValue(Schema p) { } return defaultValue; } else { - return defaultObject.toString(); + return defaultObject.toString(); } } @@ -387,7 +385,7 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) { } else { if (cp.isEnum == true || cp.hasValidation == true) { // this model has validations and/or enums so we will generate it - Schema sc = ModelUtils.getSchemaFromResponse(response); + Schema sc = ModelUtils.getSchemaFromResponse(response); newBaseType = ModelUtils.getSimpleRef(sc.get$ref()); } } @@ -406,9 +404,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) { /** * Set op's returnBaseType, returnType, examples etc. * - * @param operation endpoint Operation - * @param schemas a map of the schemas in the openapi spec - * @param op endpoint CodegenOperation + * @param operation endpoint Operation + * @param schemas a map of the schemas in the openapi spec + * @param op endpoint CodegenOperation * @param methodResponse the default ApiResponse for the endpoint */ @Override @@ -568,7 +566,7 @@ public CodegenModel fromModel(String name, Schema schema) { // 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 - ArrayList> listOfLists= new ArrayList>(); + ArrayList> listOfLists = new ArrayList>(); listOfLists.add(result.vars); listOfLists.add(result.allVars); listOfLists.add(result.requiredVars);