I am trying to model a json object for a openstack project and having trouble representing multiple sub types within a custom type.
>>>>>>>>>>>>>>>>>>>>> Here's the json object structure i am trying to model. Notice that properties is a dictionary of multiple sub types(prop1, prop2, prop3)
{
"name": "openstack",
"description": "openstack project",
"properties": {
"prop1": {
"type": "type1",
"description": "description of property1",
"address": "some address"
},
"prop2": {
"type": "type2",
"description": "description of property2",
"enabled": "False",
"created_date": "2014-04019"
},
"prop3": {
"type": "type3",
"description": "description of property 3",
"items": [
"item1",
"item2"
]
}
}
}
>>>>>>>>>>>>>>>>>>>>>> Here's the class representation.
properties = wsme.wsattr([Properties]) is not right. How do I represent a dictionary of multiple sub types ? Let me know if there is a completely different way to represent the above model.
class CustomType(types.Base):
name = wsme.wsattr(types.text, mandatory=True)
description = wsme.wsattr(types.text, mandatory=False)
properties = wsme.wsattr([Properties], mandatory=False)
class Properties(types.Base):
type = wsme.wsattr(types.text, mandatory=True)
class Type1(Properties):
description = wsme.wsattr(types.text, mandatory=False)
address = wsme.wsattr(types.text, mandatory=True)
class Type2(Properties):
description = wsme.wsattr(types.text, mandatory=False)
enabled = bool
class Type3(Properties):
description = wsme.wsattr(types.text, mandatory=False)
items = wsme.wsattr([Item], mandatory=False)
...
...
...
class MyController(RestController):
@wsexpose(CustomType, six.text_type)
def get_one(self, name):
@wsexpose(CustomType, body=CustomType)
def post(self, custom_type):
Thanks
lakshmi.