Skip to content

[kotlin-spring] Handle arrays of files correctly using MultipartFile#20108

Merged
wing328 merged 7 commits into
OpenAPITools:masterfrom
ffffionn:bugfix/kotlin-spring-multipartfile-array
Dec 4, 2024
Merged

[kotlin-spring] Handle arrays of files correctly using MultipartFile#20108
wing328 merged 7 commits into
OpenAPITools:masterfrom
ffffionn:bugfix/kotlin-spring-multipartfile-array

Conversation

@ffffionn

Copy link
Copy Markdown
Contributor

This handles request parameters of arrays of files correctly, as well as changing them to use Spring's Multipart File class, as is recommended. Previously, Spring's Resource would be used as the input and the Delegate class would not recognize the array

Fixes the following open issues for Kotlin-spring generator:
#8333
#15251

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@ffffionn

ffffionn commented Nov 15, 2024

Copy link
Copy Markdown
Contributor Author

I'm not sure that I did the samples properly, as they seem to have switched to Windows path separators instead.
I used Git Bash on Windows

@wing328

wing328 commented Nov 16, 2024

Copy link
Copy Markdown
Member

thanks for the PR. i've filed #20117 with updated samples.

is it correct to say that this is a breaking change as org.springframework.web.multipart.MultipartFile is used instead?

@ffffionn

Copy link
Copy Markdown
Contributor Author

@wing328 Yeah, I guess you could consider it that. All Spring documentation says to be using MultipartFile for uploads (but we still keep Resource for downloads)

@wing328

wing328 commented Nov 16, 2024

Copy link
Copy Markdown
Member

can you please review the build failure when you've time?

https://github.com/OpenAPITools/openapi-generator/actions/runs/11868985076/job/33078813658?pr=20117

@wing328

wing328 commented Nov 16, 2024

Copy link
Copy Markdown
Member

@wing328 Yeah, I guess you could consider it that. All Spring documentation says to be using MultipartFile for uploads (but we still keep Resource for downloads)

ok. i'll see if i can come up with a way to fallback in case the users prefer the current implementation.

@ffffionn

Copy link
Copy Markdown
Contributor Author

can you please review the build failure when you've time?

https://github.com/OpenAPITools/openapi-generator/actions/runs/11868985076/job/33078813658?pr=20117

Sorry, I'm a bit of a noob on Github Actions. Maven build passes successfully when run, is there a way to run these tests locally? (should they be included in mvn test?)

@wing328

wing328 commented Nov 16, 2024

Copy link
Copy Markdown
Member

can you run ./gradlew build -x test in samples/server/petstore/kotlin-springboot-source-swagger1 for example?

@ffffionn

ffffionn commented Nov 16, 2024

Copy link
Copy Markdown
Contributor Author

There isn't any gradle wrapper in that directory

EDIT: Ah I got it to run locally after some playing around. Let me fix these issues..
(This would be ideally solved with being able to set the typeMapping for file differently on input parameters vs response type - but in the absence of this, the solution to hard-code the MultipartFile type will do)

@ffffionn

Copy link
Copy Markdown
Contributor Author

@wing328 I made some changes but there doesn't seem to be a good way to verify all the samples compile. I feel like this should be part of the maven build

@wing328

wing328 commented Nov 20, 2024

Copy link
Copy Markdown
Member

fyi. updated samples via 2c25491

@wing328

wing328 commented Nov 20, 2024

Copy link
Copy Markdown
Member

agreed with you that we should also test the kotlin spring project with maven as well

@wing328 wing328 added this to the 7.11.0 milestone Nov 20, 2024
@wing328

wing328 commented Nov 20, 2024

Copy link
Copy Markdown
Member

cc @dr4ke616 (2018/08) @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10)

@wing328
wing328 merged commit e131d52 into OpenAPITools:master Dec 4, 2024
@ffffionn
ffffionn deleted the bugfix/kotlin-spring-multipartfile-array branch December 5, 2024 11:20
@robert-engel

Copy link
Copy Markdown

Is it correct that this change makes it impossible to generate a controller for non multipart fileuploads? MultipartFile is null if I just POST arbitrary bytes with a non multipart content-type to my endpoint.

@dhirajbadu

Copy link
Copy Markdown

Is it possible to apply this patch on 7.0.1?

vfouqueron pushed a commit to predell/openapi-generator that referenced this pull request Apr 8, 2026
…penAPITools#20108)

* [kotlin-spring] Fix no List being used for an array of files using multipart/form-data

* [kotlin-spring] Use Spring's MultipartFile class for incoming Files instead of Spring's Resource class.

* [kotlin-spring] Add test to ensure that return type for files is `org.springframework.core.io.Resource`

* [kotlin-spring] Ensure Array is used for lists of files in generated Api class

* Update samples

* [kotlin-spring] Move conditional usage of MultipartFile to optionalDataType.mustache. Update samples

* update samples

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants