Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
  • Loading branch information
mission-liao committed May 7, 2015
1 parent f03560b commit 1ba598c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyswagger/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def apply_with(self, obj, val, _):

# init array as list
if obj.minItems and len(self) < obj.minItems:
raise errs.ValidationError('Array should be more than {0}, not {1}'.format(o.minItems, len(self)))
raise errs.ValidationError('Array should be more than {0}, not {1}'.format(obj.minItems, len(self)))
if obj.maxItems and len(self) > obj.maxItems:
raise errs.ValidationError('Array should be less than {0}, not {1}'.format(o.maxItems, len(self)))
raise errs.ValidationError('Array should be less than {0}, not {1}'.format(obj.maxItems, len(self)))

self.__collection_format = getattr(obj, 'collectionFormat', 'csv')
return val
Expand Down
11 changes: 10 additions & 1 deletion pyswagger/tests/data/v2_0/schema/model/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@
"type":"boolean"
}
}
},
"array_int":{
"type":"array",
"items":{
"type":"integer",
"format":"int32"
},
"maxItems":5,
"minItems":2
}
}
}
}
13 changes: 13 additions & 0 deletions pyswagger/tests/v2_0/test_prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ def test_int(self):
self.assertRaises(errs.ValidationError, i._prim_, 200)
self.assertRaises(errs.ValidationError, i._prim_, 99)

def test_array_of_int(self):
""" test array of integer """
i = self.app.resolve('#/definitions/array_int')

# pass
i._prim_([1, 1, 1, 1, 1])
i._prim_([1, 1])

# failed
self.assertRaises(errs.ValidationError, i._prim_, [1, 1, 1, 1, 1, 1])
self.assertRaises(errs.ValidationError, i._prim_, [1])


def test_num_multiple_of(self):
""" test multipleOf """
i = self.app.resolve("#/definitions/num_multipleOf")
Expand Down

0 comments on commit 1ba598c

Please sign in to comment.