Skip to content

Commit 5ce4383

Browse files
committed
Next batch, also switch to using protobuf-spi-impl to simplify
1 parent 7dd6046 commit 5ce4383

23 files changed

+341
-197
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<jakarta.ws.rs-api.version>3.1.0</jakarta.ws.rs-api.version>
5656
<junit.version>5.13.4</junit.version>
5757
<mapstruct.version>1.6.3</mapstruct.version>
58+
<mapstruct-spi-protobuf.version>1.52.0</mapstruct-spi-protobuf.version>
5859
<mockito-core.version>5.17.0</mockito-core.version>
5960
<mockserver.version>5.15.0</mockserver.version>
6061
<mutiny-zero.version>1.1.1</mutiny-zero.version>
@@ -357,6 +358,11 @@
357358
<artifactId>mapstruct-processor</artifactId>
358359
<version>${mapstruct.version}</version>
359360
</path>
361+
<path>
362+
<groupId>no.entur.mapstruct.spi</groupId>
363+
<artifactId>protobuf-spi-impl</artifactId>
364+
<version>${mapstruct-spi-protobuf.version}</version>
365+
</path>
360366
<!-- Other annotation processors go here.
361367
362368
If 'annotationProcessorPaths' is set, processors will no longer be

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ public interface APIKeySecuritySchemeMapper {
1515
APIKeySecuritySchemeMapper INSTANCE = Mappers.getMapper(APIKeySecuritySchemeMapper.class);
1616

1717
@IgnoreProtobufInternals
18-
@Mapping(target = "descriptionBytes", ignore = true)
19-
@Mapping(target = "locationBytes", ignore = true)
20-
@Mapping(target = "nameBytes", ignore = true)
2118
// location enum is converted to string via ProtoMapperConfig.map(Location)
2219
@Mapping(target = "description", source = "description", conditionExpression = "java(domain.getDescription() != null)")
2320
io.a2a.grpc.APIKeySecurityScheme toProto(io.a2a.spec.APIKeySecurityScheme domain);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import org.mapstruct.CollectionMappingStrategy;
4+
import org.mapstruct.Mapper;
5+
import org.mapstruct.Mapping;
6+
import org.mapstruct.factory.Mappers;
7+
8+
/**
9+
* Mapper between {@link io.a2a.spec.AgentCapabilities} and {@link io.a2a.grpc.AgentCapabilities}.
10+
*/
11+
@Mapper(config = ProtoMapperConfig.class,
12+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
13+
uses = {AgentExtensionMapper.class})
14+
public interface AgentCapabilitiesMapper {
15+
16+
AgentCapabilitiesMapper INSTANCE = Mappers.getMapper(AgentCapabilitiesMapper.class);
17+
18+
@IgnoreProtobufInternals
19+
io.a2a.grpc.AgentCapabilities toProto(io.a2a.spec.AgentCapabilities domain);
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import org.mapstruct.CollectionMappingStrategy;
4+
import org.mapstruct.Mapper;
5+
import org.mapstruct.Mapping;
6+
import org.mapstruct.factory.Mappers;
7+
8+
/**
9+
* Mapper between {@link io.a2a.spec.AgentCard} and {@link io.a2a.grpc.AgentCard}.
10+
*/
11+
@Mapper(config = ProtoMapperConfig.class,
12+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
13+
uses = {
14+
AgentProviderMapper.class,
15+
AgentCapabilitiesMapper.class,
16+
AgentSkillMapper.class,
17+
SecuritySchemeMapper.class,
18+
SecurityMapper.class,
19+
AgentInterfaceMapper.class,
20+
AgentCardSignatureMapper.class
21+
})
22+
public interface AgentCardMapper {
23+
24+
AgentCardMapper INSTANCE = Mappers.getMapper(AgentCardMapper.class);
25+
26+
@IgnoreProtobufInternals
27+
@Mapping(target = "provider", source = "provider", conditionExpression = "java(domain.provider() != null)")
28+
@Mapping(target = "documentationUrl", source = "documentationUrl", conditionExpression = "java(domain.documentationUrl() != null)")
29+
@Mapping(target = "iconUrl", source = "iconUrl", conditionExpression = "java(domain.iconUrl() != null)")
30+
@Mapping(target = "url", source = "url", conditionExpression = "java(domain.url() != null)")
31+
@Mapping(target = "preferredTransport", source = "preferredTransport", conditionExpression = "java(domain.preferredTransport() != null)")
32+
@Mapping(source = "additionalInterfaces", target = "supportedInterfaces")
33+
io.a2a.grpc.AgentCard toProto(io.a2a.spec.AgentCard domain);
34+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import io.a2a.grpc.utils.ProtoUtils;
4+
import org.mapstruct.CollectionMappingStrategy;
5+
import org.mapstruct.Mapper;
6+
import org.mapstruct.Mapping;
7+
import org.mapstruct.Named;
8+
import org.mapstruct.factory.Mappers;
9+
10+
/**
11+
* Mapper between {@link io.a2a.spec.AgentCardSignature} and {@link io.a2a.grpc.AgentCardSignature}.
12+
*/
13+
@Mapper(config = ProtoMapperConfig.class,
14+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
15+
public interface AgentCardSignatureMapper {
16+
17+
AgentCardSignatureMapper INSTANCE = Mappers.getMapper(AgentCardSignatureMapper.class);
18+
19+
@Named("toProtoWithoutHeader")
20+
@IgnoreProtobufInternals
21+
@Mapping(target = "header", ignore = true)
22+
@Mapping(source = "protectedHeader", target = "protected")
23+
io.a2a.grpc.AgentCardSignature toProtoWithoutHeader(io.a2a.spec.AgentCardSignature domain);
24+
25+
default io.a2a.grpc.AgentCardSignature toProto(io.a2a.spec.AgentCardSignature domain) {
26+
if (domain == null) {
27+
return null;
28+
}
29+
io.a2a.grpc.AgentCardSignature.Builder builder = toProtoWithoutHeader(domain).toBuilder();
30+
if (domain.header() != null) {
31+
builder.setHeader(ProtoUtils.ToProto.struct(domain.header()));
32+
}
33+
return builder.build();
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import io.a2a.grpc.utils.ProtoUtils;
4+
import org.mapstruct.CollectionMappingStrategy;
5+
import org.mapstruct.Mapper;
6+
import org.mapstruct.Mapping;
7+
import org.mapstruct.Named;
8+
import org.mapstruct.factory.Mappers;
9+
10+
/**
11+
* Mapper between {@link io.a2a.spec.AgentExtension} and {@link io.a2a.grpc.AgentExtension}.
12+
*/
13+
@Mapper(config = ProtoMapperConfig.class,
14+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED)
15+
public interface AgentExtensionMapper {
16+
17+
AgentExtensionMapper INSTANCE = Mappers.getMapper(AgentExtensionMapper.class);
18+
19+
@Named("toProtoWithoutParams")
20+
@IgnoreProtobufInternals
21+
@Mapping(target = "params", ignore = true)
22+
io.a2a.grpc.AgentExtension toProtoWithoutParams(io.a2a.spec.AgentExtension domain);
23+
24+
default io.a2a.grpc.AgentExtension toProto(io.a2a.spec.AgentExtension domain) {
25+
if (domain == null) {
26+
return null;
27+
}
28+
io.a2a.grpc.AgentExtension.Builder builder = toProtoWithoutParams(domain).toBuilder();
29+
if (domain.params() != null) {
30+
builder.setParams(ProtoUtils.ToProto.struct(domain.params()));
31+
}
32+
return builder.build();
33+
}
34+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public interface AgentInterfaceMapper {
1515
AgentInterfaceMapper INSTANCE = Mappers.getMapper(AgentInterfaceMapper.class);
1616

1717
@IgnoreProtobufInternals
18-
@Mapping(target = "urlBytes", ignore = true)
19-
@Mapping(target = "protocolBindingBytes", ignore = true)
2018
io.a2a.grpc.AgentInterface toProto(io.a2a.spec.AgentInterface domain);
2119

2220
io.a2a.spec.AgentInterface fromProto(io.a2a.grpc.AgentInterface proto);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public interface AgentProviderMapper {
1515
AgentProviderMapper INSTANCE = Mappers.getMapper(AgentProviderMapper.class);
1616

1717
@IgnoreProtobufInternals
18-
@Mapping(target = "urlBytes", ignore = true)
19-
@Mapping(target = "organizationBytes", ignore = true)
2018
io.a2a.grpc.AgentProvider toProto(io.a2a.spec.AgentProvider domain);
2119

2220
io.a2a.spec.AgentProvider fromProto(io.a2a.grpc.AgentProvider proto);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.a2a.grpc.mapper;
2+
3+
import org.mapstruct.CollectionMappingStrategy;
4+
import org.mapstruct.Mapper;
5+
import org.mapstruct.Mapping;
6+
import org.mapstruct.factory.Mappers;
7+
8+
/**
9+
* Mapper between {@link io.a2a.spec.AgentSkill} and {@link io.a2a.grpc.AgentSkill}.
10+
*/
11+
@Mapper(config = ProtoMapperConfig.class,
12+
collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
13+
uses = SecurityMapper.class)
14+
public interface AgentSkillMapper {
15+
16+
AgentSkillMapper INSTANCE = Mappers.getMapper(AgentSkillMapper.class);
17+
18+
@IgnoreProtobufInternals
19+
io.a2a.grpc.AgentSkill toProto(io.a2a.spec.AgentSkill domain);
20+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ public interface AuthenticationInfoMapper {
1313
AuthenticationInfoMapper INSTANCE = Mappers.getMapper(AuthenticationInfoMapper.class);
1414

1515
@IgnoreProtobufInternals
16-
@Mapping(target = "credentialsBytes", ignore = true)
17-
@Mapping(source = "schemes", target = "schemesList")
1816
@Mapping(target = "credentials", source = "credentials", conditionExpression = "java(domain.credentials() != null)")
1917
io.a2a.grpc.AuthenticationInfo toProto(io.a2a.spec.AuthenticationInfo domain);
2018

21-
@Mapping(source = "schemesList", target = "schemes")
2219
io.a2a.spec.AuthenticationInfo fromProto(io.a2a.grpc.AuthenticationInfo proto);
2320
}

0 commit comments

Comments
 (0)