✨ Add support for dataclasses in request bodies and response_model (#3577)

This commit is contained in:
Sebastián Ramírez authored and GitHub committed 2021-07-21 19:54:08 +02:00
1 parent 75d8a6b5c2
commit 684c0077cc
10 files changed
+562

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
from dataclasses import dataclass, field
from typing import List, Optional
from fastapi import FastAPI
@dataclass
class Item:
name: str
price: float
tags: List[str] = field(default_factory=list)
description: Optional[str] = None
tax: Optional[float] = None
app = FastAPI()
@app.get("/items/next", response_model=Item)
async def read_next_item():
return {
"name": "Island In The Moon",
"price": 12.99,
"description": "A place to be be playin' and havin' fun",
"tags": ["breater"],
}