feat: fastapi integration added. - #137
Conversation
|
|
||
| jsonrpc_app = integration.Application('/api/v1') | ||
| jsonrpc_app.add_methods(methods) | ||
|
|
There was a problem hiding this comment.
I think it worth to define a fastapi app variable like:
app = jsonrpc_app.http_appto be able to start it with fastapi dev or fastapi run command.
There was a problem hiding this comment.
A more useful example is
jsonrpc_app = integration.Application('/api/v1')
jsonrpc_app.add_methods(methods)
app = fastapi.FastAPI()
app.mount("/rpc", jsonrpc_app.http_app)The same example is described in openapi + fastapi docs
| if annotation is None: | ||
| return False | ||
|
|
||
| return inspect.isclass(annotation) and issubclass(annotation, fastapi.Request) |
There was a problem hiding this comment.
fastapi request is a generic type so inspect.isclass always returns False. We must check the origin of the type not the type itself:
def is_fastapi_request(idx: int, name: str, annotation: Optional[type[Any]], default: Optional[Any]) -> bool:
if annotation is None:
return False
annotation_origin = typing.get_origin(annotation)
return inspect.isclass(annotation_origin) and issubclass(annotation_origin, fastapi.Request)| """ | ||
| Creates a user. | ||
|
|
||
| :param request: http request |
There was a problem hiding this comment.
http request is not passed. Let's pass it with to make the example more fulfilling:
@methods.add(
pass_context=True,
metadata=[
openapi.metadata(
summary="Creates a user",
tags=['users'],
errors=[AlreadyExistsError],
),
],
)
def add_user(request: fastapi.Request[Mapping[str, Any]], user: UserIn) -> UserOut:
"""
Creates a user.
:param request: http request
:param object user: user data
:return object: registered user
:raise AlreadyExistsError: user already exists
"""|
aiohttp 3.14 and aioresponses compatibility is broken pnuckowski/aioresponses#289 |
|
@lbukr I substituted aioresponses by aiointercept which is compatible with the latest aiohttp version. Please, rebase to the latest dev branch. |
Implementation of fastapi server based