From aeec95a5d8b79bc60e3d4864b9e7dc1119e67003 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Mar 2020 17:06:29 +0530 Subject: [PATCH 1/3] improved error 415 --- connexion/decorators/validation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connexion/decorators/validation.py b/connexion/decorators/validation.py index b7c7a622b..4942d3736 100644 --- a/connexion/decorators/validation.py +++ b/connexion/decorators/validation.py @@ -149,7 +149,7 @@ def wrapper(request): else: # the body has contents that were not parsed as JSON raise UnsupportedMediaTypeProblem( - "Invalid Content-type ({content_type}), expected JSON data".format( + detail="Invalid Content-type ({content_type}), expected JSON data".format( content_type=request.headers.get("Content-Type", "") )) From de75c5c5b15b95fa0410b0ce7269668f5dda8391 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Apr 2020 05:32:56 +0530 Subject: [PATCH 2/3] test added --- tests/api/test_errors.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/api/test_errors.py b/tests/api/test_errors.py index a8963bb08..577241b6c 100644 --- a/tests/api/test_errors.py +++ b/tests/api/test_errors.py @@ -78,3 +78,12 @@ def test_errors(problem_app): problem_as_exception_body = json.loads(problem_as_exception.data.decode('utf-8', 'replace')) assert 'age' in problem_as_exception_body assert problem_as_exception_body['age'] == 30 + + unsupported_media_type = app_client.get('/v1.0/media_type_not_supported') + assert unsupported_media_type.status_code == 415 + unsupported_media_type_body = json.loads(unsupported_media_type.data.decode('utf-8', 'replace')) + assert unsupported_media_type_body['type'] == 'about:blank' + assert unsupported_media_type_body['title'] == 'Unsupported media type' + assert unsupported_media_type_body['detail'] == 'Invalid Content-type (text/html), expected JSON data' + assert unsupported_media_type_body['status'] == 415 + assert unsupported_media_type_body['instance'] == 'instance1' From ed464b081eb651cf27b2d7af9e41d16d60376de9 Mon Sep 17 00:00:00 2001 From: Ruwan Date: Tue, 20 Jul 2021 17:38:38 +0200 Subject: [PATCH 3/3] Fix tests for updated 415 error response --- tests/api/test_errors.py | 5 ++--- tests/fixtures/problem/openapi.yaml | 12 ++++++++++++ tests/fixtures/problem/swagger.yaml | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tests/api/test_errors.py b/tests/api/test_errors.py index 577241b6c..1ad2a8f82 100644 --- a/tests/api/test_errors.py +++ b/tests/api/test_errors.py @@ -79,11 +79,10 @@ def test_errors(problem_app): assert 'age' in problem_as_exception_body assert problem_as_exception_body['age'] == 30 - unsupported_media_type = app_client.get('/v1.0/media_type_not_supported') + unsupported_media_type = app_client.post('/v1.0/post_wrong_content_type', data='', content_type='text/html') assert unsupported_media_type.status_code == 415 unsupported_media_type_body = json.loads(unsupported_media_type.data.decode('utf-8', 'replace')) assert unsupported_media_type_body['type'] == 'about:blank' - assert unsupported_media_type_body['title'] == 'Unsupported media type' + assert unsupported_media_type_body['title'] == 'Unsupported Media Type' assert unsupported_media_type_body['detail'] == 'Invalid Content-type (text/html), expected JSON data' assert unsupported_media_type_body['status'] == 415 - assert unsupported_media_type_body['instance'] == 'instance1' diff --git a/tests/fixtures/problem/openapi.yaml b/tests/fixtures/problem/openapi.yaml index 4e6e1fb4f..3bc02cd0f 100644 --- a/tests/fixtures/problem/openapi.yaml +++ b/tests/fixtures/problem/openapi.yaml @@ -79,6 +79,18 @@ paths: responses: '200': description: Problem exception + /post_wrong_content_type: + post: + description: Unsupported media type + operationId: fakeapi.hello.post_wrong_content_type + requestBody: + content: + application/json: + schema: + type: object + responses: + 200: + description: OK servers: - url: /v1.0 components: diff --git a/tests/fixtures/problem/swagger.yaml b/tests/fixtures/problem/swagger.yaml index 121ad943d..c4e0f2b4a 100644 --- a/tests/fixtures/problem/swagger.yaml +++ b/tests/fixtures/problem/swagger.yaml @@ -101,3 +101,19 @@ paths: responses: 200: description: Problem exception + + /post_wrong_content_type: + post: + description: Unsupported media type + operationId: fakeapi.hello.post_wrong_content_type + consumes: + - application/json + parameters: + - in: body + name: body + description: The request body + schema: + type: object + responses: + 200: + description: OK