I cannot return the nested JSON file after I validate it using Cerberus in my api. Validation works fine but I don't know how to input the JSON file to the "add_argument" function of RequestParser. I have defined the nested Json structure in a custom Validator Class. Since when all fields are Valid, it returns the Dictionary itself, its class is no longer the one I have defined which was "obs_validator". So defining my own structural class did not help me when I use add_argument. How can I resolve this issue?
def obs_validator(value):
schema= {
'input_item': {
'type':'dict',
'schema':{
'type':{'type':'string', 'required': True},
'id': {'type':'integer','required': True},
'fields': { 'type': 'list', 'required': True, 'schema':
{ 'type': 'dict', 'schema': { 'field_name': {'type': 'string', 'required': True},
'field_text': {'type': 'string', 'required': True}
}
}
}
}
},
'result_item_types': { 'type': 'list', 'required': True
},
'audit': {
'type':'dict',
'schema':{
'audit_id': {'type':'integer', 'required': True},
'audit_name': {'type':'string', 'required': True}
}
},
'requested_by': {
'type':'dict',
'schema':{
'GID': {'type':'string', 'required': True},
'roles': {'type':'string', 'required': True}
}
},
'authentication': {
'type':'dict',
'schema':{
'checksum': {'type':'string', 'required': True},
'validuntil': {'type':'string', 'required': True}
}
}
}
v =cerb.Validator(schema)
if v.validate(value):
return value
else:
raise ValueError(json.dumps(v.errors))
put_args = reqparse.RequestParser()
put_args.add_argument("What to write here??", type=obs_validator,action='append')
class text(Resource):
def put(self):
input_dict = put_args.parse_args()
return input_dict, 201