|
2 | 2 |
|
3 | 3 | import io.swagger.models.auth.AuthorizationValue;
|
4 | 4 | import io.swagger.models.refs.RefFormat;
|
| 5 | +import io.swagger.parser.processors.ExternalRefProcessor; |
5 | 6 | import org.apache.commons.io.FileUtils;
|
6 | 7 | import org.apache.commons.io.IOUtils;
|
7 | 8 | import org.apache.commons.lang3.StringUtils;
|
@@ -80,45 +81,7 @@ public static String readExternalUrlRef(String file, RefFormat refFormat, List<A
|
80 | 81 | }
|
81 | 82 |
|
82 | 83 | public static String buildUrl(String rootPath, String relativePath) {
|
83 |
| - String[] rootPathParts = rootPath.split("/"); |
84 |
| - String [] relPathParts = relativePath.split("/"); |
85 |
| - |
86 |
| - if(rootPath == null || relativePath == null) { |
87 |
| - return null; |
88 |
| - } |
89 |
| - |
90 |
| - int trimRoot = 0; |
91 |
| - int trimRel = 0; |
92 |
| - |
93 |
| - if(!"".equals(rootPathParts[rootPathParts.length - 1])) { |
94 |
| - trimRoot = 1; |
95 |
| - } |
96 |
| - for(int i = 0; i < rootPathParts.length; i++) { |
97 |
| - if("".equals(rootPathParts[i])) { |
98 |
| - trimRel += 1; |
99 |
| - } |
100 |
| - else { |
101 |
| - break; |
102 |
| - } |
103 |
| - } |
104 |
| - for(int i = 0; i < relPathParts.length; i ++) { |
105 |
| - if(".".equals(relPathParts[i])) { |
106 |
| - trimRel += 1; |
107 |
| - } |
108 |
| - else if ("..".equals(relPathParts[i])) { |
109 |
| - trimRel += 1; |
110 |
| - } |
111 |
| - } |
112 |
| - |
113 |
| - String [] outputParts = new String[rootPathParts.length + relPathParts.length - trimRoot - trimRel]; |
114 |
| - System.arraycopy(rootPathParts, 0, outputParts, 0, rootPathParts.length - trimRoot); |
115 |
| - System.arraycopy(relPathParts, |
116 |
| - trimRel, |
117 |
| - outputParts, |
118 |
| - rootPathParts.length - trimRoot + trimRel - 1, |
119 |
| - relPathParts.length - trimRel); |
120 |
| - |
121 |
| - return StringUtils.join(outputParts, "/"); |
| 84 | + return ExternalRefProcessor.join(rootPath, relativePath); |
122 | 85 | }
|
123 | 86 |
|
124 | 87 |
|
|
0 commit comments