9 changed files with 156 additions and 0 deletions
@ -0,0 +1,9 @@ |
|||||
|
from typing import Union |
||||
|
|
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
@ -0,0 +1,7 @@ |
|||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: str | None = None |
||||
|
size: float |
||||
@ -0,0 +1,18 @@ |
|||||
|
from typing import Union |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/") |
||||
|
async def create_item(item: Item) -> Item: |
||||
|
return item |
||||
@ -0,0 +1,16 @@ |
|||||
|
from fastapi import FastAPI |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: str | None = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/") |
||||
|
async def create_item(item: Item) -> Item: |
||||
|
return item |
||||
@ -0,0 +1,25 @@ |
|||||
|
from typing import Union |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from pydantic import BaseModel as BaseModelV2 |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
class ItemV2(BaseModelV2): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/", response_model=ItemV2) |
||||
|
async def create_item(item: Item): |
||||
|
return item |
||||
@ -0,0 +1,23 @@ |
|||||
|
from fastapi import FastAPI |
||||
|
from pydantic import BaseModel as BaseModelV2 |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: str | None = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
class ItemV2(BaseModelV2): |
||||
|
name: str |
||||
|
description: str | None = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/", response_model=ItemV2) |
||||
|
async def create_item(item: Item): |
||||
|
return item |
||||
@ -0,0 +1,20 @@ |
|||||
|
from typing import Union |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from fastapi.temp_pydantic_v1_params import Body |
||||
|
from pydantic.v1 import BaseModel |
||||
|
from typing_extensions import Annotated |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/") |
||||
|
async def create_item(item: Annotated[Item, Body(embed=True)]) -> Item: |
||||
|
return item |
||||
@ -0,0 +1,19 @@ |
|||||
|
from typing import Annotated |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from fastapi.temp_pydantic_v1_params import Body |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: str | None = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/") |
||||
|
async def create_item(item: Annotated[Item, Body(embed=True)]) -> Item: |
||||
|
return item |
||||
@ -0,0 +1,19 @@ |
|||||
|
from typing import Annotated, Union |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from fastapi.temp_pydantic_v1_params import Body |
||||
|
from pydantic.v1 import BaseModel |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Union[str, None] = None |
||||
|
size: float |
||||
|
|
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
|
||||
|
@app.post("/items/") |
||||
|
async def create_item(item: Annotated[Item, Body(embed=True)]) -> Item: |
||||
|
return item |
||||
Loading…
Reference in new issue