Commit dec4b48
fix: openapi working in sub-app (#324)
The `A2AFastAPIApplication` is very useful, but currently can not be
used as a [Sub
Application](https://fastapi.tiangolo.com/advanced/sub-applications/)
without breaking the openapi specification.
[Lifespan does not work for Sub
Applications](https://fastapi.tiangolo.com/advanced/events/#sub-applications),
which makes this otherwise useful integration work in existing larger
FastAPI apps.
This fix gets rid of the lifespan and instead enriches the openapi on
the first call of the [openapi
method](https://github.com/fastapi/fastapi/blob/0.116.1/fastapi/applications.py#L966).
I tested it locally and everything works with sub-application.
The following works after the fix with openapi components populated:
```python
from fastapi import FastAPI
from a2a.server.apps import A2AFastAPIApplication
app = FastAPI()
agent_app = A2AFastAPIApplication(...).build()
app.mount("/a2a", agent_app)
```
I am not adding `@override` although this overrides the `openapi`,
because the pyright fails on it, see [the failed lint
run](https://github.com/a2aproject/a2a-python/actions/runs/16370448989/job/46257297467?pr=324).
---------
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Holt Skinner <[email protected]>
Co-authored-by: kthota-g <[email protected]>1 parent 3032aa6 commit dec4b48
File tree
2 files changed
+42
-19
lines changed- src/a2a/server/apps/jsonrpc
- tests/server/apps/jsonrpc
2 files changed
+42
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
| |||
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
24 | 44 | | |
25 | 45 | | |
26 | 46 | | |
| |||
92 | 112 | | |
93 | 113 | | |
94 | 114 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 115 | + | |
112 | 116 | | |
113 | 117 | | |
114 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
0 commit comments