Skip to content

Commit

Permalink
[fix] collectionFormat is always None when not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mission-liao committed Jan 9, 2017
1 parent 6fe0b0b commit 9dc2850
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyswagger/primitives/_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
def apply_with(self, obj, val, ctx):
"""
"""
self.__collection_format = getattr(obj, 'collectionFormat', 'csv')
self.__collection_format = getattr(obj, 'collectionFormat')

if isinstance(val, six.string_types):
if self.__collection_format == 'csv':
Expand Down Expand Up @@ -57,7 +57,7 @@ def _conv(p):
for v in self:
s = ''.join([s, p if s else '', str(v)])
return s

if self.__collection_format == 'csv':
return _conv(',')
elif self.__collection_format == 'ssv':
Expand Down
6 changes: 3 additions & 3 deletions pyswagger/spec/v2_0/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Items(six.with_metaclass(FieldMeta, BaseSchema)):
"""

__swagger_fields__ = {
'collectionFormat': None,
'collectionFormat': 'csv',
}

def _prim_(self, v, prim_factory, ctx=None):
Expand Down Expand Up @@ -166,7 +166,7 @@ class Parameter(six.with_metaclass(FieldMeta, BaseSchema)):
'schema': None,

# other parameter
'collectionFormat': None,
'collectionFormat': 'csv',

# for converter only
'description': None,
Expand All @@ -189,7 +189,7 @@ class Header(six.with_metaclass(FieldMeta, BaseSchema)):
"""

__swagger_fields__ = {
'collectionFormat': None,
'collectionFormat': 'csv',
'description': None,
}

Expand Down
14 changes: 14 additions & 0 deletions pyswagger/tests/data/v2_0/schema/model/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
"host":"http://test.com",
"basePath":"/v1",
"paths":{
"/a":{
"get":{
"parameters":[
{
"name":"p1",
"in":"query",
"type":"array",
"items":{
"type":"string"
}
}
]
}
},
"/k":{
"post":{
"parameters":[
Expand Down
7 changes: 7 additions & 0 deletions pyswagger/tests/v2_0/test_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ def test_unknown(self):
p = self.app.resolve('#/paths/~1t/put')
self.assertRaises(ValueError, p, p1='tom', p2='mary', p3='qoo', p4='unknown')

def test_collection_format_default(self):
""" when not defining 'collectFormat', its default should be 'csv'
refer to issue: https://github.com/mission-liao/pyswagger/issues/101
"""
self.app.resolve('#/paths/~1a/get')(p1=['test1', 'test2']) # should not raise exception


class PrimitiveExtensionTestCase(unittest.TestCase):
""" test for extending primitives """
Expand Down

0 comments on commit 9dc2850

Please sign in to comment.