mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-04 23:23:38 -04:00
✨ Add docs and tests for Python 3.9 and Python 3.10 (#3712)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
committed by
GitHub
parent
83f6781037
commit
d08a062ee2
32
docs_src/body_nested_models/tutorial007_py39.py
Normal file
32
docs_src/body_nested_models/tutorial007_py39.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel, HttpUrl
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Image(BaseModel):
|
||||
url: HttpUrl
|
||||
name: str
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
images: Optional[list[Image]] = None
|
||||
|
||||
|
||||
class Offer(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
items: list[Item]
|
||||
|
||||
|
||||
@app.post("/offers/")
|
||||
async def create_offer(offer: Offer):
|
||||
return offer
|
||||
Reference in New Issue
Block a user