schema.py 1.7KB

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