forked from tiangolo/fastapi
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for function return type annotations to declare the `re…
…sponse_model` (tiangolo#1436) Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
- Loading branch information
Showing
18 changed files
with
1,368 additions
and
58 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import List, Union | ||
|
||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class Item(BaseModel): | ||
name: str | ||
description: Union[str, None] = None | ||
price: float | ||
tax: Union[float, None] = None | ||
tags: List[str] = [] | ||
|
||
|
||
@app.post("/items/") | ||
async def create_item(item: Item) -> Item: | ||
return item | ||
|
||
|
||
@app.get("/items/") | ||
async def read_items() -> List[Item]: | ||
return [ | ||
Item(name="Portal Gun", price=42.0), | ||
Item(name="Plumbus", price=32.0), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class Item(BaseModel): | ||
name: str | ||
description: str | None = None | ||
price: float | ||
tax: float | None = None | ||
tags: list[str] = [] | ||
|
||
|
||
@app.post("/items/") | ||
async def create_item(item: Item) -> Item: | ||
return item | ||
|
||
|
||
@app.get("/items/") | ||
async def read_items() -> list[Item]: | ||
return [ | ||
Item(name="Portal Gun", price=42.0), | ||
Item(name="Plumbus", price=32.0), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Union | ||
|
||
from fastapi import FastAPI | ||
from pydantic import BaseModel | ||
|
||
app = FastAPI() | ||
|
||
|
||
class Item(BaseModel): | ||
name: str | ||
description: Union[str, None] = None | ||
price: float | ||
tax: Union[float, None] = None | ||
tags: list[str] = [] | ||
|
||
|
||
@app.post("/items/") | ||
async def create_item(item: Item) -> Item: | ||
return item | ||
|
||
|
||
@app.get("/items/") | ||
async def read_items() -> list[Item]: | ||
return [ | ||
Item(name="Portal Gun", price=42.0), | ||
Item(name="Plumbus", price=32.0), | ||
] |
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
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
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
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
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
Oops, something went wrong.