schema.py 1.8KB

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