Skip to content

Commit d021d23

Browse files
author
bnasslahsen
committed
Added support to disable autotagging of @RestController Classes. Fixes #420.
1 parent a9e5672 commit d021d23

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/OpenAPIBuilder.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ public class OpenAPIBuilder {
8989

9090
private String serverBaseUrl;
9191

92+
private final SpringDocConfigProperties springDocConfigProperties;
93+
9294
@SuppressWarnings("WeakerAccess")
93-
OpenAPIBuilder(Optional<OpenAPI> openAPI, ApplicationContext context, SecurityParser securityParser, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider) {
95+
OpenAPIBuilder(Optional<OpenAPI> openAPI, ApplicationContext context, SecurityParser securityParser, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider, SpringDocConfigProperties springDocConfigProperties) {
9496
if (openAPI.isPresent()) {
9597
this.openAPI = openAPI.get();
9698
if (this.openAPI.getComponents() == null)
@@ -103,6 +105,7 @@ public class OpenAPIBuilder {
103105
this.context = context;
104106
this.securityParser = securityParser;
105107
this.springSecurityOAuth2Provider = springSecurityOAuth2Provider;
108+
this.springDocConfigProperties=springDocConfigProperties;
106109
}
107110

108111
private static String splitCamelCase(String str) {
@@ -210,7 +213,7 @@ public Operation buildTags(HandlerMethod handlerMethod, Operation operation, Ope
210213
operation.setTags(new ArrayList<>(tagsStr));
211214
}
212215

213-
if (CollectionUtils.isEmpty(operation.getTags())) {
216+
if (CollectionUtils.isEmpty(operation.getTags()) && springDocConfigProperties.getAutoTagClasses()) {
214217
operation.addTagsItem(splitCamelCase(handlerMethod.getBeanType().getSimpleName()));
215218
}
216219

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfigProperties.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public class SpringDocConfigProperties {
5050

5151
private List<GroupConfig> groupConfigs = new ArrayList<>();
5252

53+
private Boolean autoTagClasses = true;
54+
55+
public Boolean getAutoTagClasses() {
56+
return autoTagClasses;
57+
}
58+
59+
public void setAutoTagClasses(Boolean autoTagClasses) {
60+
this.autoTagClasses = autoTagClasses;
61+
}
62+
5363
public List<String> getPackagesToExclude() {
5464
return packagesToExclude;
5565
}
@@ -201,7 +211,8 @@ public void addGroupConfig(GroupConfig groupConfigs) {
201211
}
202212

203213
public static class GroupConfig {
204-
public GroupConfig() { }
214+
public GroupConfig() {
215+
}
205216

206217
public GroupConfig(String group, List<String> pathsToMatch, List<String> packagesToScan, List<String> packagesToExclude, List<String> pathsToExclude) {
207218
this.pathsToMatch = pathsToMatch;

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ IgnoredParameterAnnotationsDefault ignoredParameterAnnotationsDefault() {
7575
}
7676

7777
@Bean
78-
public OpenAPIBuilder openAPIBuilder(Optional<OpenAPI> openAPI, ApplicationContext context, SecurityParser securityParser, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider) {
79-
return new OpenAPIBuilder(openAPI, context, securityParser, springSecurityOAuth2Provider);
78+
public OpenAPIBuilder openAPIBuilder(Optional<OpenAPI> openAPI, ApplicationContext context, SecurityParser securityParser, Optional<SecurityOAuth2Provider> springSecurityOAuth2Provider,SpringDocConfigProperties springDocConfigProperties) {
79+
return new OpenAPIBuilder(openAPI, context, securityParser, springSecurityOAuth2Provider,springDocConfigProperties);
8080
}
8181

8282
@Bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.app88;
20+
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
@RestController
25+
public class HelloController {
26+
27+
@GetMapping(value = "/persons")
28+
public String persons() {
29+
return null;
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.app88;
20+
21+
import test.org.springdoc.api.AbstractSpringDocTest;
22+
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
import org.springframework.test.context.TestPropertySource;
25+
26+
@TestPropertySource(properties = "springdoc.auto-tag-classes=false")
27+
public class SpringDocApp88Test extends AbstractSpringDocTest {
28+
29+
@SpringBootApplication
30+
static class SpringDocTestApp {}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
"/persons": {
15+
"get": {
16+
"operationId": "persons",
17+
"responses": {
18+
"200": {
19+
"description": "default response",
20+
"content": {
21+
"*/*": {
22+
"schema": {
23+
"type": "string"
24+
}
25+
}
26+
}
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"components": {}
33+
}

0 commit comments

Comments
 (0)