Skip to content

Commit

Permalink
Close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
amacfie committed Feb 20, 2023
1 parent 710b9a6 commit eec527e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ and Result from [returns](https://returns.readthedocs.io/en/latest/pages/result.
so that both primary (200) and [additional](https://fastapi.tiangolo.com/advanced/additional-responses/)
response types can be inferred from the path operation type signature.

Install as user
Install as user:
```bash
pip install git+https://github.com/amacfie/fastapi_returns_inferring_router
```


Install as developer
Install as developer:
```bash
pip install --editable .
```
Expand Down
8 changes: 5 additions & 3 deletions fastapi_returns_inferring_router/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from typing import (TYPE_CHECKING, Any, Callable, Union, get_args, get_origin, get_type_hints)

from fastapi import APIRouter
from fastapi.datastructures import DefaultPlaceholder
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from returns.result import Result, Success, Failure
from semantic_version import Version
import fastapi


class ReturnsInferringRouter(APIRouter):
Expand Down Expand Up @@ -47,8 +50,7 @@ def new_endpoint(*args, **kwargs):
# pydantic maps None to something openapi doesn't recognize
if suc_type is None:
suc_type = Any
if kwargs.get("response_model") is None:
kwargs["response_model"] = suc_type
kwargs["response_model"] = suc_type

if (
kwargs.get("responses") is None or
Expand Down Expand Up @@ -87,7 +89,7 @@ def new_endpoint(*args, **kwargs):
responses[code] = {"model": fail_model}
kwargs["responses"] = responses

else:
elif Version(fastapi.__version__) < Version("0.89.0"):
# same pydantic issue as above
if return_type is None:
return_type = Any
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ install_requires =
fastapi==0.*
returns==0.*
build
semantic-version==2.*
sphinx==4.*
twine
python_requires = >=3.10, <4

0 comments on commit eec527e

Please sign in to comment.