Skip to content

Commit 5cf6ab5

Browse files
committed
Remove springdoc.webjars.prefix property
1 parent 4b95d0e commit 5cf6ab5

File tree

10 files changed

+25
-106
lines changed

10 files changed

+25
-106
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/properties/AbstractSwaggerUiConfigProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public abstract class AbstractSwaggerUiConfigProperties {
4949

5050
/**
51-
* The path for the Swagger UI pages to load. Will redirect to the springdoc.webjars.prefix property.
51+
* The path for the Swagger UI pages to load.
5252
*/
5353
protected String path = Constants.DEFAULT_SWAGGER_UI_PATH;
5454

@@ -814,4 +814,4 @@ public String toString() {
814814
}
815815
}
816816

817-
}
817+
}

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/properties/SpringDocConfigProperties.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.context.annotation.Lazy;
4545
import org.springframework.http.MediaType;
4646

47-
import static org.springdoc.core.utils.Constants.DEFAULT_WEB_JARS_PREFIX_URL;
4847
import static org.springdoc.core.utils.Constants.SPRINGDOC_ENABLED;
4948

5049
/**
@@ -64,11 +63,6 @@ public class SpringDocConfigProperties {
6463
*/
6564
private boolean showActuator;
6665

67-
/**
68-
* The Webjars.
69-
*/
70-
private Webjars webjars = new Webjars();
71-
7266
/**
7367
* The Api docs.
7468
*/
@@ -786,24 +780,6 @@ public void setShowActuator(boolean showActuator) {
786780
this.showActuator = showActuator;
787781
}
788782

789-
/**
790-
* Gets webjars.
791-
*
792-
* @return the webjars
793-
*/
794-
public Webjars getWebjars() {
795-
return webjars;
796-
}
797-
798-
/**
799-
* Sets webjars.
800-
*
801-
* @param webjars the webjars
802-
*/
803-
public void setWebjars(Webjars webjars) {
804-
this.webjars = webjars;
805-
}
806-
807783
/**
808784
* Gets api docs.
809785
*
@@ -1390,36 +1366,6 @@ public void setEnabled(boolean enabled) {
13901366
}
13911367
}
13921368

1393-
/**
1394-
* The type Webjars.
1395-
*
1396-
* @author bnasslahsen
1397-
*/
1398-
public static class Webjars {
1399-
/**
1400-
* The Prefix.
1401-
*/
1402-
private String prefix = DEFAULT_WEB_JARS_PREFIX_URL;
1403-
1404-
/**
1405-
* Gets prefix.
1406-
*
1407-
* @return the prefix
1408-
*/
1409-
public String getPrefix() {
1410-
return prefix;
1411-
}
1412-
1413-
/**
1414-
* Sets prefix.
1415-
*
1416-
* @param prefix the prefix
1417-
*/
1418-
public void setPrefix(String prefix) {
1419-
this.prefix = prefix;
1420-
}
1421-
}
1422-
14231369
/**
14241370
* The type Api docs.
14251371
*

springdoc-openapi-starter-webflux-ui/src/main/java/org/springdoc/webflux/ui/SwaggerWebFluxConfigurer.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
import org.springdoc.core.properties.SwaggerUiConfigProperties;
3333
import org.springdoc.core.providers.ActuatorProvider;
3434

35+
import org.springframework.http.CacheControl;
3536
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
3637
import org.springframework.web.reactive.config.WebFluxConfigurer;
3738

38-
import static org.springdoc.core.utils.Constants.ALL_PATTERN;
3939
import static org.springdoc.core.utils.Constants.CLASSPATH_RESOURCE_LOCATION;
4040
import static org.springdoc.core.utils.Constants.DEFAULT_WEB_JARS_PREFIX_URL;
41+
import static org.springdoc.core.utils.Constants.SWAGGER_INITIALIZER_JS;
4142
import static org.springdoc.core.utils.Constants.SWAGGER_UI_PREFIX;
4243
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
4344

@@ -102,28 +103,15 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
102103
if (actuatorProvider.isPresent() && actuatorProvider.get().isUseManagementPort())
103104
uiRootPath.append(actuatorProvider.get().getBasePath());
104105

105-
String webjarsPrefix = springDocConfigProperties.getWebjars().getPrefix();
106-
String resourcePath, swaggerUiPrefix, swaggerUiWebjarsPrefix;
107-
108-
if (DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix)) {
109-
swaggerUiPrefix = SWAGGER_UI_PREFIX;
110-
resourcePath = webjarsPrefix + SWAGGER_UI_PREFIX + DEFAULT_PATH_SEPARATOR + swaggerUiConfigProperties.getVersion() + DEFAULT_PATH_SEPARATOR;
111-
swaggerUiWebjarsPrefix = webjarsPrefix + swaggerUiPrefix;
112-
}
113-
else {
114-
swaggerUiPrefix = webjarsPrefix;
115-
resourcePath = DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR;
116-
swaggerUiWebjarsPrefix = swaggerUiPrefix;
117-
}
118-
119-
registry.addResourceHandler(uiRootPath + swaggerUiWebjarsPrefix + ALL_PATTERN)
120-
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + resourcePath)
106+
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/*" + SWAGGER_INITIALIZER_JS)
107+
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
108+
.setCacheControl(CacheControl.noStore())
121109
.resourceChain(false)
122110
.addResolver(swaggerResourceResolver)
123111
.addTransformer(swaggerIndexTransformer);
124112

125-
registry.addResourceHandler(uiRootPath + swaggerUiPrefix + ALL_PATTERN)
126-
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + resourcePath)
113+
registry.addResourceHandler(uiRootPath + SWAGGER_UI_PREFIX + "*/**")
114+
.addResourceLocations(CLASSPATH_RESOURCE_LOCATION + DEFAULT_WEB_JARS_PREFIX_URL + DEFAULT_PATH_SEPARATOR)
127115
.resourceChain(false)
128116
.addResolver(swaggerResourceResolver)
129117
.addTransformer(swaggerIndexTransformer);

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

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import org.springframework.web.util.ForwardedHeaderUtils;
4343
import org.springframework.web.util.UriComponentsBuilder;
4444

45-
import static org.springdoc.core.utils.Constants.DEFAULT_WEB_JARS_PREFIX_URL;
46-
4745
/**
4846
* The type Swagger welcome common.
4947
*
@@ -72,15 +70,12 @@ protected SwaggerWelcomeCommon(SwaggerUiConfigProperties swaggerUiConfig, Spring
7270
protected Mono<Void> redirectToUi(ServerHttpRequest request, ServerHttpResponse response) {
7371
SwaggerUiConfigParameters swaggerUiConfigParameters = new SwaggerUiConfigParameters(swaggerUiConfig);
7472
buildFromCurrentContextPath(swaggerUiConfigParameters, request);
75-
String webjarsPrefix = springDocConfigProperties.getWebjars().getPrefix();
76-
String additionalPrefix = DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix) ? "" : webjarsPrefix;
77-
String sbUrl = swaggerUiConfigParameters.getContextPath()
78-
+ swaggerUiConfigParameters.getUiRootPath()
79-
+ additionalPrefix
80-
+ getSwaggerUiUrl();
73+
String sbUrl = swaggerUiConfigParameters.getContextPath() + swaggerUiConfigParameters.getUiRootPath() + getSwaggerUiUrl();
8174
UriComponentsBuilder uriBuilder = getUriComponentsBuilder(swaggerUiConfigParameters, sbUrl);
75+
8276
// forward all queryParams from original request
8377
request.getQueryParams().forEach(uriBuilder::queryParam);
78+
8479
response.setStatusCode(HttpStatus.FOUND);
8580
response.getHeaders().setLocation(URI.create(uriBuilder.build().encode().toString()));
8681
return response.setComplete();
@@ -89,16 +84,9 @@ protected Mono<Void> redirectToUi(ServerHttpRequest request, ServerHttpResponse
8984
@Override
9085
protected void calculateOauth2RedirectUrl(SwaggerUiConfigParameters swaggerUiConfigParameters, UriComponentsBuilder uriComponentsBuilder) {
9186
if (StringUtils.isBlank(swaggerUiConfig.getOauth2RedirectUrl()) || !swaggerUiConfigParameters.isValidUrl(swaggerUiConfig.getOauth2RedirectUrl())) {
92-
String webjarsPrefix = springDocConfigProperties.getWebjars().getPrefix();
93-
String additionalPath = DEFAULT_WEB_JARS_PREFIX_URL.equals(webjarsPrefix) ? "" : webjarsPrefix;
94-
swaggerUiConfigParameters.setOauth2RedirectUrl(
95-
uriComponentsBuilder
96-
.path(swaggerUiConfigParameters.getUiRootPath())
97-
.path(additionalPath)
98-
.path(getOauth2RedirectUrl())
99-
.build()
100-
.toString()
101-
);
87+
swaggerUiConfigParameters.setOauth2RedirectUrl(uriComponentsBuilder
88+
.path(swaggerUiConfigParameters.getUiRootPath())
89+
.path(getOauth2RedirectUrl()).build().toString());
10290
}
10391
}
10492

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app18/SpringDocApp18Test.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
properties = { "spring.webflux.base-path=/test",
4646
"server.port=9218",
4747
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
48-
"springdoc.api-docs.path=/documentation/v3/api-docs",
49-
"springdoc.webjars.prefix= /webjars-pref" })
48+
"springdoc.api-docs.path=/documentation/v3/api-docs" })
5049
class SpringDocApp18Test extends AbstractCommonTest {
5150

5251
@LocalServerPort
@@ -66,7 +65,7 @@ void testIndex() throws Exception {
6665
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
6766
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
6867

69-
httpStatusMono = webClient.get().uri("/test/documentation/webjars-pref/swagger-ui/index.html")
68+
httpStatusMono = webClient.get().uri("/test/documentation/swagger-ui/index.html")
7069
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
7170
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);
7271

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app3/SpringDocApp3RedirectWithPrefixTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
@TestPropertySource(properties = {
3030
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
31-
"springdoc.api-docs.path=/documentation/v3/api-docs",
32-
"springdoc.webjars.prefix= /webjars-pref"
31+
"springdoc.api-docs.path=/documentation/v3/api-docs"
3332
})
3433
public class SpringDocApp3RedirectWithPrefixTest extends AbstractSpringDocTest {
3534

@@ -38,8 +37,8 @@ void shouldRedirectWithPrefix() {
3837
WebTestClient.ResponseSpec responseSpec = webTestClient.get().uri("/documentation/swagger-ui.html").exchange()
3938
.expectStatus().isFound();
4039
responseSpec.expectHeader()
41-
.value("Location", Matchers.is("/documentation/webjars-pref/swagger-ui/index.html"));
42-
webTestClient.get().uri("/documentation/webjars-pref/swagger-ui/index.html").exchange()
40+
.value("Location", Matchers.is("/documentation/swagger-ui/index.html"));
41+
webTestClient.get().uri("/documentation/swagger-ui/index.html").exchange()
4342
.expectStatus().isOk();
4443
webTestClient.get().uri("/documentation/v3/api-docs/swagger-config").exchange()
4544
.expectStatus().isOk().expectBody().jsonPath("$.validatorUrl").isEqualTo("");

springdoc-openapi-starter-webflux-ui/src/test/java/test/org/springdoc/ui/app33/SpringDocBehindProxyBasePathTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
"server.forward-headers-strategy=framework",
4242
"server.port=9318",
4343
"springdoc.swagger-ui.path=/documentation/swagger-ui.html",
44-
"springdoc.api-docs.path=/documentation/v3/api-docs",
45-
"springdoc.webjars.prefix= /webjars-pref" })
44+
"springdoc.api-docs.path=/documentation/v3/api-docs" })
4645

4746
@Import(SpringDocConfig.class)
4847
public class SpringDocBehindProxyBasePathTest extends AbstractCommonTest {
@@ -69,7 +68,7 @@ void testIndex() throws Exception {
6968
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
7069
assertThat(httpStatusMono).isEqualTo(HttpStatus.FOUND);
7170

72-
httpStatusMono = webClient.get().uri(WEBFLUX_BASE_PATH + "/documentation/webjars-pref/swagger-ui/index.html")
71+
httpStatusMono = webClient.get().uri(WEBFLUX_BASE_PATH + "/documentation/swagger-ui/index.html")
7372
.header("X-Forwarded-Prefix", X_FORWARD_PREFIX)
7473
.exchangeToMono(clientResponse -> Mono.just(clientResponse.statusCode())).block();
7574
assertThat(httpStatusMono).isEqualTo(HttpStatus.OK);

springdoc-openapi-starter-webflux-ui/src/test/resources/results/app18-1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"configUrl": "/test/documentation/v3/api-docs/swagger-config",
3-
"oauth2RedirectUrl": "http://localhost:9218/test/documentation/webjars-pref/swagger-ui/oauth2-redirect.html",
3+
"oauth2RedirectUrl": "http://localhost:9218/test/documentation/swagger-ui/oauth2-redirect.html",
44
"urls": [
55
{
66
"url": "/test/documentation/v3/api-docs/users",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"configUrl": "/path/prefix/documentation/v3/api-docs/swagger-config",
3-
"oauth2RedirectUrl": "http://localhost:9318/path/prefix/documentation/webjars-pref/swagger-ui/oauth2-redirect.html",
3+
"oauth2RedirectUrl": "http://localhost:9318/path/prefix/documentation/swagger-ui/oauth2-redirect.html",
44
"url": "/path/prefix/documentation/v3/api-docs",
55
"validatorUrl": ""
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"configUrl": "/path/prefix/test/documentation/v3/api-docs/swagger-config",
3-
"oauth2RedirectUrl": "http://localhost:9318/path/prefix/test/documentation/webjars-pref/swagger-ui/oauth2-redirect.html",
3+
"oauth2RedirectUrl": "http://localhost:9318/path/prefix/test/documentation/swagger-ui/oauth2-redirect.html",
44
"url": "/path/prefix/test/documentation/v3/api-docs",
55
"validatorUrl": ""
66
}

0 commit comments

Comments
 (0)