Skip to content

Commit 6ded07d

Browse files
author
bnasslahsen
committed
Make default type of Resource as binary. Fixes #322.
1 parent 4a03070 commit 6ded07d

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/GenericParameterBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.springframework.core.MethodParameter;
4848
import org.springframework.core.ResolvableType;
4949
import org.springframework.core.annotation.AnnotationUtils;
50+
import org.springframework.core.io.Resource;
5051
import org.springframework.web.multipart.MultipartFile;
5152

5253
@SuppressWarnings("rawtypes")
@@ -58,6 +59,7 @@ public class GenericParameterBuilder {
5859

5960
static {
6061
FILE_TYPES.add(MultipartFile.class);
62+
FILE_TYPES.add(Resource.class);
6163
ANNOTATIOSN_TO_IGNORE.add(Hidden.class);
6264
}
6365

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package test.org.springdoc.api.app109;
2+
3+
import io.swagger.v3.oas.annotations.media.Content;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
6+
7+
import org.springframework.core.io.ByteArrayResource;
8+
import org.springframework.core.io.Resource;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
public class HelloController {
14+
15+
@GetMapping("/api/v1/resource")
16+
public Resource getResource() {
17+
return new ByteArrayResource(new byte[]{});
18+
}
19+
20+
@GetMapping("/api/v1/bytearray")
21+
@ApiResponse(content = @Content(schema = @Schema(type = "string", format = "binary")))
22+
public byte[] getByteArray() {
23+
return new byte[]{};
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test.org.springdoc.api.app109;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
public class SpringDocApp109Test extends AbstractSpringDocTest {
8+
@SpringBootApplication
9+
static class SpringDocTestApp {}
10+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {
14+
"/api/v1/resource": {
15+
"get": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"operationId": "getResource",
20+
"responses": {
21+
"200": {
22+
"description": "default response",
23+
"content": {
24+
"*/*": {
25+
"schema": {
26+
"type": "string",
27+
"format": "binary"
28+
}
29+
}
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"/api/v1/bytearray": {
36+
"get": {
37+
"tags": [
38+
"hello-controller"
39+
],
40+
"operationId": "getByteArray",
41+
"responses": {
42+
"default": {
43+
"description": "default response",
44+
"content": {
45+
"*/*": {
46+
"schema": {
47+
"type": "string",
48+
"format": "binary"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
},
57+
"components": {}
58+
}

0 commit comments

Comments
 (0)