Skip to content

Commit

Permalink
CodeRabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Thurner committed Aug 17, 2024
1 parent cdc234a commit a5f7bbc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/analysis-of-endpoint-connections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Upload parsing results
uses: actions/upload-artifact@v4
with:
name: parsing results
name: REST API Parsing Results
path: |
supporting_scripts/analysis-of-endpoint-connections/endpoints.json
supporting_scripts/analysis-of-endpoint-connections/restCalls.json
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Download JSON files
uses: actions/download-artifact@v4
with:
name: parsing results
name: REST API Parsing Results
path: supporting_scripts/analysis-of-endpoint-connections/

- name: Analyze endpoints
Expand All @@ -83,7 +83,7 @@ jobs:
- name: Upload analysis results
uses: actions/upload-artifact@v4
with:
name: analysis results
name: Endpoint and REST Call Analysis Results
path: |
supporting_scripts/analysis-of-endpoint-connections/endpointAnalysisResult.json
supporting_scripts/analysis-of-endpoint-connections/restCallAnalysisResult.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,7 @@ private static void analyzeEndpoints() {
List<RestCallInformation> matchingRestCalls = restCallMap.getOrDefault(endpointURI, new ArrayList<>());

// Check for wildcard endpoints if no exact match is found
if (matchingRestCalls.isEmpty() && endpointURI.endsWith("*")) {
for (String uri : restCallMap.keySet()) {
if (uri.startsWith(endpoint.buildComparableEndpointUri().substring(0, endpoint.buildComparableEndpointUri().length() - 1))
&& endpoint.getHttpMethod().toLowerCase().equals(restCallMap.get(uri).get(0).method().toLowerCase())) {
matchingRestCalls.addAll(restCallMap.get(uri));
}
}
}
CheckForWildcardEndpoints(endpoint, matchingRestCalls, endpointURI, restCallMap);

if (matchingRestCalls.isEmpty()) {
unusedEndpoints.add(endpoint);
Expand All @@ -89,6 +82,30 @@ private static void analyzeEndpoints() {
}
}

/**
* Checks for wildcard endpoints and adds matching REST calls to the list.
*
* This method is used to find matching REST calls for endpoints that use wildcard URIs.
* If no exact match is found for an endpoint, it checks if the endpoint URI ends with a wildcard ('*').
* It then iterates through the rest call map to find URIs that start with the same prefix as the endpoint URI
* (excluding the wildcard) and have the same HTTP method. If such URIs are found, they are added to the list of matching REST calls.
*
* @param endpoint The endpoint information to check for wildcard matches.
* @param matchingRestCalls The list of matching REST calls to be populated.
* @param endpointURI The URI of the endpoint being checked.
* @param restCallMap The map of rest call URIs to their corresponding information.
*/
private static void CheckForWildcardEndpoints(EndpointInformation endpoint, List<RestCallInformation> matchingRestCalls, String endpointURI, Map<String, List<RestCallInformation>> restCallMap) {
if (matchingRestCalls.isEmpty() && endpointURI.endsWith("*")) {
for (String uri : restCallMap.keySet()) {
if (uri.startsWith(endpoint.buildComparableEndpointUri().substring(0, endpoint.buildComparableEndpointUri().length() - 1))
&& endpoint.getHttpMethod().toLowerCase().equals(restCallMap.get(uri).get(0).method().toLowerCase())) {
matchingRestCalls.addAll(restCallMap.get(uri));
}
}
}
}

/**
* Prints the endpoint analysis result.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ private static void analyzeRestCalls() {
}
}

/**
* Checks for wildcard matches and adds matching endpoints to the list.
*
* This method is used to find matching endpoints for REST calls that use wildcard URIs.
* If no exact match is found for a REST call, it checks if the REST call URI ends with a wildcard ('*').
* It then iterates through the endpoint map to find URIs that start with the same prefix as the REST call URI
* (excluding the wildcard) and have the same HTTP method. If such URIs are found, they are added to the list of matching endpoints.
*
* @param restCall The REST call information to check for wildcard matches.
* @param matchingEndpoints The list of matching endpoints to be populated.
* @param restCallURI The URI of the REST call being checked.
* @param endpointMap The map of endpoint URIs to their corresponding information.
*/
private static void checkForWildcardMatches(RestCallInformation restCall, List<EndpointInformation> matchingEndpoints, String restCallURI, Map<String, List<EndpointInformation>> endpointMap) {
if (matchingEndpoints.isEmpty() && restCallURI.endsWith("*")) {
for (String uri : endpointMap.keySet()) {
Expand Down Expand Up @@ -110,7 +123,7 @@ private static void printRestCallAnalysisResult() {
});
}
catch (IOException e) {
logger.error("failed to deserialize rest call analysis results", e);
logger.error("Failed to deserialize rest call analysis results", e);
}

restCallsAndMatchingEndpoints.restCallsWithoutMatchingEndpoints().stream().forEach(endpoint -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public record RestCallInformation(
String fileName
) {
public String buildCompleteRestCallURI() {
String result = this.url.replace("`", "");
return result;
return this.url.replace("`", "");
}

public String buildComparableRestCallUri() {
Expand Down

0 comments on commit a5f7bbc

Please sign in to comment.