Skip to content

Commit be457f4

Browse files
refactor: remove custom a2a.json from json rpc FastAPI (#850)
# Description This PR removes the generation and use of a2a.json. Its content is not compatible with the JSON-RPC protocol, so there is no need to load it with the FastAPI server generation.
1 parent 115fa4e commit be457f4

3 files changed

Lines changed: 1 addition & 2310 deletions

File tree

buf.gen.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ plugins:
2929
# Generates *_pb2.pyi files.
3030
- remote: buf.build/protocolbuffers/pyi
3131
out: src/a2a/types
32-
# Generates a2a.swagger.json (OpenAPI v2)
33-
- remote: buf.build/grpc-ecosystem/openapiv2
34-
out: src/a2a/types
35-
opt: json_names_for_fields=true

src/a2a/server/apps/jsonrpc/fastapi_app.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import importlib.resources
2-
import json
31
import logging
42

53
from collections.abc import Awaitable, Callable
@@ -36,43 +34,6 @@
3634
logger = logging.getLogger(__name__)
3735

3836

39-
class A2AFastAPI(FastAPI):
40-
"""A FastAPI application that adds A2A-specific OpenAPI components."""
41-
42-
_a2a_components_added: bool = False
43-
44-
def openapi(self) -> dict[str, Any]:
45-
"""Generates the OpenAPI schema for the application."""
46-
if self.openapi_schema:
47-
return self.openapi_schema
48-
49-
# Try to use the a2a.json schema generated from the proto file
50-
# if available, instead of generating one from the python types.
51-
try:
52-
from a2a import types # noqa: PLC0415
53-
54-
schema_file = importlib.resources.files(types).joinpath('a2a.json')
55-
if schema_file.is_file():
56-
self.openapi_schema = json.loads(
57-
schema_file.read_text(encoding='utf-8')
58-
)
59-
if self.openapi_schema:
60-
return self.openapi_schema
61-
except Exception: # noqa: BLE001
62-
logger.warning(
63-
"Could not load 'a2a.json' from 'a2a.types'. Falling back to auto-generation."
64-
)
65-
66-
openapi_schema = super().openapi()
67-
if not self._a2a_components_added:
68-
# A2ARequest is now a Union type of proto messages, so we can't use
69-
# model_json_schema. Instead, we just mark it as added without
70-
# adding the schema since proto types don't have Pydantic schemas.
71-
# The OpenAPI schema will still be functional for the endpoints.
72-
self._a2a_components_added = True
73-
return openapi_schema
74-
75-
7637
class A2AFastAPIApplication(JSONRPCApplication):
7738
"""A FastAPI application implementing the A2A protocol server endpoints.
7839
@@ -180,7 +141,7 @@ def build(
180141
Returns:
181142
A configured FastAPI application instance.
182143
"""
183-
app = A2AFastAPI(**kwargs)
144+
app = FastAPI(**kwargs)
184145

185146
self.add_routes_to_app(app, agent_card_url, rpc_url)
186147

0 commit comments

Comments
 (0)