mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 19:19:23 +00:00
Merge pull request #295 from p1c2u/fix/any-unmarshaller-validation-fix
Any unmarshaller validate fix
This commit is contained in:
commit
49720894c8
2 changed files with 47 additions and 1 deletions
|
@ -248,7 +248,7 @@ class AnyUnmarshaller(ComplexUnmarshaller):
|
|||
SchemaType.INTEGER, SchemaType.NUMBER, SchemaType.STRING,
|
||||
]
|
||||
|
||||
def __call__(self, value=NoValue):
|
||||
def unmarshal(self, value=NoValue):
|
||||
one_of_schema = self._get_one_of_schema(value)
|
||||
if one_of_schema:
|
||||
return self.unmarshallers_factory.create(one_of_schema)(value)
|
||||
|
|
|
@ -476,6 +476,52 @@ class TestSchemaUnmarshallerCall(object):
|
|||
])
|
||||
assert unmarshaller_factory(schema)(['hello']) == ['hello']
|
||||
|
||||
@pytest.mark.parametrize('value', [
|
||||
{
|
||||
'somestr': {},
|
||||
'someint': 123,
|
||||
},
|
||||
{
|
||||
'somestr': [
|
||||
'content1', 'content2'
|
||||
],
|
||||
'someint': 123,
|
||||
},
|
||||
{
|
||||
'somestr': 123,
|
||||
'someint': 123,
|
||||
},
|
||||
{
|
||||
'somestr': 'content',
|
||||
'someint': 123,
|
||||
'not_in_scheme_prop': 123,
|
||||
},
|
||||
])
|
||||
def test_schema_any_all_of_invalid_properties(
|
||||
self, value, unmarshaller_factory):
|
||||
schema = Schema(
|
||||
all_of=[
|
||||
Schema(
|
||||
'object',
|
||||
required=['somestr'],
|
||||
properties={
|
||||
'somestr': Schema('string'),
|
||||
},
|
||||
),
|
||||
Schema(
|
||||
'object',
|
||||
required=['someint'],
|
||||
properties={
|
||||
'someint': Schema('integer'),
|
||||
},
|
||||
),
|
||||
],
|
||||
additional_properties=False,
|
||||
)
|
||||
|
||||
with pytest.raises(InvalidSchemaValue):
|
||||
unmarshaller_factory(schema)(value)
|
||||
|
||||
def test_schema_any_all_of_any(self, unmarshaller_factory):
|
||||
schema = Schema(all_of=[
|
||||
Schema(),
|
||||
|
|
Loading…
Reference in a new issue