diff --git a/openapi_core/schema/schemas/models.py b/openapi_core/schema/schemas/models.py index d0b0504..22a79eb 100644 --- a/openapi_core/schema/schemas/models.py +++ b/openapi_core/schema/schemas/models.py @@ -243,6 +243,7 @@ class Schema(object): def get_validator_mapping(self): mapping = { + SchemaType.ARRAY: self._validate_collection, SchemaType.OBJECT: self._validate_object, } @@ -270,6 +271,12 @@ class Schema(object): return value + def _validate_collection(self, value): + if self.items is None: + raise OpenAPISchemaError("Schema for collection not defined") + + return list(map(self.items.validate, value)) + def _validate_object(self, value): properties = value.__dict__ diff --git a/tests/unit/schema/test_schemas.py b/tests/unit/schema/test_schemas.py index 3f96547..dde4d06 100644 --- a/tests/unit/schema/test_schemas.py +++ b/tests/unit/schema/test_schemas.py @@ -5,7 +5,7 @@ import pytest from openapi_core.extensions.models.models import Model from openapi_core.schema.schemas.exceptions import ( - InvalidSchemaValue, MultipleOneOfSchema, NoOneOfSchema, + InvalidSchemaValue, MultipleOneOfSchema, NoOneOfSchema, OpenAPISchemaError, ) from openapi_core.schema.schemas.models import Schema @@ -199,9 +199,16 @@ class TestSchemaValidate(object): schema.validate(value) @pytest.mark.parametrize('value', [[1, 2], (3, 4)]) - def test_array(self, value): + def test_array_no_schema(self, value): schema = Schema('array') + with pytest.raises(OpenAPISchemaError): + schema.validate(value) + + @pytest.mark.parametrize('value', [[1, 2], (3, 4)]) + def test_array(self, value): + schema = Schema('array', items=Schema('integer')) + result = schema.validate(value) assert result == value