Skip to content

Commit 3cb307a

Browse files
committed
Simplify building from context path using ServletRequestPathUtils
1 parent cc1a4e5 commit 3cb307a

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected Map<String, Object> getSwaggerUiConfig(ServerWebExchange exchange) {
110110
* @param swaggerUiConfigParameters the swagger ui config parameters
111111
* @param exchange the exchange
112112
*/
113-
void buildFromCurrentContextPath(SwaggerUiConfigParameters swaggerUiConfigParameters, ServerWebExchange exchange) {
113+
protected void buildFromCurrentContextPath(SwaggerUiConfigParameters swaggerUiConfigParameters, ServerWebExchange exchange) {
114114
super.init(swaggerUiConfigParameters);
115115

116116
String contextPath = exchange.getRequest().getPath().contextPath().value();

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
import org.springframework.http.HttpStatus;
4242
import org.springframework.http.ResponseEntity;
4343
import org.springframework.web.util.ForwardedHeaderUtils;
44+
import org.springframework.web.util.ServletRequestPathUtils;
4445
import org.springframework.web.util.UriComponentsBuilder;
45-
import org.springframework.web.util.UrlPathHelper;
4646

4747
/**
4848
* The type Swagger welcome common.
@@ -51,8 +51,6 @@
5151
*/
5252
public abstract class SwaggerWelcomeCommon extends AbstractSwaggerWelcome {
5353

54-
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
55-
5654
/**
5755
* Instantiates a new Abstract swagger welcome.
5856
*
@@ -112,11 +110,11 @@ protected void calculateOauth2RedirectUrl(SwaggerUiConfigParameters swaggerUiCon
112110
* @param swaggerUiConfigParameters the swagger ui config parameters
113111
* @param request the request
114112
*/
115-
void buildFromCurrentContextPath(SwaggerUiConfigParameters swaggerUiConfigParameters, HttpServletRequest request) {
113+
protected void buildFromCurrentContextPath(SwaggerUiConfigParameters swaggerUiConfigParameters, HttpServletRequest request) {
116114
super.init(swaggerUiConfigParameters);
117115

118-
String pathWithinServletMapping = urlPathHelper.getPathWithinServletMapping(request);
119-
String contextPath = request.getContextPath() + (!StringUtils.isBlank(pathWithinServletMapping) ? request.getServletPath() : "");
116+
String servletPath = ServletRequestPathUtils.getServletPathPrefix(request);
117+
String contextPath = request.getContextPath() + (servletPath != null ? servletPath : "");
120118
swaggerUiConfigParameters.setContextPath(contextPath);
121119

122120
URI uri = URI.create(request.getRequestURL().toString());

0 commit comments

Comments
 (0)