Add support for function return type annotations to declare the response_model (#1436)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
Yurii Karabas
2023-01-07 15:45:48 +02:00
committed by GitHub
parent efc12c5cdb
commit d0573f5713
18 changed files with 1368 additions and 58 deletions

View File

@@ -1,4 +1,4 @@
from typing import List, Union
from typing import Any, List, Union
from fastapi import FastAPI
from pydantic import BaseModel
@@ -15,5 +15,13 @@ class Item(BaseModel):
@app.post("/items/", response_model=Item)
async def create_item(item: Item):
async def create_item(item: Item) -> Any:
return item
@app.get("/items/", response_model=List[Item])
async def read_items() -> Any:
return [
{"name": "Portal Gun", "price": 42.0},
{"name": "Plumbus", "price": 32.0},
]