Skip to content

Commit

Permalink
Merge pull request spec-first#140 from scolby33/booleans_in_queries
Browse files Browse the repository at this point in the history
Use the JSON/Swagger aware boolean constructor for constructing boole…
  • Loading branch information
jmcs committed Feb 8, 2016
2 parents d90a1ef + 10f13ad commit 6525b6b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion connexion/decorators/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import logging
import six

from ..utils import boolean

logger = logging.getLogger(__name__)

# https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#data-types
TYPE_MAP = {'integer': int,
'number': float,
'string': str,
'boolean': bool,
'boolean': boolean,
'array': list,
'object': dict} # map of swagger types to python types

Expand Down
13 changes: 12 additions & 1 deletion tests/fakeapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,17 @@ paths:
in: query
default: false

/test-bool-array-param:
get:
summary: Test usage of an array of booleans value
operationId: fakeapi.hello.test_bool_array_param
parameters:
- name: thruthiness
in: query
type: array
items:
type: boolean

/test-required-param:
get:
summary: Test required param without default value
Expand Down Expand Up @@ -724,7 +735,7 @@ definitions:
properties:
children:
type: array
items:
items:
$ref: "#/definitions/simple_tree"
description: Docker image version to deploy
additionalProperties: false
4 changes: 4 additions & 0 deletions tests/fakeapi/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ def test_bool_default_param(thruthiness):
return thruthiness


def test_bool_array_param(thruthiness):
return all(thruthiness)


def test_required_param(simple):
return simple

Expand Down
30 changes: 28 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def test_schema_map(app):
}
}

invalid_object = {
invalid_object = {
"foo": 42
}

Expand Down Expand Up @@ -447,7 +447,7 @@ def test_schema_recursive(app):
]
}

invalid_object = {
invalid_object = {
"children": [42]
}

Expand Down Expand Up @@ -674,6 +674,32 @@ def test_bool_as_default_param(app):
assert response == True


def test_bool_param(app):
app_client = app.app.test_client()
resp = app_client.get('/v1.0/test-bool-param', query_string={'thruthiness': True})
assert resp.status_code == 200
response = json.loads(resp.data.decode())
assert response == True

resp = app_client.get('/v1.0/test-bool-param', query_string={'thruthiness': False})
assert resp.status_code == 200
response = json.loads(resp.data.decode())
assert response == False


def test_bool_array_param(app):
app_client = app.app.test_client()
resp = app_client.get('/v1.0/test-bool-array-param?thruthiness=true,true,true')
assert resp.status_code == 200
response = json.loads(resp.data.decode())
assert response == True

app_client = app.app.test_client()
resp = app_client.get('/v1.0/test-bool-array-param?thruthiness=true,true,false')
assert resp.status_code == 200
response = json.loads(resp.data.decode())
assert response == False

def test_required_param_miss_config(app):
app_client = app.app.test_client()

Expand Down

0 comments on commit 6525b6b

Please sign in to comment.