mirror of https://github.com/tiangolo/fastapi.git
Remove code examples for Python 3.8 in `body_multiple_params`
This commit is contained in:
parent
332b405af0
commit
05ac6f14b7
|
|
@ -1,28 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI, Path
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: float
|
|
||||||
tax: Union[float, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
|
||||||
async def update_item(
|
|
||||||
item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)],
|
|
||||||
q: Union[str, None] = None,
|
|
||||||
item: Union[Item, None] = None,
|
|
||||||
):
|
|
||||||
results = {"item_id": item_id}
|
|
||||||
if q:
|
|
||||||
results.update({"q": q})
|
|
||||||
if item:
|
|
||||||
results.update({"item": item})
|
|
||||||
return results
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import Body, FastAPI
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: float
|
|
||||||
tax: Union[float, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
class User(BaseModel):
|
|
||||||
username: str
|
|
||||||
full_name: Union[str, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
|
||||||
async def update_item(
|
|
||||||
item_id: int, item: Item, user: User, importance: Annotated[int, Body()]
|
|
||||||
):
|
|
||||||
results = {"item_id": item_id, "item": item, "user": user, "importance": importance}
|
|
||||||
return results
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import Body, FastAPI
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: float
|
|
||||||
tax: Union[float, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
class User(BaseModel):
|
|
||||||
username: str
|
|
||||||
full_name: Union[str, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
|
||||||
async def update_item(
|
|
||||||
*,
|
|
||||||
item_id: int,
|
|
||||||
item: Item,
|
|
||||||
user: User,
|
|
||||||
importance: Annotated[int, Body(gt=0)],
|
|
||||||
q: Union[str, None] = None,
|
|
||||||
):
|
|
||||||
results = {"item_id": item_id, "item": item, "user": user, "importance": importance}
|
|
||||||
if q:
|
|
||||||
results.update({"q": q})
|
|
||||||
return results
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import Body, FastAPI
|
|
||||||
from pydantic import BaseModel
|
|
||||||
from typing_extensions import Annotated
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
description: Union[str, None] = None
|
|
||||||
price: float
|
|
||||||
tax: Union[float, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
|
||||||
async def update_item(item_id: int, item: Annotated[Item, Body(embed=True)]):
|
|
||||||
results = {"item_id": item_id, "item": item}
|
|
||||||
return results
|
|
||||||
|
|
@ -4,16 +4,15 @@ import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from ...utils import needs_py39, needs_py310
|
from ...utils import needs_py310
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="client",
|
name="client",
|
||||||
params=[
|
params=[
|
||||||
"tutorial001",
|
"tutorial001_py39",
|
||||||
pytest.param("tutorial001_py310", marks=needs_py310),
|
pytest.param("tutorial001_py310", marks=needs_py310),
|
||||||
"tutorial001_an",
|
"tutorial001_an_py39",
|
||||||
pytest.param("tutorial001_an_py39", marks=needs_py39),
|
|
||||||
pytest.param("tutorial001_an_py310", marks=needs_py310),
|
pytest.param("tutorial001_an_py310", marks=needs_py310),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,15 @@ import pytest
|
||||||
from dirty_equals import IsDict
|
from dirty_equals import IsDict
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from ...utils import needs_py39, needs_py310
|
from ...utils import needs_py310
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="client",
|
name="client",
|
||||||
params=[
|
params=[
|
||||||
"tutorial003",
|
"tutorial003_py39",
|
||||||
pytest.param("tutorial003_py310", marks=needs_py310),
|
pytest.param("tutorial003_py310", marks=needs_py310),
|
||||||
"tutorial003_an",
|
"tutorial003_an_py39",
|
||||||
pytest.param("tutorial003_an_py39", marks=needs_py39),
|
|
||||||
pytest.param("tutorial003_an_py310", marks=needs_py310),
|
pytest.param("tutorial003_an_py310", marks=needs_py310),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue