You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.4KB

  1. # @name: schemas.py
  2. # @creation_date: 2023-01-16
  3. # @license: The MIT License <https://opensource.org/licenses/MIT>
  4. # @author: Simon Bowie <ad7588@coventry.ac.uk>
  5. # @purpose: Data schemas for API export
  6. # @acknowledgements:
  7. # https://marshmallow.readthedocs.io/en/stable/quickstart.html#next-steps
  8. # https://stackoverflow.com/questions/59721478/serializing-sqlalchemy-with-marshmallow
  9. from . import ma
  10. from marshmallow import Schema
  11. # schema for JSON transformation of User table via Marshmallow
  12. class UserSchema(ma.Schema):
  13. class Meta:
  14. fields = ('id', 'email', 'name')
  15. ordered = True
  16. # schema for JSON transformation of Resource table via Marshmallow
  17. class ToolSchema(ma.Schema):
  18. class Meta:
  19. fields = ('id', 'name', 'description', 'developer', 'developerUrl', 'projectUrl', 'repositoryUrl', 'license', 'scriptingLanguage', 'expertiseToUse', 'expertiseToHost', 'dependencies', 'ingestFormats', 'outputFormats', 'status')
  20. ordered = True
  21. class PracticeSchema(ma.Schema):
  22. class Meta:
  23. fields = ('id', 'name', 'description', 'experimental', 'lessonsLearned', 'references')
  24. ordered = True
  25. class BookSchema(ma.Schema):
  26. class Meta:
  27. fields = ('id', 'name', 'description', 'author', 'year', 'bookUrl', 'isbn')
  28. ordered = True
  29. # subschemas for nested fields
  30. class DeveloperSchema(ma.Schema):
  31. class Meta:
  32. fields = ('developer', 'developerUrl')
  33. ordered = True