@@ -20,10 +20,21 @@ def rule_to_apispec_path(rule: Rule, view: View, spec: APISpec):
20
20
Returns:
21
21
dict: APISpec `path` funtion argument dictionary
22
22
"""
23
+ if hasattr (view , "__apispec__" ):
24
+ description = getattr (view , "__apispec__" ).get ( # Look for view class API spec
25
+ "description"
26
+ ) or get_docstring ( # Or view class docstring
27
+ view
28
+ )
29
+ else :
30
+ description = get_docstring (view ) # Or view class docstring
31
+
23
32
params = {
24
33
"path" : rule_to_path (rule ),
25
- "operations" : view_to_apispec_operations (view , spec ),
26
- "description" : get_docstring (view ),
34
+ "operations" : view_to_apispec_operations (
35
+ view , spec , view_description = description
36
+ ),
37
+ "description" : description ,
27
38
"summary" : get_summary (view ),
28
39
}
29
40
@@ -40,7 +51,7 @@ def rule_to_apispec_path(rule: Rule, view: View, spec: APISpec):
40
51
return params
41
52
42
53
43
- def view_to_apispec_operations (view : View , spec : APISpec ):
54
+ def view_to_apispec_operations (view : View , spec : APISpec , view_description = None ):
44
55
"""Generate APISpec `operations` argument from a flask View
45
56
46
57
Args:
@@ -60,19 +71,25 @@ def view_to_apispec_operations(view: View, spec: APISpec):
60
71
for method in View .methods :
61
72
if hasattr (view , method ):
62
73
ops [method ] = {}
74
+ method_function = getattr (view , method )
75
+ description = (
76
+ getattr (method_function , "__apispec__" ).get (
77
+ "description"
78
+ ) # Look for APISpec
79
+ or get_docstring (method_function ) # Or function docstring
80
+ or view_description # Or inherit from view class
81
+ )
63
82
64
83
rupdate (
65
84
ops [method ],
66
85
{
67
- "description" : get_docstring ( getattr ( view , method )) ,
68
- "summary" : get_summary (getattr ( view , method ) ),
86
+ "description" : description ,
87
+ "summary" : get_summary (method_function ),
69
88
"tags" : inherited_tags ,
70
89
},
71
90
)
72
91
73
- rupdate (
74
- ops [method ], method_to_apispec_operation (getattr (view , method ), spec )
75
- )
92
+ rupdate (ops [method ], method_to_apispec_operation (method_function , spec ))
76
93
77
94
return ops
78
95
0 commit comments