/
openapi.py
110 lines (77 loc) · 2 KB
/
openapi.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
This module provides decorators which append
documentation to operations and components created in the blueprints.
"""
from typing import Any
from . import operations
from .types import ( # noqa
Array,
Binary,
Boolean,
Byte,
Date,
DateTime,
Double,
Email,
Float,
Integer,
Long,
Object,
Password,
String,
Time,
)
def operation(name: str):
def inner(func):
operations[func].name(name)
return func
return inner
def summary(text: str):
def inner(func):
operations[func].describe(summary=text)
return func
return inner
def description(text: str):
def inner(func):
operations[func].describe(description=text)
return func
return inner
def document(url: str, description: str = None):
def inner(func):
operations[func].document(url, description)
return func
return inner
def tag(*args: str):
def inner(func):
operations[func].tag(*args)
return func
return inner
def deprecated():
def inner(func):
operations[func].deprecate()
return func
return inner
def body(content: Any, **kwargs):
def inner(func):
operations[func].body(content, **kwargs)
return func
return inner
def parameter(name: str, schema: Any, location: str = "query", **kwargs):
def inner(func):
operations[func].parameter(name, schema, location, **kwargs)
return func
return inner
def response(status, content: Any = None, description: str = None, **kwargs):
def inner(func):
operations[func].response(status, content, description, **kwargs)
return func
return inner
def secured(*args, **kwargs):
raise NotImplementedError(
"SecuritySchemas are not yet implemented in sanic-openapi 0.6.3, "
"hopefully they should be ready for the next release."
)
def inner(func):
operations[func].secured(*args, **kwargs)
return func
return inner