Skip to content

Commit 86f57e2

Browse files
author
bnasslahsen
committed
Multiple file upload Flux<FilePart> error on the swagger-ui. Fixes #678
1 parent 46dff5b commit 86f57e2

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.4.1] - 2020-06-XX
8+
### Added
9+
-
10+
### Changed
11+
- Upgrade swagger-ui to 3.26.0
12+
### Fixed
13+
-
14+
715
## [1.4.0] - 2020-05-29
816
### Added
917
- #644 - Support for @RepositoryRestResource
@@ -19,7 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1927
### Changed
2028
- Upgrade swagger-ui to 3.25.4
2129
- Upgrade to spring-boot 2.3.0.RELEASE
22-
2330
### Fixed
2431
- #267 - @RequestAttribute parameter appears in the UI
2532
- #695 - Servers OpenAPI block resets after customizing with GroupedOpenApi

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
7272
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
7373
<swagger-api.version>2.1.2</swagger-api.version>
74-
<swagger-ui.version>3.25.5</swagger-ui.version>
74+
<swagger-ui.version>3.26.0</swagger-ui.version>
7575
<spring-security-oauth2.version>2.3.8.RELEASE</spring-security-oauth2.version>
7676
<classgraph.version>4.8.44</classgraph.version>
7777
</properties>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app78;
20+
21+
import java.io.File;
22+
import java.io.IOException;
23+
import java.nio.file.Path;
24+
import java.nio.file.Paths;
25+
26+
import io.swagger.v3.oas.annotations.Operation;
27+
import io.swagger.v3.oas.annotations.Parameter;
28+
import io.swagger.v3.oas.annotations.media.Content;
29+
import reactor.core.publisher.Flux;
30+
31+
import org.springframework.http.MediaType;
32+
import org.springframework.http.codec.multipart.FilePart;
33+
import org.springframework.web.bind.annotation.PostMapping;
34+
import org.springframework.web.bind.annotation.RequestPart;
35+
import org.springframework.web.bind.annotation.RestController;
36+
37+
@RestController
38+
public class HelloController<T> {
39+
40+
41+
@PostMapping(value = "/files", produces = { MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
42+
@Operation(summary = "files")
43+
public Flux<Void> handleFileUpload(
44+
@RequestPart("files") @Parameter(description = "files",
45+
content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE))
46+
Flux<FilePart> filePartFux) throws IOException {
47+
File tmp = File.createTempFile("tmp", "");
48+
return filePartFux.flatMap(filePart -> {
49+
Path path = Paths.get(tmp.toString() + filePart.filename());
50+
System.out.println(path);
51+
return filePart.transferTo(path);
52+
});
53+
}
54+
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* *
4+
* * *
5+
* * * * Copyright 2019-2020 the original author or authors.
6+
* * * *
7+
* * * * Licensed under the Apache License, Version 2.0 (the "License");
8+
* * * * you may not use this file except in compliance with the License.
9+
* * * * You may obtain a copy of the License at
10+
* * * *
11+
* * * * https://www.apache.org/licenses/LICENSE-2.0
12+
* * * *
13+
* * * * Unless required by applicable law or agreed to in writing, software
14+
* * * * distributed under the License is distributed on an "AS IS" BASIS,
15+
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* * * * See the License for the specific language governing permissions and
17+
* * * * limitations under the License.
18+
* * *
19+
* *
20+
*
21+
*
22+
*/
23+
24+
package test.org.springdoc.api.app78;
25+
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
import org.springframework.boot.autoconfigure.SpringBootApplication;
29+
import org.springframework.context.annotation.ComponentScan;
30+
import org.springframework.test.context.TestPropertySource;
31+
32+
public class SpringDocApp78Test extends AbstractSpringDocTest {
33+
34+
@SpringBootApplication
35+
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app78" })
36+
static class SpringDocTestApp {}
37+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/files": {
15+
"post": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"summary": "files",
20+
"operationId": "handleFileUpload",
21+
"requestBody": {
22+
"content": {
23+
"multipart/form-data": {
24+
"schema": {
25+
"type": "object",
26+
"properties": {
27+
"files": {
28+
"type": "array",
29+
"description": "files",
30+
"items": {
31+
"type": "string",
32+
"format": "binary"
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
},
40+
"responses": {
41+
"200": {
42+
"description": "OK",
43+
"content": {
44+
"application/json": {
45+
"schema": {
46+
"type": "array",
47+
"items": {
48+
"type": "object"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"components": {}
59+
}

0 commit comments

Comments
 (0)