Completed
Push — master ( fe6d7a...5e9dbb )
by
unknown
02:04
created

tracim.views.example_api.schema   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 35
dl 0
loc 56
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
import marshmallow
3
4
5
class NoContentSchema(marshmallow.Schema):
6
    pass
7
8
9
class AboutResponseSchema(marshmallow.Schema):
10
    version = marshmallow.fields.String(required=True,)
11
    datetime = marshmallow.fields.DateTime(required=True)
12
13
14
class UserPathSchema(marshmallow.Schema):
15
    id = marshmallow.fields.Int(
16
        required=True,
17
        validate=marshmallow.validate.Range(min=1),
18
    )
19
20
21
class UserSchema(marshmallow.Schema):
22
    id = marshmallow.fields.Int(required=True)
23
    username = marshmallow.fields.String(
24
        required=True,
25
        validate = marshmallow.validate.Regexp(regex='[\w-]+'),
26
    )
27
    email_address = marshmallow.fields.Email(required=True)
28
    first_name = marshmallow.fields.String(required=True)
29
    last_name = marshmallow.fields.String(required=True)
30
    display_name = marshmallow.fields.String(required=True)
31
    company = marshmallow.fields.String(required=True)
32
33
34
class PaginationSchema(marshmallow.Schema):
35
    first_id = marshmallow.fields.Int(required=True)
36
    last_id = marshmallow.fields.Int(required=True)
37
    current_id = marshmallow.fields.Int(required=True)
38
39
40
class ListsUserSchema(marshmallow.Schema):
41
    item_nb = marshmallow.fields.Int(
42
        required=True,
43
        validate=marshmallow.validate.Range(min=0)
44
    )
45
    items = marshmallow.fields.Nested(
46
        UserSchema,
47
        many=True,
48
        only=['id', 'username', 'display_name', 'company']
49
    )
50
    # TODO - G.M - 2017-12-05 - Fix nested schema import into doc !
51
    # Can't add doc for nested Schema properly
52
    # When schema item isn't added through their own method
53
    # Ex : Pagination Schema doesn't work here but UserSchema is ok.
54
    pagination = marshmallow.fields.Nested(
55
        PaginationSchema
56
    )
57