Skip to content

Commit ef918f0

Browse files
authored
Merge pull request #503 from joaodias14/feature/502-ignore-subtypes
#502 - Also ignore subtypes of configured classes to be ignored on Controllers
2 parents 46c0e38 + 39c4c9e commit ef918f0

File tree

4 files changed

+132
-4
lines changed

4 files changed

+132
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected boolean isParamToIgnore(MethodParameter parameter) {
257257
return true;
258258
if (parameter.getParameterAnnotation(PathVariable.class) != null || parameter.getParameterAnnotation(RequestParam.class) != null)
259259
return false;
260-
return PARAM_TYPES_TO_IGNORE.contains(parameter.getParameterType());
260+
return PARAM_TYPES_TO_IGNORE.stream().anyMatch(paramToIgnore -> paramToIgnore.isAssignableFrom(parameter.getParameterType()));
261261
}
262262

263263
private void setParams(Operation operation, List<Parameter> operationParameters, RequestBodyInfo requestBodyInfo) {

springdoc-openapi-security/src/test/java/test/org/springdoc/api/app2/HelloController.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,31 @@
1818

1919
package test.org.springdoc.api.app2;
2020

21+
import org.springframework.security.core.Authentication;
2122
import org.springframework.web.bind.annotation.GetMapping;
2223
import org.springframework.web.bind.annotation.RequestBody;
2324
import org.springframework.web.bind.annotation.RestController;
2425

2526
@RestController
2627
public class HelloController {
2728

29+
@GetMapping("oneParameterAndAuthentication")
30+
public Object oneParameterAndAuthentication(@RequestBody String req, Authentication authentication) {
31+
return null;
32+
}
2833

29-
@GetMapping
30-
public Object doPost(@RequestBody String req, org.springframework.security.core.Authentication auth) {
34+
@GetMapping("noParametersAndAuthentication")
35+
public Object noParametersAndAuthentication(Authentication authentication) {
3136
return null;
3237
}
3338

39+
@GetMapping("oneParameterAndUser")
40+
public Object oneParameterAndUser(@RequestBody String req, User user) {
41+
return null;
42+
}
43+
44+
@GetMapping("noParametersAndUser")
45+
public Object noParametersAndUser(User user) {
46+
return null;
47+
}
3448
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package test.org.springdoc.api.app2;
2+
3+
import org.springframework.security.core.Authentication;
4+
import org.springframework.security.core.GrantedAuthority;
5+
6+
import java.util.Collection;
7+
8+
public class User implements Authentication {
9+
@Override
10+
public Collection<? extends GrantedAuthority> getAuthorities() {
11+
return null;
12+
}
13+
14+
@Override
15+
public Object getCredentials() {
16+
return null;
17+
}
18+
19+
@Override
20+
public Object getDetails() {
21+
return null;
22+
}
23+
24+
@Override
25+
public Object getPrincipal() {
26+
return null;
27+
}
28+
29+
@Override
30+
public boolean isAuthenticated() {
31+
return false;
32+
}
33+
34+
@Override
35+
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
36+
37+
}
38+
39+
@Override
40+
public String getName() {
41+
return null;
42+
}
43+
}

springdoc-openapi-security/src/test/resources/results/app2.json

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
}
1616
],
1717
"paths": {
18-
"/": {
18+
"/oneParameterAndAuthentication": {
1919
"get": {
2020
"tags": [
2121
"hello-controller"
2222
],
2323
"operationId": "doPost",
24+
"operationId": "oneParameterAndAuthentication",
2425
"parameters": [
2526
{
2627
"name": "req",
@@ -44,6 +45,76 @@
4445
}
4546
}
4647
}
48+
},
49+
"/noParametersAndAuthentication": {
50+
"get": {
51+
"tags": [
52+
"hello-controller"
53+
],
54+
"operationId": "noParametersAndAuthentication",
55+
"responses": {
56+
"200": {
57+
"description": "default response",
58+
"content": {
59+
"*/*": {
60+
"schema": {
61+
"type": "object"
62+
}
63+
}
64+
}
65+
}
66+
}
67+
}
68+
},
69+
"/oneParameterAndUser": {
70+
"get": {
71+
"tags": [
72+
"hello-controller"
73+
],
74+
"operationId": "oneParameterAndUser",
75+
"parameters": [
76+
{
77+
"name": "req",
78+
"in": "query",
79+
"required": true,
80+
"schema": {
81+
"type": "string"
82+
}
83+
}
84+
],
85+
"responses": {
86+
"200": {
87+
"description": "default response",
88+
"content": {
89+
"*/*": {
90+
"schema": {
91+
"type": "object"
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}
98+
},
99+
"/noParametersAndUser": {
100+
"get": {
101+
"tags": [
102+
"hello-controller"
103+
],
104+
"operationId": "noParametersAndUser",
105+
"responses": {
106+
"200": {
107+
"description": "default response",
108+
"content": {
109+
"*/*": {
110+
"schema": {
111+
"type": "object"
112+
}
113+
}
114+
}
115+
}
116+
}
117+
}
47118
}
48119
},
49120
"components": {}

0 commit comments

Comments
 (0)