OpenAPITools / OpenAPITools/openapi-generator

[BUG][java-micronaut-server] Multipart property file is renamed to _file and affect the name

Open
#15,726 1 comment 0 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)?
  • 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
  1. Create multipart request with a property name file
  2. Generate code with java-micronaut-server
  3. Try to call it with the file and it fails
Suggest a fix

Add @Part("file") annotation to _file parameter.

@Part("file") CompletedFileUpload _file

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.