@@ -113,15 +113,14 @@ def represent_response(self, response):
113
113
114
114
115
115
class ActionView (View ):
116
- # TODO: Better support for overriding content type
117
- # TODO: Better support for custom 200 responses
118
-
119
116
# Data formatting
120
117
schema : Schema = None
121
118
args : dict = None
122
119
semtype : str = None
123
120
124
121
# Spec overrides
122
+ content_type = "application/json" # Input contentType
123
+ response_content_type = "application/json" # Output contentType
125
124
responses = {} # Custom responses for invokeaction
126
125
127
126
# Spec parameters
@@ -151,28 +150,38 @@ def get_apispec(cls):
151
150
"tags" : list (cls .get_tags ()),
152
151
"requestBody" : {
153
152
"content" : {
154
- "application/json" : (
155
- {"schema" : class_args } if class_args else {}
156
- )
153
+ cls .content_type : ({"schema" : class_args } if class_args else {})
157
154
}
158
155
},
159
156
"responses" : {
160
- # Our POST 201 will usually be application/json
157
+ 200 : {
158
+ # Allow customising 200 (immediate response) content type
159
+ "content_type" : cls .response_content_type ,
160
+ "description" : "Action completed immediately" ,
161
+ ** (
162
+ # If an action JSON schema is defined, set the response schema
163
+ {"schema" : action_json_schema }
164
+ if (action_json_schema )
165
+ else {}
166
+ ),
167
+ },
168
+ # Our POST 201 MUST be application/json
169
+ # Responses like images must be added as 200 responses with cls.responses = {200: {...}}
161
170
201 : {
162
171
"content_type" : "application/json" ,
163
172
"description" : "Action started" ,
164
173
** (
165
174
{"schema" : action_json_schema } if action_json_schema else {}
166
175
),
167
- }
176
+ },
168
177
},
169
178
},
170
179
"get" : {
171
180
"description" : "Action queue" ,
172
181
"summary" : "Action queue" ,
173
182
"tags" : list (cls .get_tags ()),
174
183
"responses" : {
175
- # Our GET 200 will usually be application/json
184
+ # Our GET 200 MUST be application/json
176
185
200 : {
177
186
"content_type" : "application/json" ,
178
187
"description" : "Action started" ,
@@ -212,7 +221,6 @@ def dispatch_request(self, *args, **kwargs):
212
221
# Wait up to 2 second for the action to complete or error
213
222
try :
214
223
task .get (block = True , timeout = 1 )
215
- logging .debug ("Got Action response quickly" )
216
224
except Timeout :
217
225
pass
218
226
@@ -231,6 +239,7 @@ class PropertyView(View):
231
239
semtype : str = None
232
240
233
241
# Spec overrides
242
+ content_type = "application/json" # Input and output contentType
234
243
responses = {} # Custom responses for invokeaction
235
244
236
245
_cls_tags = {"properties" }
@@ -250,7 +259,7 @@ def get_apispec(cls):
250
259
"tags" : list (cls .get_tags ()),
251
260
"requestBody" : {
252
261
"content" : {
253
- "application/json" : (
262
+ cls . content_type : (
254
263
{"schema" : class_json_schema }
255
264
if class_json_schema
256
265
else {}
@@ -259,7 +268,7 @@ def get_apispec(cls):
259
268
},
260
269
"responses" : {
261
270
200 : {
262
- "content_type" : "application/json" ,
271
+ "content_type" : cls . content_type ,
263
272
"description" : "Write property" ,
264
273
** (
265
274
{"schema" : class_json_schema }
0 commit comments