[BUG] [SPRING-CLOUD] Spring-cloud generator adding @RequestParam instead of @RequestPart for mutilpart/form-data
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] What's the version of OpenAPI Generator used?
- [x] Have you search for related issues/PRs?
- [x] 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.
have the same issue in 5.3.0
Any workarounds?
Still have the same issue in the latest plugin 6.2.1. Any suggestions or workarounds for this issue?
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.
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
Tested on latest master (7.25.0-SNAPSHOT, built locally), spring + library=spring-cloud, multipart/form-data:
@RequestPart(value = "file", required = false) MultipartFile file,
@RequestParam(value = "note", required = false) String note
Looks fixed to me, I think this can be closed.