|
1 | 1 | package org.springdoc.ui; |
2 | 2 |
|
3 | | -import java.io.File; |
| 3 | +import java.nio.file.Path; |
| 4 | +import java.nio.file.Paths; |
4 | 5 |
|
5 | 6 | import org.springdoc.core.properties.SwaggerUiConfigProperties; |
6 | 7 |
|
@@ -30,46 +31,18 @@ public AbstractSwaggerResourceResolver(SwaggerUiConfigProperties swaggerUiConfig |
30 | 31 | /** |
31 | 32 | * Find web jar resource path string. |
32 | 33 | * |
33 | | - * @param path the path |
| 34 | + * @param pathStr the path |
34 | 35 | * @return the string |
35 | 36 | */ |
36 | 37 | @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(); |
74 | 46 | } |
| 47 | + |
75 | 48 | } |
0 commit comments