From 15e9c281750ca5afaa825f3c319b22d17d994433 Mon Sep 17 00:00:00 2001 From: Artur Maciag Date: Tue, 18 Feb 2020 11:51:42 +0000 Subject: [PATCH] Flask error handler status fix --- openapi_core/contrib/flask/handlers.py | 6 ++---- tests/integration/contrib/flask/test_flask_views.py | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openapi_core/contrib/flask/handlers.py b/openapi_core/contrib/flask/handlers.py index fb2ea29..bc0cf5b 100644 --- a/openapi_core/contrib/flask/handlers.py +++ b/openapi_core/contrib/flask/handlers.py @@ -22,10 +22,8 @@ class FlaskOpenAPIErrorsHandler(object): data = { 'errors': data_errors, } - status = max( - range(len(data_errors)), - key=lambda idx: data_errors[idx]['status'], - ) + data_error_max = max(data_errors, key=lambda x: x['status']) + status = data_error_max['status'] return current_app.response_class( dumps(data), status=status, diff --git a/tests/integration/contrib/flask/test_flask_views.py b/tests/integration/contrib/flask/test_flask_views.py index 4fdd5af..8370644 100644 --- a/tests/integration/contrib/flask/test_flask_views.py +++ b/tests/integration/contrib/flask/test_flask_views.py @@ -45,6 +45,7 @@ class TestFlaskOpenAPIView(object): result = client.get('/browse/12/') + assert result.status_code == 415 assert result.json == { 'errors': [ { @@ -78,6 +79,7 @@ class TestFlaskOpenAPIView(object): } ] } + assert result.status_code == 500 assert result.json == expected_data def test_endpoint_error(self, client): @@ -97,6 +99,7 @@ class TestFlaskOpenAPIView(object): } ] } + assert result.status_code == 400 assert result.json == expected_data def test_valid(self, client):