-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfastapi_path_operation_config.py
More file actions
59 lines (44 loc) · 1.43 KB
/
fastapi_path_operation_config.py
File metadata and controls
59 lines (44 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from enum import Enum
from typing import Optional, Set
from fastapi import FastAPI, status
from pydantic import BaseModel
app = FastAPI()
class Tags(Enum):
items = "items"
users = "users"
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, tags=['items'])
@app.post(
"/items/",
response_model=Item,
status_code=status.HTTP_201_CREATED,
tags=[Tags.items],
summary="Create an item",
# description='Create an item with all the information, name, description, price',
response_description="The created item",
deprecated=True,
)
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
# @app.get('/items/', tags=['items'])
@app.get("/items/", tags=[Tags.items])
async def read_items():
return [{"name": "Foo", "price": 42}]
# @app.get('/users/', tags=['users'])
@app.get("/users/", tags=[Tags.users])
async def read_users():
return {"username": "johndoe"}
# PYTHONPATH=module_fastapi uvicorn fastapi_path_operation_config:app --reload