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 Aug 8, 2024
1 parent fbb59c6 commit e2fd955
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -86,6 +88,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 e2fd955

Please sign in to comment.