@@ -256,30 +256,17 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
256
256
cache .putRenamedRef ($ref , newRef );
257
257
258
258
if (response != null ) {
259
-
260
- String file = $ref .split ("#/" )[0 ];
261
-
262
- Schema schema = null ;
263
259
if (response .getContent () != null ){
264
- Map <String , MediaType > content = response .getContent ();
265
- for ( String mediaName : content .keySet ()) {
266
- MediaType mediaType = content .get (mediaName );
267
- if (mediaType .getSchema ()!= null ) {
268
- schema = mediaType .getSchema ();
269
- if (schema .get$ref () != null ) {
270
- RefFormat ref = computeRefFormat (schema .get$ref ());
271
- if (isAnExternalRefFormat (ref )) {
272
- processRefSchema (schema , $ref );
273
- } else {
274
- processRefToExternalSchema (file + schema .get$ref (), RefFormat .RELATIVE );
275
- }
276
- }else {
277
- processSchema (schema ,file );
278
- }
279
- }
280
- }
260
+ processRefContent (response .getContent (), $ref );
261
+ }
262
+ if (response .getHeaders () != null ){
263
+ processRefHeaders (response .getHeaders (), $ref );
264
+ }
265
+ if (response .getLinks () != null ){
266
+ processRefLinks (response .getLinks (), $ref );
281
267
}
282
268
}
269
+
283
270
return newRef ;
284
271
}
285
272
@@ -396,6 +383,15 @@ public String processRefToExternalHeader(String $ref, RefFormat refFormat) {
396
383
}
397
384
}
398
385
386
+ if (header != null ) {
387
+ if (header .getContent () != null ){
388
+ processRefContent (header .getContent (), $ref );
389
+ }
390
+ if (header .getSchema () != null ){
391
+ processRefSchemaObject (header .getSchema (), $ref );
392
+ }
393
+ }
394
+
399
395
return newRef ;
400
396
}
401
397
@@ -628,6 +624,15 @@ public String processRefToExternalParameter(String $ref, RefFormat refFormat) {
628
624
}
629
625
}
630
626
627
+ if (parameter != null ) {
628
+ if (parameter .getContent () != null ){
629
+ processRefContent (parameter .getContent (), $ref );
630
+ }
631
+ if (parameter .getSchema () != null ){
632
+ processRefSchemaObject (parameter .getSchema (), $ref );
633
+ }
634
+ }
635
+
631
636
return newRef ;
632
637
}
633
638
@@ -691,6 +696,56 @@ public String processRefToExternalCallback(String $ref, RefFormat refFormat) {
691
696
return newRef ;
692
697
}
693
698
699
+ private void processRefContent (Map <String , MediaType > content , String $ref ) {
700
+ for (MediaType mediaType : content .values ()) {
701
+ if (mediaType .getSchema () != null ) {
702
+ processRefSchemaObject (mediaType .getSchema (), $ref );
703
+ }
704
+ }
705
+ }
706
+
707
+ private void processRefSchemaObject (Schema schema , String $ref ) {
708
+ String file = $ref .split ("#/" )[0 ];
709
+ if (schema .get$ref () != null ) {
710
+ RefFormat ref = computeRefFormat (schema .get$ref ());
711
+ if (isAnExternalRefFormat (ref )) {
712
+ processRefSchema (schema , $ref );
713
+ } else {
714
+ processRefToExternalSchema (file + schema .get$ref (), RefFormat .RELATIVE );
715
+ }
716
+ }else {
717
+ processSchema (schema ,file );
718
+ }
719
+ }
720
+
721
+ private void processRefHeaders (Map <String , Header > headers , String $ref ) {
722
+ String file = $ref .split ("#/" )[0 ];
723
+ for (Header header : headers .values ()) {
724
+ if (header .get$ref () != null ) {
725
+ RefFormat ref = computeRefFormat (header .get$ref ());
726
+ if (isAnExternalRefFormat (ref )) {
727
+ processRefHeader (header , $ref );
728
+ } else {
729
+ processRefToExternalHeader (file + header .get$ref (), RefFormat .RELATIVE );
730
+ }
731
+ }
732
+ }
733
+ }
734
+
735
+ private void processRefLinks (Map <String , Link > links , String $ref ) {
736
+ String file = $ref .split ("#/" )[0 ];
737
+ for (Link link : links .values ()) {
738
+ if (link .get$ref () != null ) {
739
+ RefFormat ref = computeRefFormat (link .get$ref ());
740
+ if (isAnExternalRefFormat (ref )) {
741
+ processRefLink (link , $ref );
742
+ } else {
743
+ processRefToExternalLink (file + link .get$ref (), RefFormat .RELATIVE );
744
+ }
745
+ }
746
+ }
747
+ }
748
+
694
749
private void processRefSchema (Schema subRef , String externalFile ) {
695
750
RefFormat format = computeRefFormat (subRef .get$ref ());
696
751
@@ -716,6 +771,45 @@ protected String constructRef(Schema refProperty, String rootLocation) {
716
771
return join (rootLocation , ref );
717
772
}
718
773
774
+ private void processRefHeader (Header subRef , String externalFile ) {
775
+ RefFormat format = computeRefFormat (subRef .get$ref ());
776
+
777
+ if (!isAnExternalRefFormat (format )) {
778
+ subRef .set$ref (RefType .SCHEMAS .getInternalPrefix ()+ processRefToExternalSchema (externalFile + subRef .get$ref (), RefFormat .RELATIVE ));
779
+ return ;
780
+ }
781
+ String $ref = subRef .get$ref ();
782
+ String subRefExternalPath = getExternalPath (subRef .get$ref ())
783
+ .orElse (null );
784
+
785
+ if (format .equals (RefFormat .RELATIVE ) && !Objects .equals (subRefExternalPath , externalFile )) {
786
+ $ref = join (externalFile , subRef .get$ref ());
787
+ subRef .set$ref ($ref );
788
+ }else {
789
+ processRefToExternalHeader ($ref , format );
790
+ }
791
+ }
792
+
793
+ private void processRefLink (Link subRef , String externalFile ) {
794
+ RefFormat format = computeRefFormat (subRef .get$ref ());
795
+
796
+ if (!isAnExternalRefFormat (format )) {
797
+ subRef .set$ref (RefType .SCHEMAS .getInternalPrefix ()+ processRefToExternalSchema (externalFile + subRef .get$ref (), RefFormat .RELATIVE ));
798
+ return ;
799
+ }
800
+ String $ref = subRef .get$ref ();
801
+ String subRefExternalPath = getExternalPath (subRef .get$ref ())
802
+ .orElse (null );
803
+
804
+ if (format .equals (RefFormat .RELATIVE ) && !Objects .equals (subRefExternalPath , externalFile )) {
805
+ $ref = join (externalFile , subRef .get$ref ());
806
+ subRef .set$ref ($ref );
807
+ }else {
808
+ processRefToExternalLink ($ref , format );
809
+ }
810
+ }
811
+
812
+
719
813
// visible for testing
720
814
public static String join (String source , String fragment ) {
721
815
try {
0 commit comments