-
Notifications
You must be signed in to change notification settings - Fork 437
feat(server): restore FastAPI /docs visibility for A2A routes #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martimfasantos
wants to merge
12
commits into
a2aproject:main
Choose a base branch
from
martimfasantos:feat/fastapi-routes-helpers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
697db0d
feat(server): restore FastAPI /docs visibility for A2A routes
martimfasantos a02be59
fix(server): resolve lint, type, and spelling errors in route helpers
martimfasantos 205ffa2
cleanup
martimfasantos 950c37d
refactor(routes): replace oneof cartesian product with allOf+oneOf an…
martimfasantos cfe85e5
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos 9ca9381
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos 0dc0f89
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos 69abf5b
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos 41331c4
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos 92f6f17
fix(server): suppress ty invalid-assignment error on openapi override
martimfasantos d5f2217
refactor(routes): simplify envelope_schema dedup with dict.fromkeys
martimfasantos ab91425
Merge branch 'main' into feat/fastapi-routes-helpers
martimfasantos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from a2a.server.routes.helpers.fastapi import add_a2a_routes_to_fastapi | ||
|
|
||
|
|
||
| __all__ = [ | ||
| 'add_a2a_routes_to_fastapi', | ||
| ] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| """Proto → JSON Schema helpers shared across transport helpers.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from google.protobuf.descriptor import Descriptor, FieldDescriptor | ||
| from google.protobuf.message import Message | ||
|
|
||
| from a2a.types.a2a_pb2 import SendMessageRequest, TaskPushNotificationConfig | ||
|
|
||
|
|
||
| REST_BODY_TYPES: dict[tuple[str, str], type[Message]] = { | ||
| ('/message:send', 'POST'): SendMessageRequest, | ||
| ('/message:stream', 'POST'): SendMessageRequest, | ||
| ('/tasks/{id}/pushNotificationConfigs', 'POST'): TaskPushNotificationConfig, | ||
| } | ||
|
|
||
| # 64-bit integer types serialize as strings in protojson. | ||
| _PROTO_SCALAR_SCHEMAS: dict[int, dict[str, Any]] = { | ||
| FieldDescriptor.TYPE_DOUBLE: {'type': 'number'}, | ||
| FieldDescriptor.TYPE_FLOAT: {'type': 'number'}, | ||
| FieldDescriptor.TYPE_INT64: {'type': 'string', 'format': 'int64'}, | ||
| FieldDescriptor.TYPE_UINT64: {'type': 'string', 'format': 'uint64'}, | ||
| FieldDescriptor.TYPE_INT32: {'type': 'integer', 'format': 'int32'}, | ||
| FieldDescriptor.TYPE_FIXED64: {'type': 'string', 'format': 'fixed64'}, | ||
| FieldDescriptor.TYPE_FIXED32: {'type': 'integer', 'format': 'fixed32'}, | ||
| FieldDescriptor.TYPE_BOOL: {'type': 'boolean'}, | ||
| FieldDescriptor.TYPE_STRING: {'type': 'string'}, | ||
| FieldDescriptor.TYPE_BYTES: {'type': 'string', 'format': 'byte'}, | ||
| FieldDescriptor.TYPE_UINT32: {'type': 'integer', 'format': 'uint32'}, | ||
| FieldDescriptor.TYPE_SFIXED32: {'type': 'integer'}, | ||
| FieldDescriptor.TYPE_SFIXED64: {'type': 'string'}, | ||
| FieldDescriptor.TYPE_SINT32: {'type': 'integer'}, | ||
| FieldDescriptor.TYPE_SINT64: {'type': 'string'}, | ||
| } | ||
|
|
||
| _WELL_KNOWN_SCHEMAS: dict[str, dict[str, Any]] = { | ||
| 'google.protobuf.Timestamp': {'type': 'string', 'format': 'date-time'}, | ||
| 'google.protobuf.Duration': {'type': 'string'}, | ||
| 'google.protobuf.Struct': {'type': 'object'}, | ||
| 'google.protobuf.Value': {}, | ||
| 'google.protobuf.ListValue': {'type': 'array', 'items': {}}, | ||
| 'google.protobuf.Empty': {'type': 'object'}, | ||
| 'google.protobuf.Any': {'type': 'object'}, | ||
| 'google.protobuf.FieldMask': {'type': 'string'}, | ||
| } | ||
|
|
||
|
|
||
| def field_schema( | ||
| field: FieldDescriptor, components: dict[str, Any] | ||
| ) -> dict[str, Any]: | ||
| if field.message_type and field.message_type.GetOptions().map_entry: | ||
| value_field = field.message_type.fields_by_name['value'] | ||
| return { | ||
| 'type': 'object', | ||
| 'additionalProperties': field_schema(value_field, components), | ||
| } | ||
|
|
||
| if field.type == FieldDescriptor.TYPE_MESSAGE: | ||
| item = message_schema(field.message_type, components) | ||
| elif field.type == FieldDescriptor.TYPE_ENUM: | ||
| item = { | ||
| 'type': 'string', | ||
| 'enum': [v.name for v in field.enum_type.values], | ||
| } | ||
| else: | ||
| item = dict(_PROTO_SCALAR_SCHEMAS.get(field.type, {'type': 'string'})) | ||
|
|
||
| if field.is_repeated: | ||
| return {'type': 'array', 'items': item} | ||
| return item | ||
|
|
||
|
|
||
| def message_schema( | ||
| descriptor: Descriptor | Any, components: dict[str, Any] | ||
| ) -> dict[str, Any]: | ||
| """Returns a $ref to descriptor's schema, registering it in components if needed.""" | ||
| if descriptor.full_name in _WELL_KNOWN_SCHEMAS: | ||
| return dict(_WELL_KNOWN_SCHEMAS[descriptor.full_name]) | ||
|
|
||
| name = descriptor.name | ||
| ref = {'$ref': f'#/components/schemas/{name}'} | ||
| if name in components: | ||
| return ref | ||
|
|
||
| # Reserve the slot before recursing so cyclic types terminate. | ||
| components[name] = {} | ||
|
|
||
| real_oneofs = [o for o in descriptor.oneofs if len(o.fields) > 1] | ||
| oneof_field_names = {f.name for o in real_oneofs for f in o.fields} | ||
| base_properties = { | ||
| f.name: field_schema(f, components) | ||
| for f in descriptor.fields | ||
| if f.name not in oneof_field_names | ||
| } | ||
|
|
||
| if not real_oneofs: | ||
| components[name] = {'type': 'object', 'properties': base_properties} | ||
| return ref | ||
|
|
||
| oneof_constraints = [ | ||
| { | ||
| 'oneOf': [ | ||
| { | ||
| 'type': 'object', | ||
| 'properties': {f.name: field_schema(f, components)}, | ||
| 'required': [f.name], | ||
| } | ||
| for f in oneof.fields | ||
| ] | ||
| } | ||
| for oneof in real_oneofs | ||
| ] | ||
| parts: list[dict[str, Any]] = [] | ||
| if base_properties: | ||
| parts.append({'type': 'object', 'properties': base_properties}) | ||
| parts.extend(oneof_constraints) | ||
| components[name] = parts[0] if len(parts) == 1 else {'allOf': parts} | ||
| return ref |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to keep all developer facing helpers at src/a2a/helpers: #978