|
@@ -27,51 +27,3 @@ class ContextInterface(object):
|
27
|
27
|
http_code: HTTPStatus=HTTPStatus.BAD_REQUEST,
|
28
|
28
|
) -> typing.Any:
|
29
|
29
|
raise NotImplementedError()
|
30
|
|
-
|
31
|
|
-
|
32
|
|
-# TODO: In extension, see #3
|
33
|
|
-class BottleContext(ContextInterface):
|
34
|
|
- def get_request_parameters(self, *args, **kwargs) -> RequestParameters:
|
35
|
|
- return RequestParameters(
|
36
|
|
- path_parameters=bottle.request.url_args,
|
37
|
|
- query_parameters=bottle.request.params,
|
38
|
|
- body_parameters=bottle.request.json,
|
39
|
|
- form_parameters=bottle.request.forms,
|
40
|
|
- header_parameters=bottle.request.headers,
|
41
|
|
- )
|
42
|
|
-
|
43
|
|
- def get_response(
|
44
|
|
- self,
|
45
|
|
- response: dict,
|
46
|
|
- http_code: int,
|
47
|
|
- ) -> bottle.HTTPResponse:
|
48
|
|
- return bottle.HTTPResponse(
|
49
|
|
- body=json.dumps(response),
|
50
|
|
- headers=[
|
51
|
|
- ('Content-Type', 'application/json'),
|
52
|
|
- ],
|
53
|
|
- status=http_code,
|
54
|
|
- )
|
55
|
|
-
|
56
|
|
- def get_validation_error_response(
|
57
|
|
- self,
|
58
|
|
- error: ProcessValidationError,
|
59
|
|
- http_code: HTTPStatus=HTTPStatus.BAD_REQUEST,
|
60
|
|
- ) -> typing.Any:
|
61
|
|
- # TODO BS 20171010: Manage error schemas, see #4
|
62
|
|
- from hapic.hapic import _default_global_error_schema
|
63
|
|
- unmarshall = _default_global_error_schema.dump(error)
|
64
|
|
- if unmarshall.errors:
|
65
|
|
- raise OutputValidationException(
|
66
|
|
- 'Validation error during dump of error response: {}'.format(
|
67
|
|
- str(unmarshall.errors)
|
68
|
|
- )
|
69
|
|
- )
|
70
|
|
-
|
71
|
|
- return bottle.HTTPResponse(
|
72
|
|
- body=json.dumps(unmarshall.data),
|
73
|
|
- headers=[
|
74
|
|
- ('Content-Type', 'application/json'),
|
75
|
|
- ],
|
76
|
|
- status=int(http_code),
|
77
|
|
- )
|