Source code for transmute_core.response_shape

import copy
from swagger_schema import Schema


[docs]class ResponseShape(object): """ result shapes define the return format of the response. """
[docs] @staticmethod def create_body(result_dict): """ given the result dict from transmute_func, return back the response object. """ raise NotImplementedError()
[docs] @staticmethod def swagger(result_schema): """ given the schema of the inner result object, return back the swagger schema representation. """ raise NotImplementedError()
[docs]class ResponseShapeSimple(ResponseShape): """ return back just the result object. """
[docs] @staticmethod def create_body(result_dict): return result_dict["result"]
[docs] @staticmethod def swagger(result_schema): return result_schema
[docs]class ResponseShapeComplex(ResponseShape): """ return back an object with the result nested, providing a little more context on the result: * status code * success * result """
[docs] @staticmethod def create_body(result_dict): return result_dict
[docs] @staticmethod def swagger(result_schema): return Schema( { "title": "SuccessObject", "type": "object", "properties": { "result": result_schema, "success": {"type": "boolean"}, "code": {"type": "number"}, }, "required": ["success", "result", "code"], } )