OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.3k stars 6.44k forks source link

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

Open Saljack opened 1 year ago

Saljack commented 1 year ago

Bug Report Checklist

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
altro3 commented 2 weeks ago

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