Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6070
Closed
Open
Issue created Apr 27, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][All Languages] Multi-Part content type in response ignores properties of composed schema (allOf/oneOf)

Created by: vvalchev

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

To define multipart content you typically do something like that:

   requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/ChangePasswordRequest'

However, if the schema is composed (using allOf) the inherited properties are ignored.

In the provided case, it generates a method without ANY parameters:

    void changeCurrentUserPassword();
openapi-generator version

4.3.0

OpenAPI declaration file content or url

https://gist.github.com/vvalchev/54a935c0f93c06a184a9eeb1640f96e6#file-api-yml

Command line used for generation

I'm using the following maven pom.xml file to generate the sources: https://gist.github.com/vvalchev/54a935c0f93c06a184a9eeb1640f96e6#file-pom-xml

Steps to reproduce
  1. save pom.xml and api.yml
  2. run mvn compile
  3. check the generated sources
Related issues/PRs
Suggest a fix

The fix would be to handle correctly if the schema is composed. I've tried a simple patch:

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
index 82cebbf022..17edf00ddb 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
@@ -5517,8 +5517,11 @@ public class DefaultCodegen implements CodegenConfig {
         LOGGER.debug("debugging fromRequestBodyToFormParameters= " + body);
         Schema schema = ModelUtils.getSchemaFromRequestBody(body);
         schema = ModelUtils.getReferencedSchema(this.openAPI, schema);
-        if (schema.getProperties() != null && !schema.getProperties().isEmpty()) {
-            Map<String, Schema> properties = schema.getProperties();
+        List<String> allRequired = new ArrayList<String>();
+        Map<String, Schema> properties = new LinkedHashMap<>();
+        addProperties(properties, allRequired, schema);
+
+        if (!properties.isEmpty()) {
             for (Map.Entry<String, Schema> entry : properties.entrySet()) {
                 CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
                 // key => property name

After the patch, the generated code looks right:

// new code - after the patch has been applied
    void changeCurrentUserPassword(@FormParam(value = "password")  String password,@FormParam(value = "passwordConfirmation")  String passwordConfirmation,@FormParam(value = "oldPassword")  String oldPassword);

// old code
    void changeCurrentUserPassword();
Assignee
Assign to
Time tracking