3434import io .swagger .v3 .parser .ResolverCache ;
3535import io .swagger .v3 .parser .models .RefFormat ;
3636import io .swagger .v3 .parser .models .RefType ;
37+ import io .swagger .v3 .parser .util .RefUtils ;
3738
3839import org .apache .commons .io .FilenameUtils ;
3940import org .apache .commons .lang3 .StringUtils ;
@@ -92,6 +93,21 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
9293 return renamedRef ;
9394 }
9495
96+ RefFormat format = computeRefFormat ($ref );
97+ String originalRef = $ref ;
98+ if (format .equals (RefFormat .RELATIVE )) {
99+ String normalizedRef = "./" + Paths .get ($ref ).normalize ().toString ();
100+ if (!normalizedRef .equals ($ref )) {
101+ System .out .println ("Normalized " + $ref + " to " + normalizedRef );
102+ renamedRef = cache .getRenamedRef ($ref );
103+ if (renamedRef != null ) {
104+ return renamedRef ;
105+ } else {
106+ $ref = normalizedRef ;
107+ }
108+ }
109+ }
110+
95111 final Schema schema = cache .loadRef ($ref , refFormat , Schema .class );
96112
97113 if (schema == null ) {
@@ -114,6 +130,9 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
114130 final String possiblyConflictingDefinitionName = computeDefinitionName ($ref );
115131 newRef = finalNameRec (schemas , possiblyConflictingDefinitionName , schema , 0 );
116132 cache .putRenamedRef ($ref , newRef );
133+ if (!$ref .equals (originalRef )) {
134+ cache .putRenamedRef (originalRef , newRef );
135+ }
117136 Schema existingModel = schemas .get (newRef );
118137 if (existingModel != null && existingModel .get$ref () != null ) {
119138 // use the new model
0 commit comments