Skip to content

Commit fb82831

Browse files
committed
Add SwaggerBeanConfiguration to support application/octet-stream in Swagger UI
1 parent e66d109 commit fb82831

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Cosmo Tech.
2+
// Licensed under the MIT license.
3+
package com.cosmotech.api.config
4+
5+
import org.springframework.context.annotation.Configuration
6+
import org.springframework.http.MediaType
7+
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
8+
9+
/**
10+
* This class is here as a suggested workaround for the following issues. Swagger UI does not handle
11+
* multipart requests correctly even if `encoding` property is set in openapi.yaml Each part of a
12+
* multipart/form-data is sent with a content-type set to application/octet-stream The following
13+
* workaround adds application/octet-stream has a supported MediaType for the
14+
* MappingJackson2HttpMessageConverter https://github.com/swagger-api/swagger-ui/issues/6462
15+
* https://github.com/swagger-api/swagger-ui/issues/5356
16+
* https://github.com/swagger-api/swagger-ui/issues/9548
17+
* https://github.com/swagger-api/swagger-ui/issues/6462
18+
* https://github.com/swagger-api/swagger-ui/issues/9548
19+
*/
20+
@Configuration
21+
open class SwaggerBeanConfiguration(converter: MappingJackson2HttpMessageConverter) {
22+
23+
init {
24+
val supportedMediaTypes = ArrayList<MediaType?>(converter.supportedMediaTypes)
25+
supportedMediaTypes.add(MediaType("application", "octet-stream"))
26+
converter.supportedMediaTypes = supportedMediaTypes
27+
}
28+
}

0 commit comments

Comments
 (0)