feat(server): restore FastAPI /docs visibility for A2A routes#1024
Open
martimfasantos wants to merge 4 commits intoa2aproject:mainfrom
Open
feat(server): restore FastAPI /docs visibility for A2A routes#1024martimfasantos wants to merge 4 commits intoa2aproject:mainfrom
martimfasantos wants to merge 4 commits intoa2aproject:mainfrom
Conversation
40cbe9c to
697db0d
Compare
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/server/routes/helpers/_proto_schema.py (new) | — | 94.23% | — |
| src/a2a/server/routes/helpers/fastapi.py (new) | — | 91.78% | — |
| src/a2a/server/routes/helpers/jsonrpc.py (new) | — | 100.00% | — |
| Total | 93.00% | 93.02% | 🟢 +0.01% |
Generated by coverage-comment.yml
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the add_a2a_routes_to_fastapi utility, which enables A2A endpoints (Agent Card, JSON-RPC, and REST) to be correctly registered and documented within FastAPI's auto-generated OpenAPI schema. The implementation includes a new Protobuf-to-JSON-Schema conversion module to provide detailed request body documentation derived from protocol definitions. Feedback was provided regarding the scalability of the oneOf generation logic in _proto_schema.py, which currently creates a Cartesian product of variants for messages containing multiple oneofs, potentially leading to an exponential explosion of schema variants.
…d inline component install Replace O(∏fields) Cartesian product oneof generation with O(∑fields) allOf+oneOf-per-group approach, and inline _install_components into add_a2a_routes_to_fastapi to remove a single-use wrapper function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/a2a/server/routes/helpers/— a new subpackage of transport-specific route helpers mirroring the layout ofclient/transports/add_a2a_routes_to_fastapi()re-registers A2A Starlette routes asAPIRouteinstances so FastAPI's OpenAPI generator picks them up and they appear in/docsand/openapi.jsonA2A: Agent Card,A2A: JSON-RPC,A2A: REST) and annotated with proto-derived request-body schemas so Swagger UI's Try it out panel renders a typed, editable payloadA2A-Version: 1.0header is declared on every dispatcher route so Swagger pre-fills it and callers aren't blocked by the@validate_versionguardWhy
In v0.3,
A2AFastAPIApplicationwas a first-class FastAPI subclass, so all endpoints were automatically visible in/docs(see #280).The v1.0 rewrite dropped that wrapper in favour of bare Starlette route factories (
create_agent_card_routes,create_jsonrpc_routes,create_rest_routes). These returnstarlette.routing.Routeobjects; FastAPI's OpenAPI generator only enumeratesfastapi.routing.APIRouteinstances, so every A2A endpoint silently vanished from/docsand/openapi.json.This PR restores that capability without requiring callers to switch frameworks or restructure their apps — a single helper function wraps and enriches the routes in place.
Additional improvements over the v0.3 approach:
google.protobuf.descriptor) rather than Pydantic models, matching the proto-first v1.0 typesoneof→ JSON SchemaoneOfsoPart.contentvariants (text,raw,url,data) are correctly mutually exclusive in Swagger — prevents-32602 Invalid paramserrors from the auto-generated sample payloadparamsasoneOfover all 11 method types — every method is individually inspectable from a single endpoint rowA2A-Versionheader pre-filled to1.0on all dispatcher routes — removes the-32009version error that would otherwise block every "Try it out" callhelpers/mirrorsclient/transports/with one file per integration target; adding a new framework is a single new file that imports from_proto_schema.pyandjsonrpc.pyChanges
Usage
Validation
uv run pytest tests/server/routes/helpers/ -v— 25 tests, all passingScreenshots
Before

After


Continues #280 🦕