From cc37cfa79cd1c827d1bed9c882a501f5544a3acd Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Wed, 3 Feb 2016 12:01:14 +0100 Subject: [PATCH] #131 Fixes problem with param validation --- connexion/decorators/validation.py | 2 ++ tests/fakeapi/api.yaml | 10 ++++++++++ tests/fakeapi/hello.py | 4 ++++ tests/test_app.py | 13 +++++++++++++ 4 files changed, 29 insertions(+) diff --git a/connexion/decorators/validation.py b/connexion/decorators/validation.py index b52eeb091..7083434ec 100644 --- a/connexion/decorators/validation.py +++ b/connexion/decorators/validation.py @@ -11,6 +11,7 @@ language governing permissions and limitations under the License. """ +import copy import flask import functools import itertools @@ -133,6 +134,7 @@ def validate_parameter(parameter_type, value, param): except TypeValidationError as e: return str(e) + param = copy.deepcopy(param) if 'required' in param: del param['required'] try: diff --git a/tests/fakeapi/api.yaml b/tests/fakeapi/api.yaml index 10c75696b..b0415f811 100644 --- a/tests/fakeapi/api.yaml +++ b/tests/fakeapi/api.yaml @@ -646,6 +646,16 @@ paths: in: query default: false + /test-required-param: + get: + summary: Test required param without default value + operationId: fakeapi.hello.test_required_param + parameters: + - name: simple + type: string + in: query + required: true + definitions: new_stack: type: object diff --git a/tests/fakeapi/hello.py b/tests/fakeapi/hello.py index c012edfc2..aa752571a 100755 --- a/tests/fakeapi/hello.py +++ b/tests/fakeapi/hello.py @@ -230,3 +230,7 @@ def test_formData_missing_param(): def test_bool_default_param(thruthiness): return thruthiness + + +def test_required_param(simple): + return simple diff --git a/tests/test_app.py b/tests/test_app.py index 770746eb2..66303761c 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -600,3 +600,16 @@ def test_bool_as_default_param(app): assert resp.status_code == 200 response = json.loads(resp.data.decode()) assert response == True + + +def test_required_param_miss_config(app): + app_client = app.app.test_client() + + resp = app_client.get('/v1.0/test-required-param') + assert resp.status_code == 400 + + resp = app_client.get('/v1.0/test-required-param', query_string={'simple': 'test'}) + assert resp.status_code == 200 + + resp = app_client.get('/v1.0/test-required-param') + assert resp.status_code == 400