Skip to content

Commit b6f9c1d

Browse files
committed
A question about resource path processing. Fixes #2348
1 parent a1de9ad commit b6f9c1d

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,29 @@ public SwaggerResourceResolver(SwaggerUiConfigProperties swaggerUiConfigProperti
3030

3131
@Override
3232
public Mono<Resource> resolveResource(ServerWebExchange exchange, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
33-
Mono<Resource> resolved = chain.resolveResource(exchange, requestPath, locations);
34-
if (!Mono.empty().equals(resolved)) {
35-
String webJarResourcePath = findWebJarResourcePath(requestPath);
36-
if (webJarResourcePath != null)
37-
return chain.resolveResource(exchange, webJarResourcePath, locations);
38-
}
39-
return resolved;
33+
return chain.resolveResource(exchange, requestPath, locations)
34+
.switchIfEmpty(Mono.defer(() -> {
35+
String webJarsResourcePath = findWebJarResourcePath(requestPath);
36+
if (webJarsResourcePath != null) {
37+
return chain.resolveResource(exchange, webJarsResourcePath, locations);
38+
}
39+
else {
40+
return Mono.empty();
41+
}
42+
}));
4043
}
4144

4245
@Override
43-
public Mono<String> resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain) {
44-
Mono<String> path = chain.resolveUrlPath(resourcePath, locations);
45-
if (!Mono.empty().equals(path)) {
46-
String webJarResourcePath = findWebJarResourcePath(resourcePath);
47-
if (webJarResourcePath != null)
48-
return chain.resolveUrlPath(webJarResourcePath, locations);
49-
}
50-
return path;
46+
public Mono<String> resolveUrlPath(String resourceUrlPath, List<? extends Resource> locations, ResourceResolverChain chain) {
47+
return chain.resolveUrlPath(resourceUrlPath, locations)
48+
.switchIfEmpty(Mono.defer(() -> {
49+
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
50+
if (webJarResourcePath != null) {
51+
return chain.resolveUrlPath(webJarResourcePath, locations);
52+
}
53+
else {
54+
return Mono.empty();
55+
}
56+
}));
5157
}
5258
}

0 commit comments

Comments
 (0)