Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA][SERVER] In release 6.2.1, spring server generator creates wrong annotation on method parameter for multipart request #14295

Closed
raverone opened this issue Dec 20, 2022 · 7 comments

Comments

@raverone
Copy link

Description

Spring server genertor creates wrong annotation on method parameter for multipart request.
The request have 2 parameters:

  • SomeObject param1
  • MultipartFile param2

In version 5.4.0 both parameters would be annotated with @RequestPart. Which is correct.

But starting from version 6.0.0 (until the 6.2.1 at least) param1 would be annotated with @RequestParam and param2 with @RequestPart.
In this case, if you make a call to such endpoint, Spring won't be able to convert the request parameters and will throw

org.springframework.web.method.annotation.MethodArgumentConversionNotSupportedException:
Failed to convert value of type 'java.lang.String' to required type 'org.example.http.model.SomeObject';
...
no matching editors or conversion strategy found
openapi-generator version

6.2.1

OpenAPI declaration file content or url

Gist

Generation Details

Generation is done with the gradle plugin by executing ./gradlew :openApiGenerate

Steps to reproduce

I created a minimal project on github
Steps to reproduce the bug:

  • clone the repo
  • cd into the repo directory
  • execute ./gradlew :openApiGenerate
  • examine file build/generated/src/main/java/org/example/bug/http/api/TestApiApi.java
    • Expected generated code
default ResponseEntity<SomeResponse> uploadFileAndJson(
        @RequestPart(value = "someObject", required = true) SomeObject someObject,
        @RequestPart(value = "image", required = true) MultipartFile image
    )
    • Actual generated code
default ResponseEntity<SomeResponse> uploadFileAndJson(
        @RequestParam(value = "someObject", required = true) SomeObject someObject,
        @RequestPart(value = "image", required = true) MultipartFile image
    )
  • you can also execute tests with ./gradlew -i :test. It should pass, but currently it isn't.
@raverone raverone changed the title [BUG][JAVA][SERVER] In release 6.2.1, spring server genertor creates wrong annotation on method parameter for multipart request [BUG][JAVA][SERVER] In release 6.2.1, spring server generator creates wrong annotation on method parameter for multipart request Dec 22, 2022
@borsch
Copy link
Member

borsch commented Jan 2, 2023

Issue was introduced here #11449 and released as part of 6.0.0. I'll pick this one

@borsch
Copy link
Member

borsch commented Jan 5, 2023

@raverone latest 6.3.0-spanshot should contains this fix. Could you try it?

@raverone
Copy link
Author

raverone commented Jan 6, 2023

Thanks @borsch !
With openapi-generator-cli-6.3.0-20230106.034606-64.jar generated code works.
I'm closing then this ticket.
Waiting for the 6.3.0 release 🚀

@ssternal
Copy link

Using @RequestParam and @RequestPart on traditional servlet stack should be fine. If I'm not mistaken, for a reactive stack I guess all parameters of a multipart request should have the @RequestPart annotation instead. This is due to the @RequestParam annotation on reactive stack only maps to request parameters, but neither to form data, nor parts of multipart requests. This leads to a specification that states you should send parameters as part of your form, but the actual implementation requires you to send simple objects as request parameters. Can anyone confirm this?

@jorgerod
Copy link
Contributor

jorgerod commented Sep 8, 2023

Using @RequestParam and @RequestPart on traditional servlet stack should be fine. If I'm not mistaken, for a reactive stack I guess all parameters of a multipart request should have the @RequestPart annotation instead. This is due to the @RequestParam annotation on reactive stack only maps to request parameters, but neither to form data, nor parts of multipart requests. This leads to a specification that states you should send parameters as part of your form, but the actual implementation requires you to send simple objects as request parameters. Can anyone confirm this?

Your comment is correct. There is a bug for the reactive stack.
This bug was introduced in this PR.

@wing328 @cachescrubber @borsch If you like, I can make a PR so that in the case of reactive the parameter is created as @RequestPart instead of @RequestParam

@wing328
Copy link
Member

wing328 commented Sep 8, 2023

@jorgerod yes please file a PR to start with and we'll review accordingly.

@jorgerod
Copy link
Contributor

jorgerod commented Sep 8, 2023

@jorgerod yes please file a PR to start with and we'll review accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants