34
34
import io .swagger .v3 .parser .ResolverCache ;
35
35
import io .swagger .v3 .parser .models .RefFormat ;
36
36
import io .swagger .v3 .parser .models .RefType ;
37
+ import io .swagger .v3 .parser .util .RefUtils ;
37
38
38
39
import org .apache .commons .io .FilenameUtils ;
39
40
import org .apache .commons .lang3 .StringUtils ;
@@ -92,6 +93,21 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
92
93
return renamedRef ;
93
94
}
94
95
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
+
95
111
final Schema schema = cache .loadRef ($ref , refFormat , Schema .class );
96
112
97
113
if (schema == null ) {
@@ -114,6 +130,9 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
114
130
final String possiblyConflictingDefinitionName = computeDefinitionName ($ref );
115
131
newRef = finalNameRec (schemas , possiblyConflictingDefinitionName , schema , 0 );
116
132
cache .putRenamedRef ($ref , newRef );
133
+ if (!$ref .equals (originalRef )) {
134
+ cache .putRenamedRef (originalRef , newRef );
135
+ }
117
136
Schema existingModel = schemas .get (newRef );
118
137
if (existingModel != null && existingModel .get$ref () != null ) {
119
138
// use the new model
0 commit comments