-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This is Scheme, a framework for specifying structured and validated data for API resources. A schema is a structural set of field declarations for a data structure which enables parsing, validating and serializing/unserializing that data structure. Schemas are used extensively in Mesh: for API resource attributes, the content of requests of a resource and the content of responses to requests. However, schemas are a sufficiently general concept to warrant the creation of Scheme as its own project.
Basically, schemas consist of field declarations, which may either be data fields such as integers, strings and dates, or structure fields such as maps and lists. Scheme data types may be converted to native data types in many programming languages; currently Python and Javascript are supported. While the field types provided by Scheme should be suitable for most purposes, custom fields can be implemented.
See Fields for the list of supported fields.
Here is a simple definition of a blog as a Mesh resource, using Scheme for resource field definitions
class Blog(Resource):
'''Definition of a blog'''
name = 'blog'
version = 1
class schema:
id = Integer()
title = Text()
posts = Sequence(Integer())
class Post(Resource):
'''Definition of a blog post'''
name = 'post'
version = 1
class schema:
id = Integer()
title = Text()
author = Text()
body = Text()
blog = Integer()
keywords = Sequence(Text())
creation_time = Datetime()
last_update_time = Datetime()