OpenAPITools / OpenAPITools/openapi-generator

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

Open
#6,713 6 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the spring generator's spring-cloud library and compare the generated updateMarksheet method with the supplied multipart/form-data declaration and output. Trace the template or generation entry point responsible for MultipartFile parameters, then verify that multipart fields use @RequestPart rather than @RequestParam.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
63/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.