Skip to content

Commit d858ba3

Browse files
author
springdoc
committed
fixes #212: Missing Response Content
1 parent 3f1a793 commit d858ba3

File tree

6 files changed

+130
-15
lines changed

6 files changed

+130
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,35 @@ public String[] getMethodConsumes() {
5252

5353

5454
public void calculateConsumesProduces(Method method) {
55-
PostMapping reqPostMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, PostMapping.class);
56-
if (reqPostMappringMethod != null) {
57-
fillMethods(reqPostMappringMethod.produces(), reqPostMappringMethod.consumes());
55+
PostMapping reqPostMappingMethod = AnnotatedElementUtils.findMergedAnnotation(method, PostMapping.class);
56+
if (reqPostMappingMethod != null) {
57+
fillMethods(reqPostMappingMethod.produces(), reqPostMappingMethod.consumes());
5858
return;
5959
}
60-
GetMapping reqGetMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
61-
if (reqGetMappringMethod != null) {
62-
fillMethods(reqGetMappringMethod.produces(), reqGetMappringMethod.consumes());
60+
GetMapping reqGetMappingMethod = AnnotatedElementUtils.findMergedAnnotation(method, GetMapping.class);
61+
if (reqGetMappingMethod != null) {
62+
fillMethods(reqGetMappingMethod.produces(), reqGetMappingMethod.consumes());
6363
return;
6464
}
65-
DeleteMapping reqDeleteMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, DeleteMapping.class);
66-
if (reqDeleteMappringMethod != null) {
67-
fillMethods(reqDeleteMappringMethod.produces(), reqDeleteMappringMethod.consumes());
65+
DeleteMapping reqDeleteMappingMethod = AnnotatedElementUtils.findMergedAnnotation(method, DeleteMapping.class);
66+
if (reqDeleteMappingMethod != null) {
67+
fillMethods(reqDeleteMappingMethod.produces(), reqDeleteMappingMethod.consumes());
6868
return;
6969
}
70-
PutMapping reqPutMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, PutMapping.class);
71-
if (reqPutMappringMethod != null) {
72-
fillMethods(reqPutMappringMethod.produces(), reqPutMappringMethod.consumes());
70+
PutMapping reqPutMappingMethod = AnnotatedElementUtils.findMergedAnnotation(method, PutMapping.class);
71+
if (reqPutMappingMethod != null) {
72+
fillMethods(reqPutMappingMethod.produces(), reqPutMappingMethod.consumes());
7373
return;
7474
}
75-
RequestMapping reqMappringMethod = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
76-
if (reqMappringMethod != null) {
77-
fillMethods(reqMappringMethod.produces(), reqMappringMethod.consumes());
75+
RequestMapping reqMappingMethod = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
76+
RequestMapping reqMappingClass = AnnotatedElementUtils.findMergedAnnotation(method.getDeclaringClass(), RequestMapping.class);
77+
78+
if (reqMappingMethod != null && reqMappingClass != null) {
79+
fillMethods(ArrayUtils.addAll(reqMappingMethod.produces(), reqMappingClass.produces()), ArrayUtils.addAll(reqMappingMethod.consumes(), reqMappingClass.consumes()));
80+
} else if (reqMappingMethod != null) {
81+
fillMethods(reqMappingMethod.produces(), reqMappingMethod.consumes());
82+
} else if (reqMappingClass != null) {
83+
fillMethods(reqMappingClass.produces(), reqMappingClass.consumes());
7884
}
7985
}
8086

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package test.org.springdoc.api.app62;
2+
3+
import org.springframework.core.annotation.AliasFor;
4+
import org.springframework.http.MediaType;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
@Target({ElementType.METHOD, ElementType.TYPE})
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@RestController
16+
@RequestMapping
17+
public @interface BaseController {
18+
@AliasFor(annotation = RequestMapping.class)
19+
String[] value() default {};
20+
21+
@AliasFor(annotation = RequestMapping.class)
22+
String[] produces() default {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE};
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test.org.springdoc.api.app62;
2+
3+
import test.org.springdoc.api.AbstractSpringDocTest;
4+
5+
public class SpringDocApp62Test extends AbstractSpringDocTest {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package test.org.springdoc.api.app62;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class SpringDocTestApp {
8+
public static void main(String[] args) {
9+
SpringApplication.run(SpringDocTestApp.class, args);
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package test.org.springdoc.api.app62;
2+
3+
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.tags.Tag;
5+
import org.springframework.web.bind.annotation.RequestHeader;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
9+
@BaseController
10+
@Tag(name = "Test Controller")
11+
public class TestController {
12+
13+
@RequestMapping(value = "/test", method = RequestMethod.GET)
14+
@Operation(summary = "This is the test endpoint")
15+
public String test(@RequestHeader("Accept") String accept) {
16+
return "This is a test";
17+
}
18+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
"/test": {
15+
"get": {
16+
"tags": [
17+
"Test Controller"
18+
],
19+
"summary": "This is the test endpoint",
20+
"operationId": "test",
21+
"parameters": [
22+
{
23+
"name": "Accept",
24+
"in": "header",
25+
"required": true,
26+
"schema": {
27+
"type": "string"
28+
}
29+
}
30+
],
31+
"responses": {
32+
"200": {
33+
"description": "default response",
34+
"content": {
35+
"application/xml": {
36+
"schema": {
37+
"type": "string"
38+
}
39+
},
40+
"application/json": {
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
},
51+
"components": {}
52+
}

0 commit comments

Comments
 (0)