diff --git a/openapi_core/schema/schemas/models.py b/openapi_core/schema/schemas/models.py index 7353dd0..213182d 100644 --- a/openapi_core/schema/schemas/models.py +++ b/openapi_core/schema/schemas/models.py @@ -54,7 +54,7 @@ class Schema(object): SchemaType.ANY: lambda x: True, SchemaType.BOOLEAN: TypeValidator(bool), SchemaType.INTEGER: TypeValidator(integer_types, exclude=bool), - SchemaType.NUMBER: TypeValidator(integer_types, float, exclude=bool), + SchemaType.NUMBER: TypeValidator(integer_types + (float, ), exclude=bool), SchemaType.STRING: TypeValidator( text_type, date, datetime, binary_type, UUID), SchemaType.ARRAY: TypeValidator(list, tuple), @@ -228,16 +228,16 @@ class Schema(object): "Failed to format value {value} to format {type}: {exception}", value, self.format, exc) def _unmarshal_integer(self, value, custom_formatters=None, strict=True): - if strict and not isinstance(value, (integer_types, )): + if strict and not isinstance(value, integer_types): raise InvalidSchemaValue("Value {value} is not of type {type}", value, self.type) return int(value) def _unmarshal_number(self, value, custom_formatters=None, strict=True): - if strict and not isinstance(value, (float, )): + if strict and not isinstance(value, (float, ) + integer_types): raise InvalidSchemaValue("Value {value} is not of type {type}", value, self.type) - return float(value) + return value def _unmarshal_boolean(self, value, custom_formatters=None, strict=True): if strict and not isinstance(value, (bool, )): diff --git a/tests/unit/schema/test_schemas.py b/tests/unit/schema/test_schemas.py index b66dad7..8666fde 100644 --- a/tests/unit/schema/test_schemas.py +++ b/tests/unit/schema/test_schemas.py @@ -262,12 +262,12 @@ class TestSchemaUnmarshal(object): with pytest.raises(InvalidSchemaValue): schema.unmarshal(value) - def test_number_int_invalid(self): + def test_number_int(self): schema = Schema('number') value = 1 + result = schema.unmarshal(value) - with pytest.raises(InvalidSchemaValue): - schema.unmarshal(value) + assert result == value class TestSchemaValidate(object):