def __prepare_json(status, op=None, schema=None, data=None, errors=None):
"""Prepare json structure for returning."""
ret_json = {"status": status}
if errors:
if not isinstance(errors, list):
ret_json["errors"] = [errors]
else:
ret_json["errors"] = errors
if data:
ret_json["data"] = data
if op:
op_schema = _get_pkg_output_schema(op)
try:
jsonschema.validate(ret_json, op_schema)
except jsonschema.ValidationError as e:
newret_json = {"status": EXIT_OOPS,
"errors": [{"reason": str(e)}]}
return newret_json
if schema:
ret_json["schema"] = schema
return ret_json
评论列表
文章目录