mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 13:27:45 -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
@@ -11,7 +11,7 @@ class Item(BaseModel):
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: Set[str] = []
|
||||
tags: Set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, status_code=status.HTTP_201_CREATED)
|
||||
|
||||
17
docs_src/path_operation_configuration/tutorial001_py310.py
Normal file
17
docs_src/path_operation_configuration/tutorial001_py310.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from fastapi import FastAPI, status
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: str | None = None
|
||||
price: float
|
||||
tax: float | None = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, status_code=status.HTTP_201_CREATED)
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
19
docs_src/path_operation_configuration/tutorial001_py39.py
Normal file
19
docs_src/path_operation_configuration/tutorial001_py39.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI, status
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, status_code=status.HTTP_201_CREATED)
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
@@ -11,7 +11,7 @@ class Item(BaseModel):
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: Set[str] = []
|
||||
tags: Set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, tags=["items"])
|
||||
|
||||
27
docs_src/path_operation_configuration/tutorial002_py310.py
Normal file
27
docs_src/path_operation_configuration/tutorial002_py310.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, tags=["items"])
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
|
||||
|
||||
@app.get("/items/", tags=["items"])
|
||||
async def read_items():
|
||||
return [{"name": "Foo", "price": 42}]
|
||||
|
||||
|
||||
@app.get("/users/", tags=["users"])
|
||||
async def read_users():
|
||||
return [{"username": "johndoe"}]
|
||||
29
docs_src/path_operation_configuration/tutorial002_py39.py
Normal file
29
docs_src/path_operation_configuration/tutorial002_py39.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, tags=["items"])
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
|
||||
|
||||
@app.get("/items/", tags=["items"])
|
||||
async def read_items():
|
||||
return [{"name": "Foo", "price": 42}]
|
||||
|
||||
|
||||
@app.get("/users/", tags=["users"])
|
||||
async def read_users():
|
||||
return [{"username": "johndoe"}]
|
||||
@@ -11,7 +11,7 @@ class Item(BaseModel):
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: Set[str] = []
|
||||
tags: Set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
|
||||
22
docs_src/path_operation_configuration/tutorial003_py310.py
Normal file
22
docs_src/path_operation_configuration/tutorial003_py310.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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: set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
"/items/",
|
||||
response_model=Item,
|
||||
summary="Create an item",
|
||||
description="Create an item with all the information, name, description, price, tax and a set of unique tags",
|
||||
)
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
24
docs_src/path_operation_configuration/tutorial003_py39.py
Normal file
24
docs_src/path_operation_configuration/tutorial003_py39.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
"/items/",
|
||||
response_model=Item,
|
||||
summary="Create an item",
|
||||
description="Create an item with all the information, name, description, price, tax and a set of unique tags",
|
||||
)
|
||||
async def create_item(item: Item):
|
||||
return item
|
||||
@@ -11,7 +11,7 @@ class Item(BaseModel):
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: Set[str] = []
|
||||
tags: Set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, summary="Create an item")
|
||||
|
||||
26
docs_src/path_operation_configuration/tutorial004_py310.py
Normal file
26
docs_src/path_operation_configuration/tutorial004_py310.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, summary="Create an item")
|
||||
async def create_item(item: Item):
|
||||
"""
|
||||
Create an item with all the information:
|
||||
|
||||
- **name**: each item must have a name
|
||||
- **description**: a long description
|
||||
- **price**: required
|
||||
- **tax**: if the item doesn't have tax, you can omit this
|
||||
- **tags**: a set of unique tag strings for this item
|
||||
"""
|
||||
return item
|
||||
28
docs_src/path_operation_configuration/tutorial004_py39.py
Normal file
28
docs_src/path_operation_configuration/tutorial004_py39.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post("/items/", response_model=Item, summary="Create an item")
|
||||
async def create_item(item: Item):
|
||||
"""
|
||||
Create an item with all the information:
|
||||
|
||||
- **name**: each item must have a name
|
||||
- **description**: a long description
|
||||
- **price**: required
|
||||
- **tax**: if the item doesn't have tax, you can omit this
|
||||
- **tags**: a set of unique tag strings for this item
|
||||
"""
|
||||
return item
|
||||
@@ -11,7 +11,7 @@ class Item(BaseModel):
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: Set[str] = []
|
||||
tags: Set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
|
||||
31
docs_src/path_operation_configuration/tutorial005_py310.py
Normal file
31
docs_src/path_operation_configuration/tutorial005_py310.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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: set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
"/items/",
|
||||
response_model=Item,
|
||||
summary="Create an item",
|
||||
response_description="The created item",
|
||||
)
|
||||
async def create_item(item: Item):
|
||||
"""
|
||||
Create an item with all the information:
|
||||
|
||||
- **name**: each item must have a name
|
||||
- **description**: a long description
|
||||
- **price**: required
|
||||
- **tax**: if the item doesn't have tax, you can omit this
|
||||
- **tags**: a set of unique tag strings for this item
|
||||
"""
|
||||
return item
|
||||
33
docs_src/path_operation_configuration/tutorial005_py39.py
Normal file
33
docs_src/path_operation_configuration/tutorial005_py39.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import FastAPI
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class Item(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
price: float
|
||||
tax: Optional[float] = None
|
||||
tags: set[str] = set()
|
||||
|
||||
|
||||
@app.post(
|
||||
"/items/",
|
||||
response_model=Item,
|
||||
summary="Create an item",
|
||||
response_description="The created item",
|
||||
)
|
||||
async def create_item(item: Item):
|
||||
"""
|
||||
Create an item with all the information:
|
||||
|
||||
- **name**: each item must have a name
|
||||
- **description**: a long description
|
||||
- **price**: required
|
||||
- **tax**: if the item doesn't have tax, you can omit this
|
||||
- **tags**: a set of unique tag strings for this item
|
||||
"""
|
||||
return item
|
||||
Reference in New Issue
Block a user