@@ -20,10 +20,21 @@ def rule_to_apispec_path(rule: Rule, view: View, spec: APISpec):
2020    Returns: 
2121        dict: APISpec `path` funtion argument dictionary 
2222    """ 
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+ 
2332    params  =  {
2433        "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 ,
2738        "summary" : get_summary (view ),
2839    }
2940
@@ -40,7 +51,7 @@ def rule_to_apispec_path(rule: Rule, view: View, spec: APISpec):
4051    return  params 
4152
4253
43- def  view_to_apispec_operations (view : View , spec : APISpec ):
54+ def  view_to_apispec_operations (view : View , spec : APISpec ,  view_description = None ):
4455    """Generate APISpec `operations` argument from a flask View 
4556     
4657    Args: 
@@ -60,19 +71,25 @@ def view_to_apispec_operations(view: View, spec: APISpec):
6071    for  method  in  View .methods :
6172        if  hasattr (view , method ):
6273            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+             )
6382
6483            rupdate (
6584                ops [method ],
6685                {
67-                     "description" : get_docstring ( getattr ( view ,  method )) ,
68-                     "summary" : get_summary (getattr ( view ,  method ) ),
86+                     "description" : description ,
87+                     "summary" : get_summary (method_function ),
6988                    "tags" : inherited_tags ,
7089                },
7190            )
7291
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 ))
7693
7794    return  ops 
7895
0 commit comments