diff --git a/connexion/operation.py b/connexion/operation.py index cc39c96..ec37a28 100644 --- a/connexion/operation.py +++ b/connexion/operation.py @@ -343,7 +343,7 @@ class Operation(SecureOperation): logger.debug('... Adding security decorator (%r)', security_decorator, extra=vars(self)) function = security_decorator(function) - if UWSGIMetricsCollector.is_available(): + if UWSGIMetricsCollector.is_available(): # pragma: no cover decorator = UWSGIMetricsCollector(self.path, self.method) function = decorator(function) diff --git a/tests/api/test_errors.py b/tests/api/test_errors.py index bb6e31a..6194683 100644 --- a/tests/api/test_errors.py +++ b/tests/api/test_errors.py @@ -60,3 +60,9 @@ def test_errors(problem_app): problematic_json = app_client.get( '/v1.0/json_response_with_undefined_value_to_serialize') # type: flask.Response assert problematic_json.status_code == 500 + + custom_problem = app_client.get('/v1.0/customized_problem_response') + assert custom_problem.status_code == 402 + problem_body = json.loads(custom_problem.data.decode('utf-8')) + assert 'amount' in problem_body + assert problem_body['amount'] == 23. diff --git a/tests/fakeapi/hello.py b/tests/fakeapi/hello.py index 73a9b65..9710e26 100755 --- a/tests/fakeapi/hello.py +++ b/tests/fakeapi/hello.py @@ -332,3 +332,8 @@ def get_data_as_binary(): def get_invalid_response(): return {"simple": object()} + + +def get_custom_problem_response(): + return problem(402, "You need to pay", "Missing amount", + ext={'amount': 23.0}) diff --git a/tests/fixtures/problem/swagger.yaml b/tests/fixtures/problem/swagger.yaml index 270ce10..4e9836f 100644 --- a/tests/fixtures/problem/swagger.yaml +++ b/tests/fixtures/problem/swagger.yaml @@ -81,3 +81,13 @@ paths: responses: 200: description: Never happens + + /customized_problem_response: + get: + description: Custom problem response + operationId: fakeapi.hello.get_custom_problem_response + produces: + - application/json + responses: + 200: + description: Custom problem response