Skip to content

Commit 10a037b

Browse files
committed
feat: add proto2pydantic Pydantic model generation pipeline
Add protoc-gen-proto2pydantic plugin to buf.gen.yaml for generating Pydantic models alongside existing protobuf _pb2 objects. Generated models: - 39 Pydantic models + 2 enums from a2a.proto - All extend A2ABaseModel with to_proto_json() for ProtoJSON compat - Keyword escaping (list -> list_ with alias='list') - Timestamp field serializers for RFC 3339 - Oneof unions for Part.content, SecurityScheme.scheme, etc. This is an additive change - existing a2a_pb2 imports are untouched. New Pydantic models available via: from a2a.types.a2a_pydantic import ...
1 parent 8d18d3d commit 10a037b

3 files changed

Lines changed: 717 additions & 0 deletions

File tree

buf.gen.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ plugins:
2929
# Generates *_pb2.pyi files.
3030
- remote: buf.build/protocolbuffers/pyi
3131
out: src/a2a/types
32+
# Generate Pydantic models with ProtoJSON compatibility
33+
- local: protoc-gen-proto2pydantic
34+
out: src/a2a/types
35+
opt:
36+
- preset=a2a
37+
- base_class=a2a._base.A2ABaseModel
38+
- output_file=a2a_pydantic.py

scripts/gen_proto.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
set -e
33

4+
# Install proto2pydantic plugin for Pydantic model generation
5+
echo "Installing protoc-gen-proto2pydantic@v0.4.0..."
6+
go install github.com/protocgen/proto2pydantic@v0.4.0
7+
48
# Run buf generate to regenerate protobuf code and OpenAPI spec
59
npx --yes @bufbuild/buf generate
610

0 commit comments

Comments
 (0)