-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_schemas.py
177 lines (119 loc) · 5.85 KB
/
api_schemas.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""
API Schemas Module for Application
Version: 1.0.0
"""
from marshmallow import Schema, fields, validate
from application.enums.messages import MessagesEnum
from application.openapi.schemas import DeletionSchema, RequestControlSchema, MetaSchema, LinkSchema, ErrorSchema, \
HateosDefaultListResponseSchema, DefaultResponseSchema, HateosDefaultResponseSchema
# ***************************
# Product
# ***************************
class ProductSchema(Schema):
id = fields.Int(example=1)
sku = fields.Int(example=1)
name = fields.Str(example="Common Pencil")
description = fields.Str(example="Common Pencil Description")
supplier_id = fields.Int(example=1)
created_at = fields.DateTime()
updated_at = fields.DateTime()
deleted_at = fields.DateTime()
active = fields.Int(validate=validate.OneOf([0, 1]))
uuid = fields.UUID(example="4bcad46b-6978-488f-8153-1c49f8a45244")
class HateosProductListResponseSchema(HateosDefaultListResponseSchema):
data = fields.List(fields.Nested(ProductSchema))
control = fields.Nested(RequestControlSchema)
class ProductListResponseSchema(DefaultResponseSchema):
data = fields.List(fields.Nested(ProductSchema))
control = fields.Nested(RequestControlSchema)
class ProductListErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.LIST_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.LIST_ERROR.label)
message = fields.Str(example=MessagesEnum.LIST_ERROR.message)
class ProductGetResponseSchema(DefaultResponseSchema):
data = fields.Nested(ProductSchema)
class HateosProductGetResponseSchema(HateosDefaultResponseSchema):
data = fields.Nested(ProductSchema)
class ProductGetErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.FIND_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.FIND_ERROR.label)
message = fields.Str(example=MessagesEnum.FIND_ERROR.message)
class ProductCreateRequestSchema(Schema):
sku = fields.Int(example=1)
name = fields.Str(example="Common Pencil")
description = fields.Str(example="Common Pencil description")
supplier_id = fields.Int(example=1)
active = fields.Int(validate=validate.OneOf([0, 1]))
class ProductCreateResponseSchema(DefaultResponseSchema):
data = fields.Nested(ProductSchema)
class ProductCreateErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.CREATE_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.CREATE_ERROR.label)
message = fields.Str(example=MessagesEnum.CREATE_ERROR.message)
class ProductCompleteUpdateRequestSchema(ProductCreateRequestSchema):
pass
class ProductUpdateResponseSchema(ProductCreateResponseSchema):
pass
class ProductUpdateErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.UPDATE_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.UPDATE_ERROR.label)
message = fields.Str(example=MessagesEnum.UPDATE_ERROR.message)
class ProductSoftUpdateRequestSchema(Schema):
field = fields.Str(example="value")
class ProductSoftDeleteResponseSchema(DefaultResponseSchema):
data = fields.Dict(example={"deleted": True})
class ProductDeleteResponseSchema(Schema):
data = fields.Dict(example={"deleted": True})
class ProductSoftDeleteErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.SOFT_DELETE_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.SOFT_DELETE_ERROR.label)
message = fields.Str(example=MessagesEnum.SOFT_DELETE_ERROR.message)
class ProductDeleteErrorResponseSchema(ErrorSchema):
code = fields.Int(example=MessagesEnum.DELETE_ERROR.code, required=True)
label = fields.Str(example=MessagesEnum.DELETE_ERROR.label)
message = fields.Str(example=MessagesEnum.DELETE_ERROR.message)
# ***************************
# Event
# ***************************
class EventSchema(Schema):
type = fields.Str()
data = fields.Dict()
date = fields.DateTime(example="2021-05-03T19:41:36.315842-03:00")
hash = fields.Str(example="406cce9743906f7b8d7dd5d5c5d8c95d820eeefd72a3a554a4a726d022d8fa19")
class EventCreateRequestSchema(EventSchema):
pass
class EventUpdateRequestSchema(EventCreateRequestSchema):
pass
class EventListResponseSchema(DefaultResponseSchema):
data = fields.List(fields.Nested(EventSchema))
control = fields.Nested(RequestControlSchema)
meta = fields.Nested(MetaSchema)
links = fields.List(fields.Nested(LinkSchema))
class EventListErrorResponseSchema(ErrorSchema):
pass
class EventGetResponseSchema(Schema):
data = fields.Nested(EventSchema)
control = fields.Nested(RequestControlSchema)
meta = fields.Nested(MetaSchema)
links = fields.List(fields.Nested(LinkSchema))
class EventCreateResponseSchema(Schema):
result = fields.Bool(example=True)
event_hash = fields.Str(example="c82bf3ee20dd2f4ae7109e52d313a3190f1a85ba3362c54d3eb6257bd0c4d69d")
code = fields.Int(example=MessagesEnum.EVENT_REGISTERED_WITH_SUCCESS.code)
label = fields.String(example=MessagesEnum.EVENT_REGISTERED_WITH_SUCCESS.label)
message = fields.String(example=MessagesEnum.EVENT_REGISTERED_WITH_SUCCESS.message)
params = fields.List(fields.Str())
class EventCreateErrorResponseSchema(Schema):
result = fields.Bool(example=False)
event_hash = fields.Str(example=None)
code = fields.Int(example=MessagesEnum.EVENT_TYPE_UNKNOWN_ERROR.code)
label = fields.String(example=MessagesEnum.EVENT_TYPE_UNKNOWN_ERROR.label)
message = fields.String(example=MessagesEnum.EVENT_TYPE_UNKNOWN_ERROR.message)
params = fields.List(fields.Str())
class EventUpdateResponseSchema(EventGetResponseSchema):
pass
class EventDeleteResponseSchema(EventGetResponseSchema):
data = fields.Nested(DeletionSchema)
def register():
# simple function only to force the import of the script on app.py
pass