Skip to content

Property springdoc.api-docs.groups.enabled removed #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.21] -

### Removed
- Property `springdoc.api-docs.groups.enabled` removed, as not needed any more for enabling multiple OpenAPI definitions support

## [1.2.20] - 2019-12-23

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

## [1.2.19] - 2019-12-22

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

## [1.2.18] - 2019-12-14

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

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public final class Constants {
public static final String SWAGGER_CONFIG_URL = API_DOCS_URL + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
public static final String DEFAULT_API_DOCS_URL_YAML = API_DOCS_URL + ".yaml";
public static final String SPRINGDOC_ENABLED = "springdoc.api-docs.enabled";
public static final String SPRINGDOC_GROUPS_ENABLED = "springdoc.api-docs.groups.enabled";
public static final String SPRINGDOC_GROUPS_ENABLED_VALUE = "${" + SPRINGDOC_GROUPS_ENABLED + ":false}";
public static final String SPRINGDOC_SWAGGER_UI_ENABLED = "springdoc.swagger-ui.enabled";
public static final String SPRINGDOC_SHOW_ACTUATOR = "springdoc.show-actuator";
public static final String SPRINGDOC_SHOW_ACTUATOR_VALUE = "${" + SPRINGDOC_SHOW_ACTUATOR + ":false}";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static org.springdoc.core.Constants.*;
import static org.springdoc.core.Constants.API_DOCS_URL;
import static org.springdoc.core.Constants.MVC_SERVLET_PATH;
import static org.springdoc.core.Constants.SPRINGDOC_SWAGGER_UI_ENABLED;
import static org.springdoc.core.Constants.SWAGGER_CONFIG_URL;
import static org.springdoc.core.Constants.SWAGGER_UI_PATH;
import static org.springdoc.core.Constants.SWAGGER_UI_URL;
import static org.springdoc.core.Constants.SWAGGGER_CONFIG_FILE;
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
import static org.springframework.web.servlet.view.UrlBasedViewResolver.REDIRECT_URL_PREFIX;

Expand All @@ -35,9 +41,6 @@ class SwaggerWelcome {
@Autowired
private SwaggerUiConfigProperties swaggerUiConfig;

@Value(SPRINGDOC_GROUPS_ENABLED_VALUE)
private boolean groupsEnabled;

@Operation(hidden = true)
@GetMapping(SWAGGER_UI_PATH)
public String redirectToUi(HttpServletRequest request) {
Expand Down Expand Up @@ -78,10 +81,12 @@ private void buildConfigUrl(HttpServletRequest request) {
String url = buildUrl(request, apiDocsUrl);
String swaggerConfigUrl = url + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
swaggerUiConfig.setConfigUrl(swaggerConfigUrl);
if (groupsEnabled)
SwaggerUiConfigProperties.addUrl(url);
else

if (SwaggerUiConfigProperties.getSwaggerUrls().isEmpty())
swaggerUiConfig.setUrl(url);
else
SwaggerUiConfigProperties.addUrl(url);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import test.org.springdoc.ui.AbstractSpringDocTest;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class SpringDocApp3Test extends AbstractSpringDocTest {

@Test
Expand All @@ -19,4 +24,13 @@ public void appLoads() throws Exception {
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.header().string(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE));
}

@Test
public void swagger_config_for_no_groups() throws Exception {
mockMvc.perform(get("/v3/api-docs/swagger-config"))
.andExpect(status().isOk())
.andExpect(jsonPath("configUrl", equalTo("/v3/api-docs/swagger-config")))
.andExpect(jsonPath("url", equalTo("/v3/api-docs")))
.andExpect(jsonPath("urls").doesNotExist());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package test.org.springdoc.ui.app4;

import org.junit.Test;
import test.org.springdoc.ui.AbstractSpringDocTest;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class SpringDocApp4Test extends AbstractSpringDocTest {

@Test
public void swagger_config_for_multiple_groups() throws Exception {
mockMvc.perform(get("/v3/api-docs/swagger-config"))
.andExpect(status().isOk())
.andExpect(jsonPath("configUrl", equalTo("/v3/api-docs/swagger-config")))
.andExpect(jsonPath("url").doesNotExist())
.andExpect(jsonPath("urls[0].url", equalTo("/v3/api-docs/stores")))
.andExpect(jsonPath("urls[0].name", equalTo("stores")))
.andExpect(jsonPath("urls[1].url", equalTo("/v3/api-docs/pets")))
.andExpect(jsonPath("urls[1].name", equalTo("pets")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package test.org.springdoc.ui.app4;

import org.springdoc.core.GroupedOpenApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class SpringDocTestApp {

public static void main(String[] args) {
SpringApplication.run(SpringDocTestApp.class, args);
}

@Bean
public GroupedOpenApi storeOpenApi() {
String paths[] = {"/store/**"};
return GroupedOpenApi.builder()
.setGroup("stores")
.pathsToMatch(paths)
.build();
}

@Bean
public GroupedOpenApi groupOpenApi() {
String paths[] = {"/pet/**"};
return GroupedOpenApi.builder()
.setGroup("pets")
.pathsToMatch(paths)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class SwaggerWelcome {
private String uiPath;
@Value(WEB_JARS_PREFIX_URL)
private String webJarsPrefixUrl;
@Value(SPRINGDOC_GROUPS_ENABLED_VALUE)
private boolean groupsEnabled;

@Bean
@ConditionalOnProperty(name = SPRINGDOC_SWAGGER_UI_ENABLED, matchIfMissing = true)
Expand All @@ -60,10 +58,12 @@ private void buildConfigUrl() {
if (StringUtils.isEmpty(swaggerUiConfig.getConfigUrl())) {
String swaggerConfigUrl = apiDocsUrl + DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
swaggerUiConfig.setConfigUrl(swaggerConfigUrl);
if (groupsEnabled)
SwaggerUiConfigProperties.addUrl(apiDocsUrl);
else

if (SwaggerUiConfigProperties.getSwaggerUrls().isEmpty())
swaggerUiConfig.setUrl(apiDocsUrl);
else
SwaggerUiConfigProperties.addUrl(apiDocsUrl);

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.springdoc.core;

import io.swagger.v3.oas.models.OpenAPI;
import org.springdoc.api.ActuatorProvider;
import org.springdoc.api.MultipleOpenApiResource;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping;

import java.util.List;
import java.util.Optional;


@Configuration
@ConditionalOnBean(GroupedOpenApi.class)
public class MultipleOpenApiSupportConfiguration {

@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
return beanFactory -> {
for (String beanName : beanFactory.getBeanNamesForType(OpenAPI.class)) {
beanFactory.getBeanDefinition(beanName).setScope("prototype");
}
for (String beanName : beanFactory.getBeanNamesForType(OpenAPIBuilder.class)) {
beanFactory.getBeanDefinition(beanName).setScope("prototype");
}
};
}

@Bean
public MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
AbstractResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping,
Optional<ActuatorProvider> servletContextProvider) {
return new MultipleOpenApiResource(groupedOpenApis,
defaultOpenAPIBuilder, requestBuilder,
responseBuilder, operationParser,
requestMappingHandlerMapping, servletContextProvider);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.springdoc.core;

import org.springdoc.api.ActuatorProvider;
import org.springdoc.api.MultipleOpenApiResource;
import org.springdoc.api.OpenApiCustomiser;
import org.springdoc.api.OpenApiResource;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -15,24 +13,10 @@
import java.util.Optional;

import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
import static org.springdoc.core.Constants.SPRINGDOC_GROUPS_ENABLED;

@Configuration
public class SpringDocWebMvcConfiguration {


@Bean
@ConditionalOnProperty(name = SPRINGDOC_GROUPS_ENABLED)
public MultipleOpenApiResource multipleOpenApiResource(List<GroupedOpenApi> groupedOpenApis,
ObjectFactory<OpenAPIBuilder> defaultOpenAPIBuilder, AbstractRequestBuilder requestBuilder,
AbstractResponseBuilder responseBuilder, OperationBuilder operationParser,
RequestMappingInfoHandlerMapping requestMappingHandlerMapping, Optional<ActuatorProvider> servletContextProvider) {
return new MultipleOpenApiResource(groupedOpenApis,
defaultOpenAPIBuilder, requestBuilder,
responseBuilder, operationParser,
requestMappingHandlerMapping, servletContextProvider);
}

@Bean
@ConditionalOnProperty(name = SPRINGDOC_ENABLED, matchIfMissing = true)
public OpenApiResource openApiResource(OpenAPIBuilder openAPIBuilder, AbstractRequestBuilder requestBuilder,
Expand Down
Loading