Skip to content

Commit

Permalink
Fix swagger-api#750 by reusing ExternalRefProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Apr 28, 2024
1 parent be2301b commit 286842c
Showing 1 changed file with 2 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.models.auth.AuthorizationValue;
import io.swagger.models.refs.RefFormat;
import io.swagger.parser.processors.ExternalRefProcessor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -80,45 +81,7 @@ public static String readExternalUrlRef(String file, RefFormat refFormat, List<A
}

public static String buildUrl(String rootPath, String relativePath) {
String[] rootPathParts = rootPath.split("/");
String [] relPathParts = relativePath.split("/");

if(rootPath == null || relativePath == null) {
return null;
}

int trimRoot = 0;
int trimRel = 0;

if(!"".equals(rootPathParts[rootPathParts.length - 1])) {
trimRoot = 1;
}
for(int i = 0; i < rootPathParts.length; i++) {
if("".equals(rootPathParts[i])) {
trimRel += 1;
}
else {
break;
}
}
for(int i = 0; i < relPathParts.length; i ++) {
if(".".equals(relPathParts[i])) {
trimRel += 1;
}
else if ("..".equals(relPathParts[i])) {
trimRel += 1;
}
}

String [] outputParts = new String[rootPathParts.length + relPathParts.length - trimRoot - trimRel];
System.arraycopy(rootPathParts, 0, outputParts, 0, rootPathParts.length - trimRoot);
System.arraycopy(relPathParts,
trimRel,
outputParts,
rootPathParts.length - trimRoot + trimRel - 1,
relPathParts.length - trimRel);

return StringUtils.join(outputParts, "/");
return ExternalRefProcessor.join(rootPath, relativePath);
}


Expand Down

0 comments on commit 286842c

Please sign in to comment.