Open knoxsp opened 6 years ago
the JSONObject currently returns 'None' when acessing an attribute that doesn't exist. If we change this to throw an AttributeError (correct) then we need a way to formalise what attributes are allowed on an incoming object. One solution could be:
#PARENT SCHEMA class HydraSchema(): def validate(self, k, v): pass def __init__(self, parent=None): super(Project, self).__init__() if parent is None: return for k, v in parent.items(): #validate k versus v validate(k, v) setattr(self, k, v) #HYDRA SCHEMA class HydraProject(JSONObject): _properties = { ('id', Integer(default=None)), ('name', Unicode(default=None)), ('description', Unicode(default=None)), ('status', Unicode(default='A', pattern="[AX]")), ('cr_date', Unicode(default=None)), ('created_by', Integer(default=None)), ('attributes', SpyneArray(ResourceAttr)), ('attribute_data', SpyneArray(ResourceScenario)), } SpyneProject = make_spyne_resource(HydraProject) #SPYNE SCHEMA class SpyneProject(Resource): """ - **id** Integer(default=None) - **name** Unicode(default=None) - **description** Unicode(default=None) - **status** Unicode(default='A') - **cr_date** Unicode(default=None) - **created_by** Integer(default=None) - **attributes** SpyneArray(ResourceAttr) - **attribute_data** SpyneArray(ResourceScenario) """ _type_info = [ ('id', Integer(default=None)), ('name', Unicode(default=None)), ('description', Unicode(default=None)), ('status', Unicode(default='A', pattern="[AX]")), ('cr_date', Unicode(default=None)), ('created_by', Integer(default=None)), ('attributes', SpyneArray(ResourceAttr)), ('attribute_data', SpyneArray(ResourceScenario)), ]
We discussed using marshmallow for the schema declaration. This needs a proof of concept first before accepting as an idea.
the JSONObject currently returns 'None' when acessing an attribute that doesn't exist. If we change this to throw an AttributeError (correct) then we need a way to formalise what attributes are allowed on an incoming object. One solution could be: