[BUG][java-micronaut-server] Multipart property file is renamed to _file and affect the name
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] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
Description
Because file is reserved word (see AbstractJavaCodegen.java#L180) in AbstractJavaCodegen so it is replaced/escaped with _file. Therefore if you use a property in multipar/form-data with a name file it is generated in java-micronaut-server as a parameter CompletedFileUpload _file and Micronaut it as the multipart name. It does not work if you send a request with the name file and the parameter is always null. If you send the same requests but change the name to _file it works. But it does not match to OpenaAPI.
openapi-generator version
I use the latest version OpenAPI Generator with maven plugin v6.6.0. I also tried master branch.
OpenAPI declaration
I have this request body definition:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
name:
type: string
file:
type: string
format: binary
Generated Code
public void upload(
String name,
CompletedFileUpload _file // always null because wrong name
)
Steps to reproduce
- Create multipart request with a property name
file - Generate code with
java-micronaut-server - Try to call it with the
fileand it fails
Suggest a fix
Add @Part("file") annotation to _file parameter.
@Part("file") CompletedFileUpload _file
Fixed it here: https://github.com/micronaut-projects/micronaut-openapi/pull/1735
Just use official micronaut generator for java and kotlin by micronaut-opeanpi gradle or maven plugin from this repo: https://github.com/micronaut-projects/micronaut-openapi
Look to this guide: https://guides.micronaut.io/latest/micronaut-openapi-generator-server.html
Also, please describe problems and suggestions here: https://github.com/micronaut-projects/micronaut-openapi/issues