Skip to content
Open
Show file tree
Hide file tree
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: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Java SDK for the Agent Name Service (ANS) Registry. This SDK provides clients fo

## API Specification Reference

The ANS Registry SDK is based off of the REST API. The spec is documented using the OpenAPI (Swagger) specification:
- [View OpenAPI Spec - Human Readable](https://developer.godaddy.com/doc/endpoint/ans)
- [OpenAPI Spec - AI/Machine Readable](https://developer.godaddy.com/swagger/swagger_ans.json)
The ANS Registry SDK is based off of the REST API. The spec is documented using the OpenAPI specification:
- [ANS OpenAPI Spec (ans repo)](https://github.com/agentnameservice/ans/blob/main/spec/api-spec-v2.yaml)
- Local copy used for code generation: [`ans-sdk-api/spec/api-spec.yaml`](ans-sdk-api/spec/api-spec.yaml)

## Requirements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.godaddy.ans.sdk.agent.protocol.HttpApiClient;
import com.godaddy.ans.sdk.model.generated.AgentDetails;
import com.godaddy.ans.sdk.model.generated.AgentEndpoint;
import com.godaddy.ans.sdk.model.generated.Protocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -178,13 +179,14 @@ public Optional<String> getMetadataUrl(String protocol) {
/**
* Checks if a Protocol enum matches the protocol string.
*/
private boolean matchesProtocol(AgentEndpoint.ProtocolEnum endpointProtocol, String protocolStr) {
private boolean matchesProtocol(Protocol endpointProtocol, String protocolStr) {
if (endpointProtocol == null || protocolStr == null) {
return false;
}
// Handle both enum name (HTTP_API) and value (HTTP-API)
return protocolStr.equals(endpointProtocol.name())
|| protocolStr.equals(endpointProtocol.getValue());
// Normalize hyphens to underscores so "HTTP-API" form matches HTTP_API
String normalized = protocolStr.replace('-', '_');
return normalized.equals(endpointProtocol.name())
|| normalized.equals(endpointProtocol.getValue());
Comment on lines -185 to +189

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

After normalizing protocolStr to use underscores, the second comparison against getValue() (which returns e.g. "HTTP_API") is redundant with the first comparison against name() — they return the same string for the new top-level Protocol enum. The second clause is effectively dead.

If the intent is to keep both the legacy hyphenated alias and the canonical form working, the original protocolStr should still be compared against getValue() before normalization:

  return protocolStr.equals(endpointProtocol.name())
      || protocolStr.equals(endpointProtocol.getValue())
      || protocolStr.replace('-', '_').equals(endpointProtocol.name());

Alternatively, we can remove the 2nd OR branch.

@jhateley-godaddy jhateley-godaddy Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The Protocol enum still contains an entry where the name doesn't match the value:

  A2_A("A2A")

so I think we still need this. There is an existing test in AgentConnectionTest:

@Test
    void supportsProtocolWithSupportedProtocolShouldReturnTrue() {
        // Given
        AgentConnection connection = new AgentConnection(agentDetails, ansHttpClient);

        // When/Then - using enum name format
        assertThat(connection.supportsProtocol("HTTP_API")).isTrue();
        assertThat(connection.supportsProtocol("A2A")).isTrue();
    }

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.godaddy.ans.sdk.model.generated.AgentDetails;
import com.godaddy.ans.sdk.model.generated.AgentEndpoint;
import com.godaddy.ans.sdk.model.generated.AgentLifecycleStatus;
import com.godaddy.ans.sdk.model.generated.Protocol;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -16,6 +17,7 @@
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand All @@ -36,16 +38,16 @@ class AgentConnectionTest {
void setUp() {
// Create test agent details with endpoints
AgentEndpoint httpApiEndpoint = new AgentEndpoint();
httpApiEndpoint.setProtocol(AgentEndpoint.ProtocolEnum.HTTP_API);
httpApiEndpoint.setProtocol(Protocol.HTTP_API);
httpApiEndpoint.setAgentUrl(URI.create("https://agent.example.com/api"));
httpApiEndpoint.setMetaDataUrl(URI.create("https://agent.example.com/metadata"));

AgentEndpoint a2aEndpoint = new AgentEndpoint();
a2aEndpoint.setProtocol(AgentEndpoint.ProtocolEnum.A2_A);
a2aEndpoint.setProtocol(Protocol.A2_A);
a2aEndpoint.setAgentUrl(URI.create("wss://agent.example.com/a2a"));

agentDetails = new AgentDetails();
agentDetails.setAgentId("test-agent-id");
agentDetails.setAgentId(UUID.randomUUID());
agentDetails.setAnsName("ans://v1.0.0.agent.example.com");
agentDetails.setAgentHost("agent.example.com");
agentDetails.setVersion("1.0.0");
Expand Down Expand Up @@ -94,7 +96,7 @@ void supportsProtocolWithProtocolValueShouldReturnTrue() {
// Given
AgentConnection connection = new AgentConnection(agentDetails, ansHttpClient);

// When/Then - using protocol value format (HTTP-API)
// When/Then - legacy hyphenated alias (HTTP-API) should still match HTTP_API
assertThat(connection.supportsProtocol("HTTP-API")).isTrue();
}

Expand Down
26 changes: 3 additions & 23 deletions ans-sdk-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ plugins {
val jacksonVersion: String by project

// Authoritative source for the API spec
val apiSpecUrl = "https://developer.godaddy.com/swagger/swagger_ans.json"
val apiSpecFile = layout.buildDirectory.file("api-spec.json")
val apiSpecFile = layout.projectDirectory.file("spec/api-spec.yaml")

dependencies {
// Jackson for JSON serialization
Expand All @@ -20,25 +19,10 @@ dependencies {
implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")
}

// Task to download the API spec from the authoritative source
val downloadApiSpec by tasks.registering {
val outputFile = apiSpecFile
outputs.file(outputFile)
doLast {
val destFile = outputFile.get().asFile
destFile.parentFile.mkdirs()
URI.create(apiSpecUrl).toURL().openStream().use { input ->
destFile.outputStream().use { output ->
input.copyTo(output)
}
}
logger.lifecycle("Downloaded API spec from $apiSpecUrl")
}
}

openApiGenerate {
generatorName.set("java")
inputSpec.set(apiSpecFile.get().asFile.absolutePath)
inputSpec.set(apiSpecFile)
skipValidateSpec.set(true)
outputDir.set(layout.buildDirectory.dir("generated").get().asFile.absolutePath)
apiPackage.set("com.godaddy.ans.sdk.api.generated")
modelPackage.set("com.godaddy.ans.sdk.model.generated")
Expand All @@ -61,10 +45,6 @@ sourceSets {
}
}

tasks.openApiGenerate {
dependsOn(downloadApiSpec)
}

tasks.compileJava {
dependsOn(tasks.openApiGenerate)
}
Expand Down
Loading
Loading