Skip to content

Commit

Permalink
coderabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Thurner committed Aug 16, 2024
1 parent 0af1eb4 commit eef32ad
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,7 @@ private static void analyzeRestCalls() {
for (RestCallInformation restCall : restCallFile.getRestCalls()) {
Optional<EndpointInformation> matchingEndpoint = Optional.empty();

for (EndpointClassInformation endpointClass : endpointClasses) {
for (EndpointInformation endpoint : endpointClass.getEndpoints()) {
String endpointURI = endpoint.buildComparableEndpointUri();
String restCallURI = restCall.buildComparableRestCallUri();
if (endpointURI.equals(restCallURI) && endpoint.getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoint = Optional.of(endpoint);
}
else if (endpointURI.endsWith("*") && restCallURI.startsWith(endpointURI.substring(0, endpointURI.length() - 1))
&& endpoint.getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoint = Optional.of(endpoint);
}
}
}
matchingEndpoint = findMatchingEndpoint(restCall, endpointClasses, matchingEndpoint);

if (matchingEndpoint.isPresent()) {
restCallsWithMatchingEndpoint.add(new RestCallWithMatchingEndpoint(matchingEndpoint.get(), restCall, restCall.getFileName()));
Expand All @@ -78,6 +66,34 @@ else if (endpointURI.endsWith("*") && restCallURI.startsWith(endpointURI.substri
}
}

/**
* Finds a matching endpoint for a given REST call.
*
* This method iterates over a list of endpoint classes and their endpoints to find a match for the provided REST call.
* A match is determined based on the URI and HTTP method of the endpoint and the REST call.
*
* @param restCall The REST call information to match.
* @param endpointClasses The list of endpoint classes containing endpoint information.
* @param matchingEndpoint An optional containing the matching endpoint if found.
* @return An optional containing the matching endpoint if found, otherwise an empty optional.
*/
private static Optional<EndpointInformation> findMatchingEndpoint(RestCallInformation restCall, List<EndpointClassInformation> endpointClasses, Optional<EndpointInformation> matchingEndpoint) {
for (EndpointClassInformation endpointClass : endpointClasses) {
for (EndpointInformation endpoint : endpointClass.getEndpoints()) {
String endpointURI = endpoint.buildComparableEndpointUri();
String restCallURI = restCall.buildComparableRestCallUri();
if (endpointURI.equals(restCallURI) && endpoint.getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoint = Optional.of(endpoint);
}
else if (endpointURI.endsWith("*") && restCallURI.startsWith(endpointURI.substring(0, endpointURI.length() - 1))
&& endpoint.getHttpMethod().toLowerCase().equals(restCall.getMethod().toLowerCase())) {
matchingEndpoint = Optional.of(endpoint);
}
}
}
return matchingEndpoint;
}

/**
* Prints the endpoint analysis result.
*
Expand Down

0 comments on commit eef32ad

Please sign in to comment.