-
Notifications
You must be signed in to change notification settings - Fork 421
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
[Spring] Support MultiPartFile for file uploads #183
Comments
@jglynn I submitted a pull request (actually 2 different ways of solving this) that should fix this issue. |
I also used a work around. With the swagger-codegen-maven-plugin
|
@mistriel could you elaborate how you made it work, including your yaml schema example? Because this typemapping does nothing on our side. |
@shathor this is the relevant part from my YAML : /media/upload:
post:
tags:
- media
summary: Upload media file to storage
operationId: uploadFile
produces:
- application/json
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
required: true
file:
type: multipartFile
required: true
classification:
required: true
$ref: '#/components/schemas/MediaClassification'
visibility:
required: true
$ref: '#/components/schemas/Visibility' Note that i also downloaded the entire templates and used them as part of the maven build : <properties>
<checkstyle.skip>true</checkstyle.skip><!-- set to true since code is generated -->
<findbugs.skip>true</findbugs.skip><!-- set to true since code is generated -->
<swagger.resources>${project.basedir}/src/main/resources/swagger/</swagger.resources>
</properties>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<id>generate swagger</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${swagger.resources}/app-server-api.yaml</inputSpec>
<language>spring</language>
<templateDirectory>${swagger.resources}/templates/</templateDirectory>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>
<typeMappings>
<typeMapping>multipartFile=org.springframework.web.multipart.MultipartFile</typeMapping>
</typeMappings>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
<modelPackage>xxx.xxx.xxx.payload</modelPackage>
<apiPackage>xxx.xxx.xxx.api</apiPackage>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
<interfaceOnly>true</interfaceOnly>
<library>spring-mvc</library>
<delegatePattern>false</delegatePattern>
<useTags>true</useTags>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
And mainly customized the api.mustache file
|
I see, thanks a lot. I was hoping to get by without modifying the templates. |
Sorry, the rest of it is protected by our IP, yet this should do the work for you. |
I got another workaround. In the maven build add: <typeMappings>
<typeMapping>File=org.springframework.core.io.InputStreamSource</typeMapping>
</typeMappings> The YAML part: requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
myOtherProperty:
$ref: '#/components/schemas/MyType'
type: string
required:
- file
- myOtherProperty |
PR #184 got merged a few days ago so this should be fixed in the next release |
Using version 3.0.19 I still have to use the workarround
to have a MutlipartFile when I want an array of file in the requestBody.
|
Seems the problem is still present. |
|
|
The problem is still here |
Somewhat similar to #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:
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.
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.
The text was updated successfully, but these errors were encountered: