Skip to content

Commit fca4705

Browse files
ehsavoieclaude
andcommitted
feat: Add fromProto mappers to AgentCardMapper and dependencies
Added bidirectional mapping support for converting gRPC AgentCard to domain AgentCard. - Added fromProto method to AgentCardMapper with conditional mapping for optional fields - Implemented fromProto in supporting mappers: AgentCapabilitiesMapper, AgentSkillMapper, AgentExtensionMapper, AgentCardSignatureMapper - Added polymorphic fromProto to SecuritySchemeMapper using switch expression for oneof pattern - Implemented manual fromProto methods in concrete SecurityScheme mappers (APIKey, HTTPAuth, OAuth2, OpenIdConnect, MutualTLS) to handle immutable domain objects with constructors - Added fromProto to OAuthFlowsMapper for OAuth2 flow conversion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 5992585 commit fca4705

12 files changed

+114
-0
lines changed

spec-grpc/src/main/java/io/a2a/grpc/mapper/APIKeySecuritySchemeMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ public interface APIKeySecuritySchemeMapper {
1616
// location enum is converted to string via ProtoMapperConfig.map(Location)
1717
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")
1818
io.a2a.grpc.APIKeySecurityScheme toProto(io.a2a.spec.APIKeySecurityScheme domain);
19+
20+
default io.a2a.spec.APIKeySecurityScheme fromProto(io.a2a.grpc.APIKeySecurityScheme proto) {
21+
if (proto == null) {
22+
return null;
23+
}
24+
25+
io.a2a.spec.APIKeySecurityScheme.Location location =
26+
io.a2a.spec.APIKeySecurityScheme.Location.fromString(proto.getLocation());
27+
String description = proto.getDescription().isEmpty() ? null : proto.getDescription();
28+
29+
return new io.a2a.spec.APIKeySecurityScheme(location, proto.getName(), description);
30+
}
1931
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCapabilitiesMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public interface AgentCapabilitiesMapper {
1414
AgentCapabilitiesMapper INSTANCE = A2AMappers.getMapper(AgentCapabilitiesMapper.class);
1515

1616
io.a2a.grpc.AgentCapabilities toProto(io.a2a.spec.AgentCapabilities domain);
17+
18+
io.a2a.spec.AgentCapabilities fromProto(io.a2a.grpc.AgentCapabilities proto);
1719
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCardMapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public interface AgentCardMapper {
2929
@Mapping(target = "preferredTransport", ignore = true) // Deprecated in proto, derived from supportedInterfaces[0]
3030
@Mapping(target = "additionalInterfaces", ignore = true) // Deprecated in proto, use supportedInterfaces instead
3131
io.a2a.grpc.AgentCard toProto(io.a2a.spec.AgentCard domain);
32+
33+
@Mapping(target = "provider", source = "provider", conditionExpression = "java(proto.hasProvider())")
34+
@Mapping(target = "documentationUrl", source = "documentationUrl", conditionExpression = "java(!proto.getDocumentationUrl().isEmpty())")
35+
@Mapping(target = "iconUrl", source = "iconUrl", conditionExpression = "java(!proto.getIconUrl().isEmpty())")
36+
io.a2a.spec.AgentCard fromProto(io.a2a.grpc.AgentCard proto);
3237
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentCardSignatureMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ public interface AgentCardSignatureMapper {
2424
@Mapping(source = "protectedHeader", target = "protected")
2525
@Mapping(target = "header", source = "header", conditionExpression = "java(domain.header() != null)", qualifiedByName = "mapToStruct")
2626
io.a2a.grpc.AgentCardSignature toProto(io.a2a.spec.AgentCardSignature domain);
27+
28+
/**
29+
* Converts proto AgentCardSignature to domain AgentCardSignature.
30+
* <p>
31+
* Maps protected field → protectedHeader and header from struct to map.
32+
*/
33+
@Mapping(source = "protected", target = "protectedHeader")
34+
@Mapping(target = "header", source = "header", qualifiedByName = "structToMap")
35+
io.a2a.spec.AgentCardSignature fromProto(io.a2a.grpc.AgentCardSignature proto);
2736
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentExtensionMapper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public interface AgentExtensionMapper {
2323
*/
2424
@Mapping(target = "params", source = "params", conditionExpression = "java(domain.params() != null)", qualifiedByName = "mapToStruct")
2525
io.a2a.grpc.AgentExtension toProto(io.a2a.spec.AgentExtension domain);
26+
27+
/**
28+
* Converts proto AgentExtension to domain AgentExtension.
29+
* <p>
30+
* Maps params field from struct to map.
31+
*/
32+
@Mapping(target = "params", source = "params", qualifiedByName = "structToMap")
33+
io.a2a.spec.AgentExtension fromProto(io.a2a.grpc.AgentExtension proto);
2634
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/AgentSkillMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public interface AgentSkillMapper {
1414
AgentSkillMapper INSTANCE = A2AMappers.getMapper(AgentSkillMapper.class);
1515

1616
io.a2a.grpc.AgentSkill toProto(io.a2a.spec.AgentSkill domain);
17+
18+
io.a2a.spec.AgentSkill fromProto(io.a2a.grpc.AgentSkill proto);
1719
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/HTTPAuthSecuritySchemeMapper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@ public interface HTTPAuthSecuritySchemeMapper {
1616
@Mapping(target = "bearerFormat", source = "bearerFormat", conditionExpression = "java(domain.getBearerFormat() != null)")
1717
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")
1818
io.a2a.grpc.HTTPAuthSecurityScheme toProto(io.a2a.spec.HTTPAuthSecurityScheme domain);
19+
20+
default io.a2a.spec.HTTPAuthSecurityScheme fromProto(io.a2a.grpc.HTTPAuthSecurityScheme proto) {
21+
if (proto == null) {
22+
return null;
23+
}
24+
25+
String bearerFormat = proto.getBearerFormat().isEmpty() ? null : proto.getBearerFormat();
26+
String description = proto.getDescription().isEmpty() ? null : proto.getDescription();
27+
28+
return new io.a2a.spec.HTTPAuthSecurityScheme(bearerFormat, proto.getScheme(), description);
29+
}
1930
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/MutualTLSSecuritySchemeMapper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ public interface MutualTLSSecuritySchemeMapper {
1515

1616
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")
1717
io.a2a.grpc.MutualTlsSecurityScheme toProto(io.a2a.spec.MutualTLSSecurityScheme domain);
18+
19+
default io.a2a.spec.MutualTLSSecurityScheme fromProto(io.a2a.grpc.MutualTlsSecurityScheme proto) {
20+
if (proto == null) {
21+
return null;
22+
}
23+
24+
String description = proto.getDescription().isEmpty() ? null : proto.getDescription();
25+
26+
return new io.a2a.spec.MutualTLSSecurityScheme(description);
27+
}
1828
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/OAuth2SecuritySchemeMapper.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,16 @@ public interface OAuth2SecuritySchemeMapper {
1717
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")
1818
@Mapping(target = "oauth2MetadataUrl", source = "oauth2MetadataUrl", conditionExpression = "java(domain.getOauth2MetadataUrl() != null)")
1919
io.a2a.grpc.OAuth2SecurityScheme toProto(io.a2a.spec.OAuth2SecurityScheme domain);
20+
21+
default io.a2a.spec.OAuth2SecurityScheme fromProto(io.a2a.grpc.OAuth2SecurityScheme proto) {
22+
if (proto == null) {
23+
return null;
24+
}
25+
26+
io.a2a.spec.OAuthFlows flows = OAuthFlowsMapper.INSTANCE.fromProto(proto.getFlows());
27+
String description = proto.getDescription().isEmpty() ? null : proto.getDescription();
28+
String oauth2MetadataUrl = proto.getOauth2MetadataUrl().isEmpty() ? null : proto.getOauth2MetadataUrl();
29+
30+
return new io.a2a.spec.OAuth2SecurityScheme(flows, description, oauth2MetadataUrl);
31+
}
2032
}

spec-grpc/src/main/java/io/a2a/grpc/mapper/OAuthFlowsMapper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ public interface OAuthFlowsMapper {
1919
OAuthFlowsMapper INSTANCE = A2AMappers.getMapper(OAuthFlowsMapper.class);
2020

2121
io.a2a.grpc.OAuthFlows toProto(io.a2a.spec.OAuthFlows domain);
22+
23+
io.a2a.spec.OAuthFlows fromProto(io.a2a.grpc.OAuthFlows proto);
2224
}

0 commit comments

Comments
 (0)