Skip to content

Commit 1d94e47

Browse files
committed
Refactoring AbstractSwaggerResourceResolver.findWebJarResourcePath. related to #2366
1 parent 5ec10ac commit 1d94e47

File tree

1 file changed

+12
-39
lines changed

1 file changed

+12
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.springdoc.ui;
22

3-
import java.io.File;
3+
import java.nio.file.Path;
4+
import java.nio.file.Paths;
45

56
import org.springdoc.core.properties.SwaggerUiConfigProperties;
67

@@ -30,46 +31,18 @@ public AbstractSwaggerResourceResolver(SwaggerUiConfigProperties swaggerUiConfig
3031
/**
3132
* Find web jar resource path string.
3233
*
33-
* @param path the path
34+
* @param pathStr the path
3435
* @return the string
3536
*/
3637
@Nullable
37-
protected String findWebJarResourcePath(String path) {
38-
String webjar = webjar(path);
39-
if (webjar.length() > 0 && !path.equals(webjar)) {
40-
String version = swaggerUiConfigProperties.getVersion();
41-
if (version != null) {
42-
String partialPath = path(webjar, path);
43-
return webjar + File.separator + version + File.separator + partialPath;
44-
}
45-
}
46-
return null;
47-
}
48-
49-
/**
50-
* Webjar string.
51-
*
52-
* @param path the path
53-
* @return the string
54-
*/
55-
private String webjar(String path) {
56-
int startOffset = (path.startsWith("/") ? 1 : 0);
57-
int endOffset = path.indexOf('/', 1);
58-
return endOffset != -1 ? path.substring(startOffset, endOffset) : path;
59-
}
60-
61-
62-
/**
63-
* Path string.
64-
*
65-
* @param webjar the webjar
66-
* @param path the path
67-
* @return the string
68-
*/
69-
private String path(String webjar, String path) {
70-
if (path.startsWith(webjar) && path.length() > webjar.length()) {
71-
path = path.substring(webjar.length() + 1);
72-
}
73-
return path;
38+
protected String findWebJarResourcePath(String pathStr) {
39+
Path path = Paths.get(pathStr);
40+
if (path.getNameCount() < 2) return null;
41+
String version = swaggerUiConfigProperties.getVersion();
42+
if (version == null) return null;
43+
Path first = path.getName(0);
44+
Path rest = path.subpath(1, path.getNameCount());
45+
return first.resolve(version).resolve(rest).toString();
7446
}
47+
7548
}

0 commit comments

Comments
 (0)