Skip to content

Commit f09afb9

Browse files
committed
Fix WebJar resource handler mappings for Swagger UI resources. Fixes #3146
1 parent e6be796 commit f09afb9

33 files changed

Lines changed: 1022 additions & 263 deletions

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-common/src/main/java/org/springdoc/core/utils/Constants.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626

2727
package org.springdoc.core.utils;
2828

29-
import org.springframework.util.ResourceUtils;
30-
3129
import static org.springframework.util.AntPathMatcher.DEFAULT_PATH_SEPARATOR;
30+
import static org.springframework.util.ResourceUtils.CLASSPATH_URL_PREFIX;
3231

3332
/**
3433
* The type Constants.
@@ -70,7 +69,7 @@ public final class Constants {
7069
/**
7170
* The constant SWAGGER_CONFIG_URL.
7271
*/
73-
public static final String SWAGGER_CONFIG_URL = API_DOCS_URL + DEFAULT_PATH_SEPARATOR + SWAGGER_CONFIG_FILE;
72+
public static final String SWAGGER_CONFIG_URL = API_DOCS_URL + "/" + SWAGGER_CONFIG_FILE;
7473

7574
/**
7675
* The constant YAML.
@@ -178,20 +177,24 @@ public final class Constants {
178177
public static final String SPRINGDOC_ACTUATOR_DOC_DESCRIPTION = "Spring Boot Actuator Web API Documentation";
179178

180179
/**
181-
* The constant DEFAULT_WEB_JARS_PREFIX_URL.
180+
* The constant CLASSPATH_RESOURCE_LOCATION.
182181
*/
183-
public static final String DEFAULT_WEB_JARS_PREFIX_URL = "/webjars";
182+
public static final String CLASSPATH_RESOURCE_LOCATION = CLASSPATH_URL_PREFIX + "META-INF" + DEFAULT_PATH_SEPARATOR + "resources" + DEFAULT_PATH_SEPARATOR;
184183

185184
/**
186-
* The constant CLASSPATH_RESOURCE_LOCATION.
185+
* The constant WEBJARS_RESOURCE_LOCATION.
187186
*/
188-
public static final String CLASSPATH_RESOURCE_LOCATION = ResourceUtils.CLASSPATH_URL_PREFIX + "/META-INF/resources";
187+
public static final String WEBJARS_RESOURCE_LOCATION = CLASSPATH_RESOURCE_LOCATION + "webjars" + DEFAULT_PATH_SEPARATOR;
189188

189+
/**
190+
* The constant SWAGGER_UI_WEBJAR_NAME.
191+
*/
192+
public static final String SWAGGER_UI_WEBJAR_NAME = "swagger-ui";
190193

191194
/**
192195
* The constant SWAGGER_UI_PREFIX.
193196
*/
194-
public static final String SWAGGER_UI_PREFIX = "/swagger-ui";
197+
public static final String SWAGGER_UI_PREFIX = "/" + SWAGGER_UI_WEBJAR_NAME;
195198

196199
/**
197200
* The constant INDEX_PAGE.
@@ -231,7 +234,7 @@ public final class Constants {
231234
/**
232235
* The constant DEFAULT_SWAGGER_UI_PATH.
233236
*/
234-
public static final String DEFAULT_SWAGGER_UI_PATH = DEFAULT_PATH_SEPARATOR + "swagger-ui.html";
237+
public static final String DEFAULT_SWAGGER_UI_PATH = "/swagger-ui.html";
235238

236239
/**
237240
* The constant SWAGGER_UI_PATH.
@@ -363,6 +366,21 @@ public final class Constants {
363366
*/
364367
public static final String ALL_PATTERN = "/**";
365368

369+
/**
370+
* The constant SWAGGER_UI_WEBJAR_NAME_PATTERN.
371+
*/
372+
public static final String SWAGGER_UI_WEBJAR_NAME_PATTERN = "/*" + SWAGGER_UI_WEBJAR_NAME;
373+
374+
/**
375+
* The constant SWAGGER_INITIALIZER_PATTERN.
376+
*/
377+
public static final String SWAGGER_INITIALIZER_PATTERN = "/*" + SWAGGER_INITIALIZER_JS;
378+
379+
/**
380+
* The constant SWAGGER_RESOURCE_CACHE_NAME.
381+
*/
382+
public static final String SWAGGER_RESOURCE_CACHE_NAME = "swagger-resource-chain-cache";
383+
366384
/**
367385
* The constant HEALTH_PATTERN.
368386
*/
@@ -397,7 +415,7 @@ public final class Constants {
397415
/**
398416
* The constant DEFAULT_YAML_API_DOCS_ACTUATOR_PATH.
399417
*/
400-
public static final String DEFAULT_YAML_API_DOCS_ACTUATOR_PATH = DEFAULT_PATH_SEPARATOR + YAML;
418+
public static final String DEFAULT_YAML_API_DOCS_ACTUATOR_PATH = "/" + YAML;
401419

402420
/**
403421
* The constant ACTUATOR_DEFAULT_GROUP.

0 commit comments

Comments
 (0)