@@ -391,9 +391,39 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
391
391
}
392
392
}
393
393
newRef = possiblyConflictingDefinitionName ;
394
- openAPI .getComponents ().addResponses (newRef , response );
395
394
cache .putRenamedRef ($ref , newRef );
396
395
396
+ if (existingResponse == null ) {
397
+ // don't overwrite existing model reference
398
+ openAPI .getComponents ().addResponses (newRef , response );
399
+ cache .addReferencedKey (newRef );
400
+
401
+ String file = $ref .split ("#/" )[0 ];
402
+ if (response .get$ref () != null ) {
403
+ RefFormat format = computeRefFormat (response .get$ref ());
404
+ if (isAnExternalRefFormat (format )) {
405
+ String fullRef = response .get$ref ();
406
+ if (!format .equals (RefFormat .URL )) {
407
+ String parent = file .substring (0 , file .lastIndexOf ('/' ));
408
+ if (!parent .isEmpty ()) {
409
+ if (fullRef .contains ("#/" )) {
410
+ String [] parts = fullRef .split ("#/" );
411
+ String fullRefFilePart = parts [0 ];
412
+ String fullRefInternalRefPart = parts [1 ];
413
+ fullRef = Paths .get (parent , fullRefFilePart ).normalize ().toString () + "#/" + fullRefInternalRefPart ;
414
+ } else {
415
+ fullRef = Paths .get (parent , fullRef ).normalize ().toString ();
416
+ }
417
+ }
418
+
419
+ }
420
+ response .set$ref (processRefToExternalResponse (fullRef , format ));
421
+ } else {
422
+ processRefToExternalResponse (file + response .get$ref (), RefFormat .RELATIVE );
423
+ }
424
+ }
425
+ }
426
+
397
427
if (response != null ) {
398
428
if (response .getContent () != null ){
399
429
processRefContent (response .getContent (), $ref );
0 commit comments