Skip to content

Commit e61b1fe

Browse files
author
michal
committed
Ignoring annotation should support meta-annotations
If @A is ignored and @b is meta-annotation containing @A, then @b should be also ignored
1 parent a3553d3 commit e61b1fe

File tree

6 files changed

+167
-1
lines changed

6 files changed

+167
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static void mergeSchema(Content existingContent, Schema<?> schemaN, Strin
233233
@SuppressWarnings("unchecked")
234234
public static boolean isAnnotationToIgnore(MethodParameter parameter) {
235235
return ANNOTATIONS_TO_IGNORE.stream().anyMatch(
236-
annotation -> parameter.getParameterAnnotation(annotation) != null
236+
annotation -> AnnotationUtils.findAnnotation(parameter.getParameter(), annotation) != null
237237
|| AnnotationUtils.findAnnotation(parameter.getParameterType(), annotation) != null);
238238
}
239239

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test.org.springdoc.api.app7;
2+
3+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
4+
5+
import java.lang.annotation.Documented;
6+
import java.lang.annotation.ElementType;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
import java.lang.annotation.Target;
10+
11+
@Target({ElementType.PARAMETER, ElementType.TYPE})
12+
@Retention(RetentionPolicy.RUNTIME)
13+
@Documented
14+
@AuthenticationPrincipal
15+
public @interface CurrentUser {
16+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app7;
20+
21+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
22+
import org.springframework.web.bind.annotation.PostMapping;
23+
import org.springframework.web.bind.annotation.RestController;
24+
25+
@RestController
26+
public class HelloController {
27+
28+
@PostMapping(value = "/hello")
29+
public String hello(
30+
@AuthenticationPrincipal Person person1,
31+
@CurrentUser Person person2) {
32+
return "OK";
33+
}
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app7;
20+
21+
public class Person {
22+
23+
private String name;
24+
25+
public Person() {
26+
}
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public void setName(String name) {
33+
this.name = name;
34+
}
35+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app7;
20+
21+
import io.swagger.v3.oas.models.OpenAPI;
22+
import io.swagger.v3.oas.models.info.Info;
23+
import io.swagger.v3.oas.models.info.License;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.context.annotation.Bean;
26+
import test.org.springdoc.api.AbstractSpringDocTest;
27+
28+
public class SpringDocApp7Test extends AbstractSpringDocTest {
29+
30+
@SpringBootApplication(scanBasePackages = { "test.org.springdoc.api.configuration,test.org.springdoc.api.app7" })
31+
static class SpringDocTestApp {
32+
@Bean
33+
public OpenAPI customOpenAPI() {
34+
return new OpenAPI()
35+
.info(new Info().title("Security API").version("v1")
36+
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
37+
}
38+
}
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "Security API",
5+
"license": {
6+
"name": "Apache 2.0",
7+
"url": "http://springdoc.org"
8+
},
9+
"version": "v1"
10+
},
11+
"servers": [
12+
{
13+
"url": "http://localhost",
14+
"description": "Generated server url"
15+
}
16+
],
17+
"paths": {
18+
"/hello": {
19+
"post": {
20+
"tags": [
21+
"hello-controller"
22+
],
23+
"operationId": "hello",
24+
"responses": {
25+
"200": {
26+
"description": "OK",
27+
"content": {
28+
"*/*": {
29+
"schema": {
30+
"type": "string"
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"components": {
40+
}
41+
}

0 commit comments

Comments
 (0)