class MainDataItem(schema.SchemaCompoundedAttribute): type = schema.SchemaAttribute(data_type=str) id = schema.SchemaAttribute(data_type=str) attributes = schema.SchemaFreeContentCompoundedAttribute( attributes_mapping, required=False) links = LinksObject(required=False) relationships = schema.SchemaFreeContentCompoundedAttribute( relationships_type_mapping, required=False)
class UserSchema(schema.Schema): username = schema.SchemaAttribute(str) first_name = schema.SchemaAttribute(str, required=False, required_with=['birth_date']) email = schema.SchemaAttribute(str) is_active = schema.SchemaAttribute(bool) birth_date = schema.SchemaAttribute(str, required=False)
class RelationshipLinksObject(LinksObject): related = schema.SchemaAttribute(data_type=str)
class LinksObject(schema.SchemaCompoundedAttribute): self = schema.SchemaAttribute(data_type=str)
class RelationshipItemData(schema.SchemaCompoundedAttribute): type = schema.SchemaAttribute(data_type=str) id = schema.SchemaAttribute(data_type=str)
import schema class LinksObject(schema.SchemaCompoundedAttribute): self = schema.SchemaAttribute(data_type=str) class RelationshipLinksObject(LinksObject): related = schema.SchemaAttribute(data_type=str) attributes_mapping = {str: schema.SchemaAttribute(data_type=str)} class RelationshipItemData(schema.SchemaCompoundedAttribute): type = schema.SchemaAttribute(data_type=str) id = schema.SchemaAttribute(data_type=str) relationships_data_type_mapping = { dict: RelationshipItemData(), list: schema.SchemaCollectionAttribute(inner_attribute=RelationshipItemData()) } class RelationshipItem(schema.SchemaCompoundedAttribute): links = RelationshipLinksObject(required=False) data = schema.SchemaFreeTypeAttribute( mapping=relationships_data_type_mapping)
class Post(schema.SchemaCompoundedAttribute): title = schema.SchemaAttribute(data_type=str) tags = schema.SchemaCollectionAttribute( inner_attribute=schema.SchemaAttribute(data_type=str))
class UserAppearance(schema.SchemaCompoundedAttribute): height = schema.SchemaAttribute(data_type=str) age = schema.SchemaAttribute(data_type=int)
class ProfileSchema(schema.SchemaCompoundedAttribute): last_logged = schema.SchemaAttribute(str) settings = Settings()
class Settings(schema.SchemaCompoundedAttribute): profile_color = schema.SchemaAttribute(str) stay_logged = schema.SchemaAttribute(bool)
'settings': { 'profile_color': 'green', 'stay_logged': True } } } example_compounded_user_data.update(profile_data) class UserAppearance(schema.SchemaCompoundedAttribute): height = schema.SchemaAttribute(data_type=str) age = schema.SchemaAttribute(data_type=int) user_attribute_mapping = { str: schema.SchemaAttribute(data_type=str), dict: UserAppearance(data_type=dict) } example_free_content_user_data = copy.deepcopy(example_compounded_user_data) attributes_data = { 'attributes': { 'surname': 'Kolik', 'job': 'Programmer', 'appearance': { 'height': '174cm', 'age': 22 } } } example_free_content_user_data.update(attributes_data)