swagger-api / swagger-api/swagger-codegen-generators
[Spring] Support MultiPartFile for file uploads
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Somewhat similar to https://github.com/swagger-api/swagger-codegen-generators/issues/150 but for Spring specifically.
When using the Spring profile and a multipart service definition, I would expect to be able to influence the generated api Controller stub to use Spring's org.springframework.web.multipart.MultiPartFile.
The options I've tried and result:
- type: string, format: binary maps to a byte[]
- type: file, format: binary maps to a
org.springframework.core.io.Resource(I would expect this to use MultiPartFile instead)
As an alternative, I extended the SpringCodegen and registered my own typeMapping.
typeMapping.put{"multiPartFile","MultiPartFile");
importMapping.put("MultiPartFile", "org.springframework.web.multipart.MultiPartFile");
With this I was able to get a controller stub generated using the MultiPartFile and support uploads. I'm pretty new to this product so I'm not sure if this is a best practice or not.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SpringCodegen extension and the typeMapping and importMapping examples in the issue; trace how multipart definitions become generated Spring controller parameter types. Check the existing Spring generator behavior and related generator tests, if present. Done means a Spring multipart definition can generate a controller stub using MultiPartFile with its correct import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100