OpenAPITools / OpenAPITools/openapi-generator
[BUG][java-micronaut-server] Multipart property file is renamed to _file and affect the name
Nobody has claimed this yet.
- 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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the java-micronaut-server generation entry point and the reserved-word handling described in AbstractJavaCodegen.java#L180. Reproduce the multipart request using the provided YAML, then verify that the generated parameter preserves the OpenAPI property name through its Micronaut annotation and accepts a request using file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100