10
10
11
11
from .. import fields
12
12
from ..json .schemas import schema_to_json
13
- from ..schema import EventSchema , ActionSchema , Schema , build_action_schema
13
+ from ..schema import EventSchema , ActionSchema
14
14
from ..utilities import get_docstring , get_summary , merge
15
15
from .utilities import ensure_schema , get_marshamallow_plugin
16
16
from ..views import ActionView , EventView , PropertyView , View
@@ -54,6 +54,7 @@ class MarshmallowPlugin(_MarshmallowPlugin):
54
54
55
55
class FlaskLabThingsPlugin (BasePlugin ):
56
56
"""APIspec plugin for Flask LabThings"""
57
+ spec = None
57
58
58
59
def init_spec (self , spec ):
59
60
self .spec = spec
@@ -67,14 +68,18 @@ def spec_for_interaction(cls, interaction):
67
68
if hasattr (interaction , method ):
68
69
prop = getattr (interaction , method )
69
70
d [method ] = {
70
- "description" : getattr (prop , "description" , None )
71
- or get_docstring (prop , remove_newlines = False )
72
- or getattr (interaction , "description" , None )
73
- or get_docstring (interaction , remove_newlines = False ),
74
- "summary" : getattr (prop , "summary" , None )
75
- or get_summary (prop )
76
- or getattr (interaction , "summary" , None )
77
- or get_summary (interaction ),
71
+ "description" : (
72
+ getattr (prop , "description" , None )
73
+ or get_docstring (prop , remove_newlines = False )
74
+ or getattr (interaction , "description" , None )
75
+ or get_docstring (interaction , remove_newlines = False )
76
+ ),
77
+ "summary" : (
78
+ getattr (prop , "summary" , None )
79
+ or get_summary (prop )
80
+ or getattr (interaction , "summary" , None )
81
+ or get_summary (interaction )
82
+ ),
78
83
"tags" : list (interaction .get_tags ()),
79
84
"responses" : {
80
85
"5XX" : {
@@ -92,9 +97,14 @@ def spec_for_interaction(cls, interaction):
92
97
},
93
98
}
94
99
},
100
+ "parameters" : [],
95
101
}
96
- if hasattr (prop , "responses" ):
97
- d [method ]["responses" ].update (prop .responses )
102
+ # Allow custom responses from the class, overridden by the method
103
+ d [method ]["responses" ].update (getattr (interaction , "responses" , {}))
104
+ d [method ]["responses" ].update (getattr (prop , "responses" , {}))
105
+ # Allow custom parameters from the class & method
106
+ d [method ]["parameters" ].extend (getattr (interaction , "parameters" , {}))
107
+ d [method ]["parameters" ].extend (getattr (prop , "parameters" , {}))
98
108
return d
99
109
100
110
@classmethod
0 commit comments