openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open Saljack opened this issue 2 years ago • 1 comments

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

Saljack avatar Jun 02 '23 05:06 Saljack

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

altro3 avatar Aug 27 '24 09:08 altro3