schema.py 1.8KB

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