diff --git a/pyswagger/primitives.py b/pyswagger/primitives.py index 342cc51..79b1936 100644 --- a/pyswagger/primitives.py +++ b/pyswagger/primitives.py @@ -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 diff --git a/pyswagger/tests/data/v2_0/schema/model/swagger.json b/pyswagger/tests/data/v2_0/schema/model/swagger.json index 9e8ffc8..e51acd9 100644 --- a/pyswagger/tests/data/v2_0/schema/model/swagger.json +++ b/pyswagger/tests/data/v2_0/schema/model/swagger.json @@ -262,6 +262,15 @@ "type":"boolean" } } + }, + "array_int":{ + "type":"array", + "items":{ + "type":"integer", + "format":"int32" + }, + "maxItems":5, + "minItems":2 } } -} \ No newline at end of file +} diff --git a/pyswagger/tests/v2_0/test_prim.py b/pyswagger/tests/v2_0/test_prim.py index c1958c2..f729bb8 100644 --- a/pyswagger/tests/v2_0/test_prim.py +++ b/pyswagger/tests/v2_0/test_prim.py @@ -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")