-
Notifications
You must be signed in to change notification settings - Fork 19
/
response_shape.py
66 lines (53 loc) · 1.48 KB
/
response_shape.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
from swagger_schema import Schema
class ResponseShape(object):
"""
result shapes define the return format of the
response.
"""
@staticmethod
def create_body(result_dict):
"""
given the result dict from
transmute_func, return back the
response object.
"""
raise NotImplementedError()
@staticmethod
def swagger(result_schema):
"""
given the schema of the inner
result object, return back the
swagger schema representation.
"""
raise NotImplementedError()
class ResponseShapeSimple(ResponseShape):
""" return back just the result object. """
@staticmethod
def create_body(result_dict):
return result_dict["result"]
@staticmethod
def swagger(result_schema):
return result_schema
class ResponseShapeComplex(ResponseShape):
"""
return back an object with the result nested,
providing a little more context on the result:
* status code
* success
* result
"""
@staticmethod
def create_body(result_dict):
return result_dict
@staticmethod
def swagger(result_schema):
return Schema({
"title": "SuccessObject",
"type": "object",
"properties": {
"result": result_schema,
"success": {"type": "boolean"},
"code": {"type": "number"}
},
"required": ["success", "result", "code"]
})