Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
vvalchev opened this issue Apr 27, 2020 · 0 comments · Fixed by #6073
Closed
5 of 6 tasks

Comments

@vvalchev
Copy link
Contributor

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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant