Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/src/main/java/io/a2a/client/A2ACardResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public A2ACardResolver(A2AHttpClient httpClient, String baseUrl, String agentCar
public A2ACardResolver(A2AHttpClient httpClient, String baseUrl, String agentCardPath,
Map<String, String> authHeaders) throws A2AClientError {
this.httpClient = httpClient;
if (!baseUrl.endsWith("/")) {
baseUrl += "/";
}
agentCardPath = agentCardPath == null || agentCardPath.isEmpty() ? DEFAULT_AGENT_CARD_PATH : agentCardPath;
if (agentCardPath.startsWith("/")) {
agentCardPath = agentCardPath.substring(1);
}
Comment on lines 61 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to determine the effective agentCardPath and ensure it's a relative path is correct. However, it can be expressed more concisely by combining the ternary operator for the default value with another one for stripping the leading slash. This can make the code slightly cleaner and easier to read.

        String path = (agentCardPath == null || agentCardPath.isEmpty()) ? DEFAULT_AGENT_CARD_PATH : agentCardPath;
        agentCardPath = path.startsWith("/") ? path.substring(1) : path;

try {
this.url = new URI(baseUrl).resolve(agentCardPath).toString();
} catch (URISyntaxException e) {
Expand Down