Skip to content

Commit

Permalink
Merge pull request #136 from rafaelcaricio/fix_parameter_validation
Browse files Browse the repository at this point in the history
Fixes problem with param validation
  • Loading branch information
hjacobs committed Feb 3, 2016
2 parents 5222e44 + cc37cfa commit 678fbf7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions connexion/decorators/validation.py
Expand Up @@ -11,6 +11,7 @@
language governing permissions and limitations under the License.
"""

import copy
import flask
import functools
import itertools
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions tests/fakeapi/api.yaml
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/fakeapi/hello.py
Expand Up @@ -230,3 +230,7 @@ def test_formData_missing_param():

def test_bool_default_param(thruthiness):
return thruthiness


def test_required_param(simple):
return simple
13 changes: 13 additions & 0 deletions tests/test_app.py
Expand Up @@ -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

0 comments on commit 678fbf7

Please sign in to comment.