For example, you can pass an `example` for a body request to `Body`:
-```Python hl_lines="20 21 22 23 24 25"
+```Python hl_lines="19 20 21 22 23 24"
{!../../../docs_src/schema_extra_example/tutorial003.py!}
```
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item = Body(..., embed=True)):
+async def update_item(item_id: int, item: Item = Body(..., embed=True)):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item, user: User):
+async def update_item(item_id: int, item: Item, user: User):
results = {"item_id": item_id, "item": item, "user": user}
return results
@app.put("/items/{item_id}")
async def update_item(
- *, item_id: int, item: Item, user: User, importance: int = Body(...)
+ item_id: int, item: Item, user: User, importance: int = Body(...)
):
results = {"item_id": item_id, "item": item, "user": user, "importance": importance}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item = Body(..., embed=True)):
+async def update_item(item_id: int, item: Item = Body(..., embed=True)):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.post("/offers/")
-async def create_offer(*, offer: Offer):
+async def create_offer(offer: Offer):
return offer
@app.post("/images/multiple/")
-async def create_multiple_images(*, images: List[Image]):
+async def create_multiple_images(images: List[Image]):
return images
@app.get("/items/")
-async def read_items(*, ads_id: str = Cookie(None)):
+async def read_items(ads_id: str = Cookie(None)):
return {"ads_id": ads_id}
@app.post("/user/", response_model=UserOut)
-async def create_user(*, user_in: UserIn):
+async def create_user(user_in: UserIn):
user_saved = fake_save_user(user_in)
return user_saved
@app.post("/user/", response_model=UserOut)
-async def create_user(*, user_in: UserIn):
+async def create_user(user_in: UserIn):
user_saved = fake_save_user(user_in)
return user_saved
@app.get("/items/")
-async def read_items(*, user_agent: str = Header(None)):
+async def read_items(user_agent: str = Header(None)):
return {"User-Agent": user_agent}
@app.get("/items/")
-async def read_items(*, strange_header: str = Header(None, convert_underscores=False)):
+async def read_items(strange_header: str = Header(None, convert_underscores=False)):
return {"strange_header": strange_header}
@app.post("/items/", response_model=Item, summary="Create an item")
-async def create_item(*, item: Item):
+async def create_item(item: Item):
"""
Create an item with all the information:
@app.post("/items/", response_model=Item, status_code=status.HTTP_201_CREATED)
-async def create_item(*, item: Item):
+async def create_item(item: Item):
return item
@app.post("/items/", response_model=Item, tags=["items"])
-async def create_item(*, item: Item):
+async def create_item(item: Item):
return 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):
+async def create_item(item: Item):
return item
@app.post("/items/", response_model=Item, summary="Create an item")
-async def create_item(*, item: Item):
+async def create_item(item: Item):
"""
Create an item with all the information:
summary="Create an item",
response_description="The created item",
)
-async def create_item(*, item: Item):
+async def create_item(item: Item):
"""
Create an item with all the information:
@app.post("/login/")
-async def login(*, username: str = Form(...), password: str = Form(...)):
+async def login(username: str = Form(...), password: str = Form(...)):
return {"username": username}
# Don't do this in production!
@app.post("/user/", response_model=UserIn)
-async def create_user(*, user: UserIn):
+async def create_user(user: UserIn):
return user
@app.post("/user/", response_model=UserOut)
-async def create_user(*, user: UserIn):
+async def create_user(user: UserIn):
return user
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
-async def update_item(*, item_id: int, item: Item):
+async def update_item(item_id: int, item: Item):
results = {"item_id": item_id, "item": item}
return results
@app.put("/items/{item_id}")
async def update_item(
- *,
item_id: int,
item: Item = Body(
...,
"price": 35.4,
"tax": 3.2,
},
- )
+ ),
):
results = {"item_id": item_id, "item": item}
return results
return user
-def create_access_token(*, data: dict, expires_delta: timedelta = None):
+def create_access_token(data: dict, expires_delta: timedelta = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
return user
-def create_access_token(*, data: dict, expires_delta: timedelta = None):
+def create_access_token(data: dict, expires_delta: timedelta = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta