def render(self, api_context: ApiInvocationContext): LOG.info("Method request body before transformations: %s", to_str(api_context.data_as_string())) request_templates = api_context.integration.get("requestTemplates", {}) template = request_templates.get(APPLICATION_JSON, {}) if not template: return api_context.data_as_string() variables = self.build_variables_mapping(api_context) result = self.render_vtl(template, variables=variables) LOG.info(f"Endpoint request body after transformations:\n{result}") return result
def build_variables_mapping(api_context: ApiInvocationContext): # TODO: make this (dict) an object so usages of "render_vtl" variables are defined return { "context": api_context.context or {}, "stage_variables": api_context.stage_variables or {}, "input": { "body": api_context.data_as_string(), "params": { "path": api_context.path_params, "querystring": api_context.query_params(), "header": api_context.headers, }, }, }