mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
Merge pull request #85 from p1c2u/feature/collection-validation
Collection validation
This commit is contained in:
commit
101a11ebe9
2 changed files with 16 additions and 2 deletions
|
@ -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__
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue