Skip to content

Commit 4972089

Browse files
authored
Merge pull request #295 from p1c2u/fix/any-unmarshaller-validation-fix
Any unmarshaller validate fix
2 parents 4e7d8ed + abfd0c6 commit 4972089

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class AnyUnmarshaller(ComplexUnmarshaller):
248248
SchemaType.INTEGER, SchemaType.NUMBER, SchemaType.STRING,
249249
]
250250

251-
def __call__(self, value=NoValue):
251+
def unmarshal(self, value=NoValue):
252252
one_of_schema = self._get_one_of_schema(value)
253253
if one_of_schema:
254254
return self.unmarshallers_factory.create(one_of_schema)(value)

tests/unit/unmarshalling/test_unmarshal.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,52 @@ def test_schema_any_all_of(self, unmarshaller_factory):
476476
])
477477
assert unmarshaller_factory(schema)(['hello']) == ['hello']
478478

479+
@pytest.mark.parametrize('value', [
480+
{
481+
'somestr': {},
482+
'someint': 123,
483+
},
484+
{
485+
'somestr': [
486+
'content1', 'content2'
487+
],
488+
'someint': 123,
489+
},
490+
{
491+
'somestr': 123,
492+
'someint': 123,
493+
},
494+
{
495+
'somestr': 'content',
496+
'someint': 123,
497+
'not_in_scheme_prop': 123,
498+
},
499+
])
500+
def test_schema_any_all_of_invalid_properties(
501+
self, value, unmarshaller_factory):
502+
schema = Schema(
503+
all_of=[
504+
Schema(
505+
'object',
506+
required=['somestr'],
507+
properties={
508+
'somestr': Schema('string'),
509+
},
510+
),
511+
Schema(
512+
'object',
513+
required=['someint'],
514+
properties={
515+
'someint': Schema('integer'),
516+
},
517+
),
518+
],
519+
additional_properties=False,
520+
)
521+
522+
with pytest.raises(InvalidSchemaValue):
523+
unmarshaller_factory(schema)(value)
524+
479525
def test_schema_any_all_of_any(self, unmarshaller_factory):
480526
schema = Schema(all_of=[
481527
Schema(),

0 commit comments

Comments
 (0)