recover response_model from output annotations #6355
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
app = FastAPI()
@router.post("/have_output_example_and_schema", response_model=list)
async def test(input: int-> list:
return []
@router.post("/have_not_output_example_and_schema")
async def test_2(input: int-> list:
return [] DescriptionI think it will be nice if the type in response_model (in the app decorators) will be infered from the output annotation of the function. Wanted SolutionWhen response_model is None it will try to use the annotation one, es by using @router.post("/have_not_output_example_and_schema")
async def test_2(input: int-> list:
return [] Will be the same as @router.post("/have_not_output_example_and_schema",response_model=list)
async def test_2(input: int-> list:
return [] Wanted Codefrom fastapi import FastAPI
app = FastAPI()
@router.post("/have_output_example_and_schema")
async def test(input: int-> list:
return []
@router.post("/have_not_output_example_and_schema")
async def test_2(input: int-> list:
return [] AlternativesNo response Operating SystemWindows Operating System DetailsWindows 11 FastAPI Version0.75.0 Python VersionPython 3.10.4 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
This has been discarded earlier, like in #101 |
Beta Was this translation helpful? Give feedback.
-
Ah! I missed that, thanks. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the help here @chbndrhnns! 👏 🙇 Thanks for reporting back and closing the issue @AM-I-Human 👍 This is now supported (optionally) in the latest versions. 🚀
|
Beta Was this translation helpful? Give feedback.
This has been discarded earlier, like in #101