2
from typing import FrozenSet, Optional
4
from fastapi import FastAPI, Path, Query
9
@app.api_route("/api_route")
11
return {"message": "Hello World"}
14
def non_decorated_route():
15
return {"message": "Hello World"}
18
app.add_api_route("/non_decorated_route", non_decorated_route)
26
@app.get("/path/{item_id}")
31
@app.get("/path/str/{item_id}")
32
def get_str_id(item_id: str):
36
@app.get("/path/int/{item_id}")
37
def get_int_id(item_id: int):
41
@app.get("/path/float/{item_id}")
42
def get_float_id(item_id: float):
46
@app.get("/path/bool/{item_id}")
47
def get_bool_id(item_id: bool):
51
@app.get("/path/param/{item_id}")
52
def get_path_param_id(item_id: Optional[str] = Path()):
56
@app.get("/path/param-minlength/{item_id}")
57
def get_path_param_min_length(item_id: str = Path(min_length=3)):
61
@app.get("/path/param-maxlength/{item_id}")
62
def get_path_param_max_length(item_id: str = Path(max_length=3)):
66
@app.get("/path/param-min_maxlength/{item_id}")
67
def get_path_param_min_max_length(item_id: str = Path(max_length=3, min_length=2)):
71
@app.get("/path/param-gt/{item_id}")
72
def get_path_param_gt(item_id: float = Path(gt=3)):
76
@app.get("/path/param-gt0/{item_id}")
77
def get_path_param_gt0(item_id: float = Path(gt=0)):
81
@app.get("/path/param-ge/{item_id}")
82
def get_path_param_ge(item_id: float = Path(ge=3)):
86
@app.get("/path/param-lt/{item_id}")
87
def get_path_param_lt(item_id: float = Path(lt=3)):
91
@app.get("/path/param-lt0/{item_id}")
92
def get_path_param_lt0(item_id: float = Path(lt=0)):
96
@app.get("/path/param-le/{item_id}")
97
def get_path_param_le(item_id: float = Path(le=3)):
101
@app.get("/path/param-lt-gt/{item_id}")
102
def get_path_param_lt_gt(item_id: float = Path(lt=3, gt=1)):
106
@app.get("/path/param-le-ge/{item_id}")
107
def get_path_param_le_ge(item_id: float = Path(le=3, ge=1)):
111
@app.get("/path/param-lt-int/{item_id}")
112
def get_path_param_lt_int(item_id: int = Path(lt=3)):
116
@app.get("/path/param-gt-int/{item_id}")
117
def get_path_param_gt_int(item_id: int = Path(gt=3)):
121
@app.get("/path/param-le-int/{item_id}")
122
def get_path_param_le_int(item_id: int = Path(le=3)):
126
@app.get("/path/param-ge-int/{item_id}")
127
def get_path_param_ge_int(item_id: int = Path(ge=3)):
131
@app.get("/path/param-lt-gt-int/{item_id}")
132
def get_path_param_lt_gt_int(item_id: int = Path(lt=3, gt=1)):
136
@app.get("/path/param-le-ge-int/{item_id}")
137
def get_path_param_le_ge_int(item_id: int = Path(le=3, ge=1)):
143
return f"foo bar {query}"
146
@app.get("/query/optional")
147
def get_query_optional(query=None):
150
return f"foo bar {query}"
153
@app.get("/query/int")
154
def get_query_type(query: int):
155
return f"foo bar {query}"
158
@app.get("/query/int/optional")
159
def get_query_type_optional(query: Optional[int] = None):
162
return f"foo bar {query}"
165
@app.get("/query/int/default")
166
def get_query_type_int_default(query: int = 10):
167
return f"foo bar {query}"
170
@app.get("/query/param")
171
def get_query_param(query=Query(default=None)):
174
return f"foo bar {query}"
177
@app.get("/query/param-required")
178
def get_query_param_required(query=Query()):
179
return f"foo bar {query}"
182
@app.get("/query/param-required/int")
183
def get_query_param_required_type(query: int = Query()):
184
return f"foo bar {query}"
187
@app.get("/enum-status-code", status_code=http.HTTPStatus.CREATED)
188
def get_enum_status_code():
192
@app.get("/query/frozenset")
193
def get_query_type_frozenset(query: FrozenSet[int] = Query(...)):
194
return ",".join(map(str, sorted(query)))