swagger-api / swagger-api/swagger-codegen-generators

[Spring] Support MultiPartFile for file uploads

Open
#183 17 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.