-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_app.py
70 lines (57 loc) · 1.43 KB
/
example_app.py
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
60
61
62
63
64
65
66
67
68
69
70
from typing import Optional
from tornado.web import url
from tornado.ioloop import IOLoop
from torn_open import (
AnnotatedHandler,
Application,
RequestModel,
ResponseModel,
ClientError,
tags,
summary,
)
class MyRequestModel(RequestModel):
"""
Docsting here will show up as description of the request model on redoc
"""
var1: str
var2: int
class MyResponseModel(ResponseModel):
"""
Docsting here will show up as description of the response on redoc
"""
path_param: str
query_parm: int
req_body: MyRequestModel
class MyAnnotatedHandler(AnnotatedHandler):
@tags("tag_1", "tag_2")
@summary("this is a summary")
def post(
self,
*,
path_param: str,
query_param: Optional[int] = 1,
req_body: MyRequestModel,
) -> MyResponseModel:
"""
Docstrings will show up as descriptions on redoc
"""
try:
"""do something here"""
except:
raise ClientError(status_code=403, error_type="forbiddon")
return MyResponseModel(
path_param=path_param,
query_param=query_param,
req_body=req_body,
)
def make_app():
return Application(
[
url(r"/annotated/(?P<path_param>[^/]+)", MyAnnotatedHandler),
],
)
if __name__ == "__main__":
app = make_app()
app.listen(8888)
IOLoop.current().start()