Skip to content

Commit

Permalink
Merge pull request #1642 from ayeshLK/master
Browse files Browse the repository at this point in the history
Fix logic issue in selecting the relevant HATEOAS resource when resource method is not configured
  • Loading branch information
ayeshLK authored Apr 3, 2024
2 parents 4fbd0e6 + cb6e4d2 commit de5adbb
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private Map<String, Link> mapHateoasLinksToOpenApiLinks(Service hateoasService,
.filter(resources -> link.getResourceName().equals(resources.getKey()))
.findFirst()
.flatMap(hateoasResourceMapping -> hateoasResourceMapping.getValue().stream()
.filter(hateoasRes -> link.getResourceMethod().equals(hateoasRes.resourceMethod()))
.filter(hateoasRes -> isValidResource(link, hateoasRes))
.findFirst());
if (resource.isEmpty()) {
continue;
Expand All @@ -187,4 +187,13 @@ private Map<String, Link> mapHateoasLinksToOpenApiLinks(Service hateoasService,
}
return hateoasLinks;
}

private boolean isValidResource(HateoasLink link, Resource currentResource) {
// If the `resourceMethod` is not provided that means there will be only one mapping for the resource,
// by returning `true` here will make sure the first resource matching the resource-name would be selected
if (Objects.isNull(link.getResourceMethod())) {
return true;
}
return currentResource.resourceMethod().equals(link.getResourceMethod());
}
}

0 comments on commit de5adbb

Please sign in to comment.