Skip to content

Commit 5a355d5

Browse files
committed
CHANGELOG.md update
1 parent 7799b3b commit 5a355d5

File tree

14 files changed

+317
-74
lines changed

14 files changed

+317
-74
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- #1020 - Change handler methods scanning strategy
1212
- #1026 - Support for @Operation in @RepositoryRestResource Spring Data Repositories.
1313
- #1027 - Detect automatically @Controller with @Operation.
14-
1514
### Changed
1615
- Upgrade versions: spring-boot to 2.4.2 and swagger-ui to 3.40
1716
### Fixed
@@ -20,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2019
- #1015 - Default value for List/Array RequestParameter has wrong type.
2120
- #1010 - Wrong Parameter Name with Default Sort.
2221
- #1014 - HATOEAS Links produces a circular reference.
22+
- #1035 - oauth2 redirect url calculated incorrectly when springdoc.swagger-ui.path=/
2323

2424
## [1.5.2] - 2020-12-16
2525
### Added

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
3434
import org.springframework.boot.actuate.autoconfigure.web.server.ConditionalOnManagementPort;
3535
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType;
36+
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
3637
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
3738
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
3839
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3940
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
4041
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
42+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
4143
import org.springframework.context.annotation.Bean;
4244
import org.springframework.context.annotation.Configuration;
4345
import org.springframework.context.annotation.Lazy;
@@ -68,8 +70,8 @@ public class SwaggerConfig implements WebFluxConfigurer {
6870
@Bean
6971
@ConditionalOnMissingBean
7072
@ConditionalOnProperty(name = SPRINGDOC_USE_MANAGEMENT_PORT, havingValue = "false", matchIfMissing = true)
71-
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters) {
72-
return new SwaggerWelcomeWebFlux(swaggerUiConfig,springDocConfigProperties,swaggerUiConfigParameters);
73+
SwaggerWelcomeWebFlux swaggerWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,SwaggerUiConfigParameters swaggerUiConfigParameters, WebFluxProperties webFluxProperties) {
74+
return new SwaggerWelcomeWebFlux(swaggerUiConfig,springDocConfigProperties,swaggerUiConfigParameters,webFluxProperties);
7375
}
7476

7577
/**
@@ -129,12 +131,14 @@ static class SwaggerActuatorWelcomeConfiguration {
129131
* @param springDocConfigProperties the spring doc config properties
130132
* @param swaggerUiConfigParameters the swagger ui config parameters
131133
* @param webEndpointProperties the web endpoint properties
134+
* @param managementServerProperties the management server properties
132135
* @return the swagger welcome actuator
133136
*/
134137
@Bean
135138
@ConditionalOnMissingBean
136-
SwaggerWelcomeActuator swaggerActuatorWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties) {
137-
return new SwaggerWelcomeActuator(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, webEndpointProperties);
139+
SwaggerWelcomeActuator swaggerActuatorWelcome(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties,
140+
SwaggerUiConfigParameters swaggerUiConfigParameters, WebEndpointProperties webEndpointProperties, ManagementServerProperties managementServerProperties) {
141+
return new SwaggerWelcomeActuator(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters, webEndpointProperties,managementServerProperties);
138142
}
139143
}
140144
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import reactor.core.publisher.Mono;
3131

3232
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
33+
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties;
3334
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpoint;
3435
import org.springframework.http.MediaType;
3536
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -56,6 +57,11 @@ public class SwaggerWelcomeActuator extends SwaggerWelcomeCommon {
5657
*/
5758
private WebEndpointProperties webEndpointProperties;
5859

60+
/**
61+
* The Management server properties.
62+
*/
63+
private ManagementServerProperties managementServerProperties;
64+
5965
/**
6066
* The constant SWAGGER_CONFIG_ACTUATOR_URL.
6167
*/
@@ -72,9 +78,11 @@ public class SwaggerWelcomeActuator extends SwaggerWelcomeCommon {
7278
public SwaggerWelcomeActuator(SwaggerUiConfigProperties swaggerUiConfig
7379
, SpringDocConfigProperties springDocConfigProperties,
7480
SwaggerUiConfigParameters swaggerUiConfigParameters,
75-
WebEndpointProperties webEndpointProperties) {
81+
WebEndpointProperties webEndpointProperties,
82+
ManagementServerProperties managementServerProperties) {
7683
super(swaggerUiConfig, springDocConfigProperties,swaggerUiConfigParameters);
7784
this.webEndpointProperties = webEndpointProperties;
85+
this.managementServerProperties=managementServerProperties;
7886
}
7987

8088
/**
@@ -114,9 +122,8 @@ public Map<String, Object> getSwaggerUiConfig(ServerHttpRequest request) {
114122
*/
115123
@Override
116124
protected void buildConfigUrl(String contextPath, UriComponentsBuilder uriComponentsBuilder) {
117-
String apiDocsUrl = DEFAULT_API_DOCS_ACTUATOR_URL;
118125
if (StringUtils.isEmpty(swaggerUiConfig.getConfigUrl())) {
119-
String url = buildUrl(contextPath + webEndpointProperties.getBasePath(), apiDocsUrl);
126+
String url = buildUrl(contextPath + webEndpointProperties.getBasePath(), DEFAULT_API_DOCS_ACTUATOR_URL);
120127
String swaggerConfigUrl = contextPath + webEndpointProperties.getBasePath()
121128
+ DEFAULT_PATH_SEPARATOR + DEFAULT_SWAGGER_UI_ACTUATOR_PATH
122129
+ DEFAULT_PATH_SEPARATOR + SWAGGGER_CONFIG_FILE;
@@ -142,4 +149,11 @@ protected void calculateUiRootPath(StringBuilder... sbUrls) {
142149
calculateUiRootCommon(sbUrl, sbUrls);
143150
}
144151

152+
@Override
153+
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
154+
if (oauthPrefix == null && !swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl())) {
155+
this.oauthPrefix = uriComponentsBuilder.path(managementServerProperties.getBasePath()+swaggerUiConfigParameters.getUiRootPath()).path(webJarsPrefixUrl);
156+
swaggerUiConfigParameters.setOauth2RedirectUrl(this.oauthPrefix.path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
157+
}
158+
}
145159
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.http.HttpStatus;
3333
import org.springframework.http.server.reactive.ServerHttpRequest;
3434
import org.springframework.http.server.reactive.ServerHttpResponse;
35+
import org.springframework.util.AntPathMatcher;
3536
import org.springframework.web.util.UriComponentsBuilder;
3637

3738
import static org.springdoc.core.Constants.SWAGGER_UI_URL;
@@ -90,15 +91,6 @@ protected Map<String, Object> getSwaggerUiConfig(ServerHttpRequest request) {
9091
return swaggerUiConfigParameters.getConfigParameters();
9192
}
9293

93-
94-
@Override
95-
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
96-
if (oauthPrefix == null && !swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl())) {
97-
this.oauthPrefix = uriComponentsBuilder.path(swaggerUiConfigParameters.getUiRootPath()).path(webJarsPrefixUrl);
98-
swaggerUiConfigParameters.setOauth2RedirectUrl(this.oauthPrefix.path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
99-
}
100-
}
101-
10294
/**
10395
* From current context path string.
10496
*
@@ -108,7 +100,8 @@ protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuil
108100
private String fromCurrentContextPath(ServerHttpRequest request) {
109101
String contextPath = request.getPath().contextPath().value();
110102
String url = UriComponentsBuilder.fromHttpRequest(request).toUriString();
111-
url = url.replace(request.getPath().toString(), "/");
103+
if (!AntPathMatcher.DEFAULT_PATH_SEPARATOR.equals(request.getPath().toString()))
104+
url = url.replace(request.getPath().toString(), "");
112105
buildConfigUrl(contextPath, UriComponentsBuilder.fromUriString(url));
113106
return contextPath;
114107
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
import org.springdoc.core.SwaggerUiConfigProperties;
2929
import reactor.core.publisher.Mono;
3030

31+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
3132
import org.springframework.http.MediaType;
3233
import org.springframework.http.server.reactive.ServerHttpRequest;
3334
import org.springframework.http.server.reactive.ServerHttpResponse;
3435
import org.springframework.stereotype.Controller;
3536
import org.springframework.web.bind.annotation.GetMapping;
3637
import org.springframework.web.bind.annotation.ResponseBody;
38+
import org.springframework.web.util.UriComponentsBuilder;
3739

3840
import static org.springdoc.core.Constants.SWAGGER_CONFIG_URL;
3941
import static org.springdoc.core.Constants.SWAGGER_UI_PATH;
@@ -45,15 +47,22 @@
4547
@Controller
4648
public class SwaggerWelcomeWebFlux extends SwaggerWelcomeCommon {
4749

50+
/**
51+
* The Webflux base path.
52+
*/
53+
private String webfluxBasePath;
54+
4855
/**
4956
* Instantiates a new Swagger welcome.
5057
*
5158
* @param swaggerUiConfig the swagger ui config
5259
* @param springDocConfigProperties the spring doc config properties
5360
* @param swaggerUiConfigParameters the swagger ui config parameters
61+
* @param webFluxProperties the web flux properties
5462
*/
55-
public SwaggerWelcomeWebFlux(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters) {
63+
public SwaggerWelcomeWebFlux(SwaggerUiConfigProperties swaggerUiConfig, SpringDocConfigProperties springDocConfigProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, WebFluxProperties webFluxProperties) {
5664
super(swaggerUiConfig, springDocConfigProperties, swaggerUiConfigParameters);
65+
webfluxBasePath = webFluxProperties.getBasePath();
5766
}
5867

5968
/**
@@ -90,4 +99,11 @@ protected void calculateUiRootPath(StringBuilder... sbUrls) {
9099
calculateUiRootCommon(sbUrl, sbUrls);
91100
}
92101

102+
@Override
103+
protected void calculateOauth2RedirectUrl(UriComponentsBuilder uriComponentsBuilder) {
104+
if (oauthPrefix == null && !swaggerUiConfigParameters.isValidUrl(swaggerUiConfigParameters.getOauth2RedirectUrl())) {
105+
this.oauthPrefix = uriComponentsBuilder.path(webfluxBasePath).path(swaggerUiConfigParameters.getUiRootPath()).path(webJarsPrefixUrl);
106+
swaggerUiConfigParameters.setOauth2RedirectUrl(this.oauthPrefix.path(swaggerUiConfigParameters.getOauth2RedirectUrl()).build().toString());
107+
}
108+
}
93109
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.ui.app18;
20+
21+
import javax.validation.Valid;
22+
import javax.validation.constraints.Size;
23+
24+
import org.springdoc.core.GroupedOpenApi;
25+
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.web.bind.annotation.GetMapping;
28+
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.RestController;
30+
31+
@RestController
32+
public class HelloController {
33+
34+
@GetMapping(value = "/persons")
35+
public void persons(@Valid @RequestParam @Size(min = 4, max = 6) String name) {
36+
37+
}
38+
39+
@Bean
40+
public GroupedOpenApi userOpenApi() {
41+
return GroupedOpenApi.builder()
42+
.group("users")
43+
.packagesToScan("test.org.springdoc.api.app145")
44+
.build();
45+
}
46+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.ui.app18;
20+
21+
import javax.annotation.PostConstruct;
22+
23+
import org.junit.jupiter.api.Test;
24+
import reactor.core.publisher.Mono;
25+
import test.org.springdoc.ui.AbstractCommonTest;
26+
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.test.context.SpringBootTest;
29+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
30+
import org.springframework.boot.web.server.LocalServerPort;
31+
import org.springframework.http.HttpStatus;
32+
import org.springframework.web.reactive.function.client.WebClient;
33+
34+
import static org.junit.jupiter.api.Assertions.assertTrue;
35+
import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
36+
37+
38+
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT,
39+
properties = { "spring.webflux.base-path=/test",
40+
"server.port=9018",
41+
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
42+
"springdoc.api-docs.path=/documentation/v3/api-docs",
43+
"spring.webflux.base-path=/test",
44+
"springdoc.webjars.prefix= /webjars-pref" })
45+
class SpringDocApp18Test extends AbstractCommonTest {
46+
47+
@LocalServerPort
48+
private int port;
49+
50+
private WebClient webClient;
51+
52+
@SpringBootApplication
53+
static class SpringDocTestApp {}
54+
55+
@PostConstruct
56+
void init(){
57+
webClient = WebClient.builder().baseUrl("http://localhost:"+port)
58+
.build();
59+
}
60+
61+
@Test
62+
public void testIndexActuator() throws Exception {
63+
HttpStatus httpStatusMono = webClient.get().uri("/test/documentation/swagger-ui.html")
64+
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
65+
assertTrue(httpStatusMono.equals(HttpStatus.TEMPORARY_REDIRECT));
66+
67+
httpStatusMono = webClient.get().uri("/test/documentation/webjars-pref/swagger-ui/index.html")
68+
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
69+
assertTrue(httpStatusMono.equals(HttpStatus.OK));
70+
71+
String contentAsString = webClient.get().uri("/test/documentation/v3/api-docs/swagger-config").retrieve()
72+
.bodyToMono(String.class).block();
73+
String expected = getContent("results/app18-1.json");
74+
assertEquals(expected, contentAsString, true);
75+
}
76+
77+
78+
79+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.ui.app19;
20+
21+
import javax.validation.Valid;
22+
import javax.validation.constraints.Size;
23+
24+
import org.springdoc.core.GroupedOpenApi;
25+
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.web.bind.annotation.GetMapping;
28+
import org.springframework.web.bind.annotation.RequestParam;
29+
import org.springframework.web.bind.annotation.RestController;
30+
31+
@RestController
32+
public class HelloController {
33+
34+
@GetMapping(value = "/persons")
35+
public void persons(@Valid @RequestParam @Size(min = 4, max = 6) String name) {
36+
37+
}
38+
39+
@Bean
40+
public GroupedOpenApi userOpenApi() {
41+
return GroupedOpenApi.builder()
42+
.group("users")
43+
.packagesToScan("test.org.springdoc.api.app145")
44+
.build();
45+
}
46+
}

0 commit comments

Comments
 (0)