OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.86k stars 6.59k forks source link

[BUG] [SPRING-CLOUD] Spring-cloud generator adding @RequestParam instead of @RequestPart for mutilpart/form-data #6713

Open matrixguy opened 4 years ago

matrixguy commented 4 years ago

Bug Report Checklist

Description

Spring-cloud generator(feign client) adding @RequestParam instead of @RequestPart for MultipartFile

openapi-generator version

4.3.0

OpenAPI declaration file content or url
{
  "/endpoint": {
    "put": {
      "tags": [
        "MarksheetController"
      ],
      "operationId": "updateMarksheet",
      "parameters": [
        {
          "name": "studentId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "number"
          }
        },
        {
          "name": "requestId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "requestBody": {
        "content": {
          "multipart/form-data": {
            "schema": {
              "type": "object",
              "properties": {
                "time": {
                  "type": "string"
                },
                "marksheet": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      },
      "responses": {
        "200": {
          "description": "default response",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateMarksheetResponse"
              }
            }
          }
        }
      }
    }
  }
}

Generated Code

ResponseEntity <UpdateMarksheetResponse> updateMarksheet(
    @ApiParam(value ="",required = true) @PathVariable("studentId") BigDecimal accountID, 
    @ApiParam(value = "", required = true) @PathVariable("requestId") String requestId, 
    @ApiParam(value = "") @RequestParam(value = "time", required = false) String time, 
    @ApiParam(value = "") @RequestParam("marksheet") MultipartFile marksheet
);
Command line used for generation

Generated using gradle task.

generatorName = "spring"
library = "spring-cloud"
configOptions = [
        "dateLibrary"              : "java-8",
        "serializationLibrary"     : "jackson",
        "useBeanValidation"        : "false"
]
Suggest a fix

Generate @RequestPart instead of @RequestParam , may require changes in template.

leovante commented 2 years ago

have the same issue in 5.3.0

draperunner commented 2 years ago

Any workarounds?

lvramanan commented 2 years ago

Still have the same issue in the latest plugin 6.2.1. Any suggestions or workarounds for this issue?

ste1n commented 1 year ago

I'm also using version 6.2.1 and ran into the same bug today. The only fix I could find was to replace the annotation after code generation.

I'm now using the suggested workaround using the com.google.code.maven-replacer-plugin to replace the generated @RequestParam annotation with @RequestPart.

drndos commented 1 year ago

Add <templateDirectory>${project.basedir}/src/main/resources/custom</templateDirectory> to your maven config of a openapi generator inside configuration tag. Add custom package inside resources Copy and paste https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/JavaSpring/formParams.mustache inside there Edit RequestParam to RequestPart