Skip to content

Commit

Permalink
Multiple file upload Flux<FilePart> error on the swagger-ui. Fixes #678
Browse files Browse the repository at this point in the history
  • Loading branch information
bnasslahsen committed Jun 7, 2020
1 parent 46dff5b commit 86f57e2
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.1] - 2020-06-XX
### Added
-
### Changed
- Upgrade swagger-ui to 3.26.0
### Fixed
-

## [1.4.0] - 2020-05-29
### Added
- #644 - Support for @RepositoryRestResource
Expand All @@ -19,7 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Upgrade swagger-ui to 3.25.4
- Upgrade to spring-boot 2.3.0.RELEASE

### Fixed
- #267 - @RequestAttribute parameter appears in the UI
- #695 - Servers OpenAPI block resets after customizing with GroupedOpenApi
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<nexus-staging-maven-plugin>1.6.8</nexus-staging-maven-plugin>
<swagger-api.version>2.1.2</swagger-api.version>
<swagger-ui.version>3.25.5</swagger-ui.version>
<swagger-ui.version>3.26.0</swagger-ui.version>
<spring-security-oauth2.version>2.3.8.RELEASE</spring-security-oauth2.version>
<classgraph.version>4.8.44</classgraph.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
*
* * Copyright 2019-2020 the original author or authors.
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * https://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
*
*/

package test.org.springdoc.api.app78;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import reactor.core.publisher.Flux;

import org.springframework.http.MediaType;
import org.springframework.http.codec.multipart.FilePart;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController<T> {


@PostMapping(value = "/files", produces = { MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
@Operation(summary = "files")
public Flux<Void> handleFileUpload(
@RequestPart("files") @Parameter(description = "files",
content = @Content(mediaType = MediaType.APPLICATION_OCTET_STREAM_VALUE))
Flux<FilePart> filePartFux) throws IOException {
File tmp = File.createTempFile("tmp", "");
return filePartFux.flatMap(filePart -> {
Path path = Paths.get(tmp.toString() + filePart.filename());
System.out.println(path);
return filePart.transferTo(path);
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* *
* * *
* * * * Copyright 2019-2020 the original author or authors.
* * * *
* * * * Licensed under the Apache License, Version 2.0 (the "License");
* * * * you may not use this file except in compliance with the License.
* * * * You may obtain a copy of the License at
* * * *
* * * * https://www.apache.org/licenses/LICENSE-2.0
* * * *
* * * * Unless required by applicable law or agreed to in writing, software
* * * * distributed under the License is distributed on an "AS IS" BASIS,
* * * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * * * See the License for the specific language governing permissions and
* * * * limitations under the License.
* * *
* *
*
*
*/

package test.org.springdoc.api.app78;

import test.org.springdoc.api.AbstractSpringDocTest;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;

public class SpringDocApp78Test extends AbstractSpringDocTest {

@SpringBootApplication
@ComponentScan(basePackages = { "org.springdoc", "test.org.springdoc.api.app78" })
static class SpringDocTestApp {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "",
"description": "Generated server url"
}
],
"paths": {
"/files": {
"post": {
"tags": [
"hello-controller"
],
"summary": "files",
"operationId": "handleFileUpload",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"files": {
"type": "array",
"description": "files",
"items": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object"
}
}
}
}
}
}
}
}
},
"components": {}
}

0 comments on commit 86f57e2

Please sign in to comment.