Created
November 6, 2019 19:37
-
-
Save dmontagu/054984647100cb9653e1b97c19886281 to your computer and use it in GitHub Desktop.
This file contains 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
from typing import TYPE_CHECKING, Any, Callable, get_type_hints | |
from fastapi import APIRouter | |
class InferringRouter(APIRouter): | |
if not TYPE_CHECKING: | |
def add_api_route(self, path: str, endpoint: Callable[..., Any], **kwargs: Any) -> None: | |
if kwargs.get("response_model") is None: | |
kwargs["response_model"] = get_type_hints(endpoint).get("return") | |
return super().add_api_route(path, endpoint, **kwargs) | |
else: # pragma: no cover | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment