Skip to content

Commit 6b38e96

Browse files
author
Anastasiia Smirnova
committed
Property springdoc.api-docs.groups.enabled removed, as not needed any more for enabling multiple OpenAPI definitions support
1 parent bc5637a commit 6b38e96

File tree

12 files changed

+177
-94
lines changed

12 files changed

+177
-94
lines changed

CHANGELOG.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.2.21] -
8+
9+
### Removed
10+
- Property `springdoc.api-docs.groups.enabled` removed, as not needed any more for enabling multiple OpenAPI definitions support
11+
712
## [1.2.20] - 2019-12-23
813

914
### Changed
@@ -13,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1318

1419
## [1.2.19] - 2019-12-22
1520

16-
### Addded
21+
### Added
1722
- Support for Multiple OpenAPI definitions in one Spring Boot #213
1823
- Support for spring-context-indexer #262
1924
- Added support using properties from application.yml for description field in swagger-annotations #231
@@ -32,7 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3237

3338
## [1.2.18] - 2019-12-14
3439

35-
### Addded
40+
### Added
3641
- Globally exclude params for webflux #228
3742
- Added ability to ignore param with @hidden annotation at class level #255
3843
- Support of spring.mvc.servlet.path #238
@@ -48,7 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4853
### Fixed
4954
- Fixes error with JDK 11 + Kotlin #248
5055
## [1.2.17] - 2019-12-05
51-
### Addded
56+
### Added
5257
- Handle multiple endpoints on @GetParam #219
5358

5459
### Changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public final class Constants {
1111
public static final String SWAGGER_CONFIG_URL = API_DOCS_URL + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
1212
public static final String DEFAULT_API_DOCS_URL_YAML = API_DOCS_URL + ".yaml";
1313
public static final String SPRINGDOC_ENABLED = "springdoc.api-docs.enabled";
14-
public static final String SPRINGDOC_GROUPS_ENABLED = "springdoc.api-docs.groups.enabled";
15-
public static final String SPRINGDOC_GROUPS_ENABLED_VALUE = "${" + SPRINGDOC_GROUPS_ENABLED + ":false}";
1614
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled";
1715
public static final String SPRINGDOC_SHOW_ACTUATOR = "springdoc.show-actuator";
1816
public static final String SPRINGDOC_SHOW_ACTUATOR_VALUE = "${" + SPRINGDOC_SHOW_ACTUATOR + ":false}";

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

-25
This file was deleted.

springdoc-openapi-ui/src/main/java/org/springdoc/ui/SwaggerWelcome.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
import javax.servlet.http.HttpServletRequest;
1616
import java.util.Map;
1717

18-
import static org.springdoc.core.Constants.*;
18+
import static org.springdoc.core.Constants.API_DOCS_URL;
19+
import static org.springdoc.core.Constants.MVC_SERVLET_PATH;
20+
import static org.springdoc.core.Constants.SPRINGDOC_SWAGGER_UI_ENABLED;
21+
import static org.springdoc.core.Constants.SWAGGER_CONFIG_URL;
22+
import static org.springdoc.core.Constants.SWAGGER_UI_PATH;
23+
import static org.springdoc.core.Constants.SWAGGER_UI_URL;
24+
import static org.springdoc.core.Constants.SWAGGGER_CONFIG_FILE;
1925
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
2026
import static org.springframework.web.servlet.view.UrlBasedViewResolver.REDIRECT_URL_PREFIX;
2127

@@ -35,9 +41,6 @@ class SwaggerWelcome {
3541
@Autowired
3642
private SwaggerUiConfigProperties swaggerUiConfig;
3743

38-
@Value(SPRINGDOC_GROUPS_ENABLED_VALUE)
39-
private boolean groupsEnabled;
40-
4144
@Operation(hidden = true)
4245
@GetMapping(SWAGGER_UI_PATH)
4346
public String redirectToUi(HttpServletRequest request) {
@@ -78,10 +81,12 @@ private void buildConfigUrl(HttpServletRequest request) {
7881
String url = buildUrl(request, apiDocsUrl);
7982
String swaggerConfigUrl = url + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
8083
swaggerUiConfig.setConfigUrl(swaggerConfigUrl);
81-
if (groupsEnabled)
82-
SwaggerUiConfigProperties.addUrl(url);
83-
else
84+
85+
if (SwaggerUiConfigProperties.getSwaggerUrls().isEmpty())
8486
swaggerUiConfig.setUrl(url);
87+
else
88+
SwaggerUiConfigProperties.addUrl(url);
89+
8590
}
8691
}
8792
}

springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app3/SpringDocApp3Test.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
88
import test.org.springdoc.ui.AbstractSpringDocTest;
99

10+
import static org.hamcrest.CoreMatchers.equalTo;
11+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
12+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
13+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
14+
1015
public class SpringDocApp3Test extends AbstractSpringDocTest {
1116

1217
@Test
@@ -19,4 +24,13 @@ public void appLoads() throws Exception {
1924
.andExpect(MockMvcResultMatchers.status().isOk())
2025
.andExpect(MockMvcResultMatchers.header().string(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE));
2126
}
27+
28+
@Test
29+
public void swagger_config_for_no_groups() throws Exception {
30+
mockMvc.perform(get("/v3/api-docs/swagger-config"))
31+
.andExpect(status().isOk())
32+
.andExpect(jsonPath("configUrl", equalTo("/v3/api-docs/swagger-config")))
33+
.andExpect(jsonPath("url", equalTo("/v3/api-docs")))
34+
.andExpect(jsonPath("urls").doesNotExist());
35+
}
2236
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.springdoc.ui.app4;
2+
3+
import org.junit.Test;
4+
import test.org.springdoc.ui.AbstractSpringDocTest;
5+
6+
import static org.hamcrest.CoreMatchers.equalTo;
7+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
8+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
9+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
10+
11+
public class SpringDocApp4Test extends AbstractSpringDocTest {
12+
13+
@Test
14+
public void swagger_config_for_multiple_groups() throws Exception {
15+
mockMvc.perform(get("/v3/api-docs/swagger-config"))
16+
.andExpect(status().isOk())
17+
.andExpect(jsonPath("configUrl", equalTo("/v3/api-docs/swagger-config")))
18+
.andExpect(jsonPath("url").doesNotExist())
19+
.andExpect(jsonPath("urls[0].url", equalTo("/v3/api-docs/stores")))
20+
.andExpect(jsonPath("urls[0].name", equalTo("stores")))
21+
.andExpect(jsonPath("urls[1].url", equalTo("/v3/api-docs/pets")))
22+
.andExpect(jsonPath("urls[1].name", equalTo("pets")));
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test.org.springdoc.ui.app4;
2+
3+
import org.springdoc.core.GroupedOpenApi;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.context.annotation.Bean;
7+
8+
@SpringBootApplication
9+
public class SpringDocTestApp {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringDocTestApp.class, args);
13+
}
14+
15+
@Bean
16+
public GroupedOpenApi storeOpenApi() {
17+
String paths[] = {"/store/**"};
18+
return GroupedOpenApi.builder()
19+
.setGroup("stores")
20+
.pathsToMatch(paths)
21+
.build();
22+
}
23+
24+
@Bean
25+
public GroupedOpenApi groupOpenApi() {
26+
String paths[] = {"/pet/**"};
27+
return GroupedOpenApi.builder()
28+
.setGroup("pets")
29+
.pathsToMatch(paths)
30+
.build();
31+
}
32+
33+
}

springdoc-openapi-webflux-ui/src/main/java/org/springdoc/ui/SwaggerWelcome.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public class SwaggerWelcome {
3535
private String uiPath;
3636
@Value(WEB_JARS_PREFIX_URL)
3737
private String webJarsPrefixUrl;
38-
@Value(SPRINGDOC_GROUPS_ENABLED_VALUE)
39-
private boolean groupsEnabled;
4038

4139
@Bean
4240
@ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
@@ -60,10 +58,12 @@ private void buildConfigUrl() {
6058
if (StringUtils.isEmpty(swaggerUiConfig.getConfigUrl())) {
6159
String swaggerConfigUrl = apiDocsUrl + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
6260
swaggerUiConfig.setConfigUrl(swaggerConfigUrl);
63-
if (groupsEnabled)
64-
SwaggerUiConfigProperties.addUrl(apiDocsUrl);
65-
else
61+
62+
if (SwaggerUiConfigProperties.getSwaggerUrls().isEmpty())
6663
swaggerUiConfig.setUrl(apiDocsUrl);
64+
else
65+
SwaggerUiConfigProperties.addUrl(apiDocsUrl);
66+
6767
}
6868
}
6969

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.springdoc.core;
2+
3+
import io.swagger.v3.oas.models.OpenAPI;
4+
import org.springdoc.api.ActuatorProvider;
5+
import org.springdoc.api.MultipleOpenApiResource;
6+
import org.springframework.beans.factory.ObjectFactory;
7+
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
8+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;
12+
13+
import java.util.List;
14+
import java.util.Optional;
15+
16+
17+
@Configuration
18+
@ConditionalOnBean(GroupedOpenApi.class)
19+
public class MultipleOpenApiSupportConfiguration {
20+
21+
@Bean
22+
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
23+
return beanFactory -> {
24+
for (String beanName : beanFactory.getBeanNamesForType(OpenAPI.class)) {
25+
beanFactory.getBeanDefinition(beanName).setScope("prototype");
26+
}
27+
for (String beanName : beanFactory.getBeanNamesForType(OpenAPIBuilder.class)) {
28+
beanFactory.getBeanDefinition(beanName).setScope("prototype");
29+
}
30+
};
31+
}
32+
33+
@Bean
34+
public MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
35+
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
36+
AbstractResponseBuilder responseBuilder, OperationBuilder operationParser,
37+
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
38+
Optional<ActuatorProvider> servletContextProvider) {
39+
return new MultipleOpenApiResource(groupedOpenApis,
40+
defaultOpenAPIBuilder, requestBuilder,
41+
responseBuilder, operationParser,
42+
requestMappingHandlerMapping, servletContextProvider);
43+
}
44+
}

springdoc-openapi-webmvc-core/src/main/java/org/springdoc/core/SpringDocWebMvcConfiguration.java

-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.springdoc.core;
22

33
import org.springdoc.api.ActuatorProvider;
4-
import org.springdoc.api.MultipleOpenApiResource;
54
import org.springdoc.api.OpenApiCustomiser;
65
import org.springdoc.api.OpenApiResource;
7-
import org.springframework.beans.factory.ObjectFactory;
86
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
97
import org.springframework.context.annotation.Bean;
108
import org.springframework.context.annotation.Configuration;
@@ -15,24 +13,10 @@
1513
import java.util.Optional;
1614

1715
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
18-
import static org.springdoc.core.Constants.SPRINGDOC_GROUPS_ENABLED;
1916

2017
@Configuration
2118
public class SpringDocWebMvcConfiguration {
2219

23-
24-
@Bean
25-
@ConditionalOnProperty(name = SPRINGDOC_GROUPS_ENABLED)
26-
public MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
27-
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
28-
AbstractResponseBuilder responseBuilder, OperationBuilder operationParser,
29-
RequestMappingInfoHandlerMapping requestMappingHandlerMapping, Optional<ActuatorProvider> servletContextProvider) {
30-
return new MultipleOpenApiResource(groupedOpenApis,
31-
defaultOpenAPIBuilder, requestBuilder,
32-
responseBuilder, operationParser,
33-
requestMappingHandlerMapping, servletContextProvider);
34-
}
35-
3620
@Bean
3721
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
3822
public OpenApiResource openApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder requestBuilder,

0 commit comments

Comments
 (0)