Skip to content

Commit 2bd4335

Browse files
committed
oas3.1 initial support - response resolution fix
1 parent 6a9df4d commit 2bd4335

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,39 @@ public String processRefToExternalResponse(String $ref, RefFormat refFormat) {
391391
}
392392
}
393393
newRef = possiblyConflictingDefinitionName;
394-
openAPI.getComponents().addResponses(newRef, response);
395394
cache.putRenamedRef($ref, newRef);
396395

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+
397427
if(response != null) {
398428
if(response.getContent() != null){
399429
processRefContent(response.getContent(), $ref);

0 commit comments

Comments
 (0)