Skip to content

Commit

Permalink
Normalize refs to prevent schema duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Dec 20, 2024
1 parent 0f9d0c5 commit 8174b8f
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.swagger.v3.parser.ResolverCache;
import io.swagger.v3.parser.models.RefFormat;
import io.swagger.v3.parser.models.RefType;
import io.swagger.v3.parser.util.RefUtils;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -92,6 +93,18 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
return renamedRef;
}

RefFormat format = computeRefFormat($ref);
if (format.equals(RefFormat.RELATIVE)) {
String normalizedRef = Paths.get($ref).normalize().toString();
System.out.println("Normalized " + $ref + " to " + normalizedRef);
renamedRef = cache.getRenamedRef($ref);
if (renamedRef != null) {
return renamedRef;
} else {
$ref = normalizedRef;
}
}

final Schema schema = cache.loadRef($ref, refFormat, Schema.class);

if(schema == null) {
Expand Down

0 comments on commit 8174b8f

Please sign in to comment.