Skip to content

Commit 26e177d

Browse files
committed
webflux integration
1 parent b8394d7 commit 26e177d

File tree

53 files changed

+1550
-1541
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1550
-1541
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ default boolean isRestController(String operationPath, Class<?> controllerClass
8181

8282
String getBasePath();
8383

84-
String getServletContextPath();
84+
String getContextPath();
8585

8686
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class CacheOrGroupedOpenApiCondition extends AnyNestedCondition {
4444
* The type On multiple open api support condition.
4545
* @author bnasslahsen
4646
*/
47-
@Conditional(MultipleOpenApiSupportCondition.class)
47+
@Conditional(MultipleOpenApiGroupsCondition.class)
4848
static class OnMultipleOpenApiSupportCondition {}
4949

5050
/**
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
*
3+
* *
4+
* * * Copyright 2019-2020 the original author or authors.
5+
* * *
6+
* * * Licensed under the Apache License, Version 2.0 (the "License");
7+
* * * you may not use this file except in compliance with the License.
8+
* * * You may obtain a copy of the License at
9+
* * *
10+
* * * https://www.apache.org/licenses/LICENSE-2.0
11+
* * *
12+
* * * Unless required by applicable law or agreed to in writing, software
13+
* * * distributed under the License is distributed on an "AS IS" BASIS,
14+
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * * See the License for the specific language governing permissions and
16+
* * * limitations under the License.
17+
* *
18+
*
19+
*/
20+
package org.springdoc.core;
21+
22+
23+
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
26+
27+
import static org.springdoc.core.Constants.GROUP_CONFIG_FIRST_PROPERTY;
28+
29+
/**
30+
* The type Multiple open api support condition.
31+
* @author bnasslahsen
32+
*/
33+
public class MultipleOpenApiGroupsCondition extends AnyNestedCondition {
34+
35+
/**
36+
* Instantiates a new Multiple open api support condition.
37+
*/
38+
MultipleOpenApiGroupsCondition() {
39+
super(ConfigurationPhase.REGISTER_BEAN);
40+
}
41+
42+
/**
43+
* The type On grouped open api bean.
44+
* @author bnasslahsen
45+
*/
46+
@ConditionalOnBean(GroupedOpenApi.class)
47+
static class OnGroupedOpenApiBean {}
48+
49+
/**
50+
* The type On group config property.
51+
* @author bnasslahsen
52+
*/
53+
@ConditionalOnProperty(name = GROUP_CONFIG_FIRST_PROPERTY)
54+
static class OnGroupConfigProperty {}
55+
56+
}
Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,13 @@
1-
/*
2-
*
3-
* *
4-
* * * Copyright 2019-2020 the original author or authors.
5-
* * *
6-
* * * Licensed under the Apache License, Version 2.0 (the "License");
7-
* * * you may not use this file except in compliance with the License.
8-
* * * You may obtain a copy of the License at
9-
* * *
10-
* * * https://www.apache.org/licenses/LICENSE-2.0
11-
* * *
12-
* * * Unless required by applicable law or agreed to in writing, software
13-
* * * distributed under the License is distributed on an "AS IS" BASIS,
14-
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15-
* * * See the License for the specific language governing permissions and
16-
* * * limitations under the License.
17-
* *
18-
*
19-
*/
201
package org.springdoc.core;
212

22-
3+
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
4+
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
235
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
24-
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
256
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
7+
import org.springframework.context.annotation.Conditional;
268

27-
import static org.springdoc.core.Constants.GROUP_CONFIG_FIRST_PROPERTY;
9+
import static org.springdoc.core.Constants.SPRINGDOC_SHOW_ACTUATOR;
2810

29-
/**
30-
* The type Multiple open api support condition.
31-
* @author bnasslahsen
32-
*/
3311
public class MultipleOpenApiSupportCondition extends AnyNestedCondition {
3412

3513
/**
@@ -40,17 +18,14 @@ public class MultipleOpenApiSupportCondition extends AnyNestedCondition {
4018
}
4119

4220
/**
43-
* The type On grouped open api bean.
21+
* The type On multiple open api support condition.
4422
* @author bnasslahsen
4523
*/
46-
@ConditionalOnBean(GroupedOpenApi.class)
47-
static class OnGroupedOpenApiBean {}
24+
@Conditional(MultipleOpenApiGroupsCondition.class)
25+
static class OnMultipleOpenApiSupportCondition {}
4826

49-
/**
50-
* The type On group config property.
51-
* @author bnasslahsen
52-
*/
53-
@ConditionalOnProperty(name = GROUP_CONFIG_FIRST_PROPERTY)
54-
static class OnGroupConfigProperty {}
27+
@ConditionalOnManagementPort(ManagementPortType.DIFFERENT)
28+
@ConditionalOnProperty(SPRINGDOC_SHOW_ACTUATOR)
29+
static class OnActuatorDifferentPort{}
5530

5631
}

springdoc-openapi-common/src/main/java/org/springdoc/ui/AbstractSwaggerWelcome.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package org.springdoc.ui;
2222

23+
import org.apache.commons.lang3.ArrayUtils;
2324
import org.apache.commons.lang3.StringUtils;
2425
import org.springdoc.core.SpringDocConfigProperties;
2526
import org.springdoc.core.SwaggerUiConfigParameters;
@@ -149,6 +150,15 @@ else if (swaggerUiConfig.isDisplayQueryParamsWithoutOauth2() && StringUtils.isNo
149150
return uriBuilder;
150151
}
151152

153+
protected void calculateUiRootCommon(StringBuilder sbUrl, StringBuilder[] sbUrls) {
154+
if (ArrayUtils.isNotEmpty(sbUrls))
155+
sbUrl = sbUrls[0];
156+
String swaggerPath = swaggerUiConfigParameters.getPath();
157+
if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
158+
sbUrl.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
159+
swaggerUiConfigParameters.setUiRootPath(sbUrl.toString());
160+
}
161+
152162
/**
153163
* Calculate oauth 2 redirect url.
154164
*

springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerConfig.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public class SwaggerConfig {
6666
*/
6767
@Bean
6868
@ConditionalOnMissingBean
69-
SwaggerWelcome swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters) {
70-
return new SwaggerWelcome(swaggerUiConfig, springDocConfigProperties,swaggerUiConfigParameters);
69+
@ConditionalOnProperty(name = SPRINGDOC_USE_MANAGEMENT_PORT, havingValue = "false", matchIfMissing = true)
70+
SwaggerWelcomeWebMvc swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters) {
71+
return new SwaggerWelcomeWebMvc(swaggerUiConfig, springDocConfigProperties,swaggerUiConfigParameters);
7172
}
7273

7374
/**
@@ -116,8 +117,8 @@ static class SwaggerActuatorWelcomeConfiguration {
116117

117118
@Bean
118119
@ConditionalOnMissingBean
119-
ActuatorSwaggerWelcome swaggerActuatorWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties) {
120-
return new ActuatorSwaggerWelcome(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, webEndpointProperties);
120+
SwaggerWelcomeActuator swaggerActuatorWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties) {
121+
return new SwaggerWelcomeActuator(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, webEndpointProperties);
121122
}
122123

123124
}

springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/ActuatorSwaggerWelcome.java renamed to springdoc-openapi-ui/src/main/java/org/springdoc/webmvc/ui/SwaggerWelcomeActuator.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,29 @@
55
import javax.servlet.http.HttpServletRequest;
66

77
import io.swagger.v3.oas.annotations.Operation;
8-
import org.apache.commons.lang3.ArrayUtils;
98
import org.apache.commons.lang3.StringUtils;
109
import org.springdoc.core.SpringDocConfigProperties;
1110
import org.springdoc.core.SwaggerUiConfigParameters;
1211
import org.springdoc.core.SwaggerUiConfigProperties;
13-
import org.springdoc.ui.AbstractSwaggerWelcome;
1412

1513
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
1614
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
1715
import org.springframework.http.MediaType;
1816
import org.springframework.util.CollectionUtils;
1917
import org.springframework.web.bind.annotation.GetMapping;
2018
import org.springframework.web.bind.annotation.ResponseBody;
21-
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
22-
import org.springframework.web.servlet.view.UrlBasedViewResolver;
2319
import org.springframework.web.util.UriComponentsBuilder;
2420

2521
import static org.springdoc.core.Constants.DEFAULT_API_DOCS_ACTUATOR_URL;
2622
import static org.springdoc.core.Constants.DEFAULT_SWAGGER_UI_ACTUATOR_PATH;
27-
import static org.springdoc.core.Constants.SWAGGER_UI_URL;
2823
import static org.springdoc.core.Constants.SWAGGGER_CONFIG_FILE;
2924
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
3025

3126
/**
3227
* The type Swagger actuator welcome.
3328
*/
3429
@ControllerEndpoint(id = DEFAULT_SWAGGER_UI_ACTUATOR_PATH)
35-
public class ActuatorSwaggerWelcome extends AbstractSwaggerWelcome {
30+
public class SwaggerWelcomeActuator extends SwaggerWelcomeCommon {
3631

3732
/**
3833
* The Web endpoint properties.
@@ -48,7 +43,7 @@ public class ActuatorSwaggerWelcome extends AbstractSwaggerWelcome {
4843
* @param swaggerUiConfigParameters the swagger ui config parameters
4944
* @param webEndpointProperties the web endpoint properties
5045
*/
51-
public ActuatorSwaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties) {
46+
public SwaggerWelcomeActuator(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties) {
5247
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
5348
this.webEndpointProperties = webEndpointProperties;
5449
}
@@ -62,10 +57,7 @@ public ActuatorSwaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringD
6257
@Operation(hidden = true)
6358
@GetMapping("/")
6459
public String redirectToUi(HttpServletRequest request) {
65-
buildConfigUrl(request.getContextPath(), ServletUriComponentsBuilder.fromCurrentContextPath());
66-
String sbUrl = swaggerUiConfigParameters.getUiRootPath() + SWAGGER_UI_URL;
67-
UriComponentsBuilder uriBuilder = getUriComponentsBuilder(sbUrl);
68-
return UrlBasedViewResolver.REDIRECT_URL_PREFIX + uriBuilder.build().encode().toString();
60+
return super.redirectToUi(request);
6961
}
7062

7163
/**
@@ -78,20 +70,14 @@ public String redirectToUi(HttpServletRequest request) {
7870
@GetMapping(value = SWAGGER_CONFIG_ACTUATOR_URL, produces = MediaType.APPLICATION_JSON_VALUE)
7971
@ResponseBody
8072
public Map<String, Object> openapiJson(HttpServletRequest request) {
81-
buildConfigUrl(request.getContextPath(), ServletUriComponentsBuilder.fromCurrentContextPath());
82-
return swaggerUiConfigParameters.getConfigParameters();
73+
return super.openapiJson(request);
8374
}
8475

8576
@Override
8677
protected void calculateUiRootPath(StringBuilder... sbUrls) {
8778
StringBuilder sbUrl = new StringBuilder();
8879
sbUrl.append(webEndpointProperties.getBasePath());
89-
if (ArrayUtils.isNotEmpty(sbUrls))
90-
sbUrl = sbUrls[0];
91-
String swaggerPath = swaggerUiConfigParameters.getPath();
92-
if (swaggerPath.contains(DEFAULT_PATH_SEPARATOR))
93-
sbUrl.append(swaggerPath, 0, swaggerPath.lastIndexOf(DEFAULT_PATH_SEPARATOR));
94-
swaggerUiConfigParameters.setUiRootPath(sbUrl.toString());
80+
calculateUiRootCommon(sbUrl, sbUrls);
9581
}
9682

9783

@@ -117,9 +103,4 @@ protected void buildConfigUrl(String contextPath, UriComponentsBuilder uriCompon
117103
calculateOauth2RedirectUrl(uriComponentsBuilder);
118104
}
119105

120-
@Override
121-
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
122-
if (!swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl()))
123-
swaggerUiConfigParameters.setOauth2RedirectUrl(uriComponentsBuilder.path(swaggerUiConfigParameters.getUiRootPath()).path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
124-
}
125106
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.springdoc.webmvc.ui;
2+
3+
import java.util.Map;
4+
5+
import javax.servlet.http.HttpServletRequest;
6+
7+
import org.springdoc.core.SpringDocConfigProperties;
8+
import org.springdoc.core.SwaggerUiConfigParameters;
9+
import org.springdoc.core.SwaggerUiConfigProperties;
10+
import org.springdoc.ui.AbstractSwaggerWelcome;
11+
12+
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13+
import org.springframework.web.servlet.view.UrlBasedViewResolver;
14+
import org.springframework.web.util.UriComponentsBuilder;
15+
16+
import static org.springdoc.core.Constants.SWAGGER_UI_URL;
17+
18+
public abstract class SwaggerWelcomeCommon extends AbstractSwaggerWelcome {
19+
/**
20+
* Instantiates a new Abstract swagger welcome.
21+
* @param swaggerUiConfig the swagger ui config
22+
* @param springDocConfigProperties the spring doc config properties
23+
* @param swaggerUiConfigParameters the swagger ui config parameters
24+
*/
25+
public SwaggerWelcomeCommon(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters) {
26+
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
27+
}
28+
29+
protected String redirectToUi(HttpServletRequest request) {
30+
buildConfigUrl(request.getContextPath(), ServletUriComponentsBuilder.fromCurrentContextPath());
31+
String sbUrl = swaggerUiConfigParameters.getUiRootPath() + SWAGGER_UI_URL;
32+
UriComponentsBuilder uriBuilder = getUriComponentsBuilder(sbUrl);
33+
return UrlBasedViewResolver.REDIRECT_URL_PREFIX + uriBuilder.build().encode().toString();
34+
}
35+
36+
protected Map<String, Object> openapiJson(HttpServletRequest request) {
37+
buildConfigUrl(request.getContextPath(), ServletUriComponentsBuilder.fromCurrentContextPath());
38+
return swaggerUiConfigParameters.getConfigParameters();
39+
}
40+
41+
@Override
42+
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
43+
if (!swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl()))
44+
swaggerUiConfigParameters.setOauth2RedirectUrl(uriComponentsBuilder.path(swaggerUiConfigParameters.getUiRootPath()).path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
45+
}
46+
}

0 commit comments

Comments
 (0)