mirror of
https://github.com/correl/openapi-core.git
synced 2025-03-20 01:09:23 -09:00
Merge pull request #286 from p1c2u/fix/any-unmarshaller-use-all-of
AnyUnmarshaller use allOf schemas
This commit is contained in:
commit
ab78913945
3 changed files with 36 additions and 0 deletions
openapi_core/unmarshalling/schemas
tests
|
@ -253,6 +253,10 @@ class AnyUnmarshaller(ComplexUnmarshaller):
|
|||
if one_of_schema:
|
||||
return self.unmarshallers_factory.create(one_of_schema)(value)
|
||||
|
||||
all_of_schema = self._get_all_of_schema(value)
|
||||
if all_of_schema:
|
||||
return self.unmarshallers_factory.create(all_of_schema)(value)
|
||||
|
||||
for schema_type in self.SCHEMA_TYPES_ORDER:
|
||||
unmarshaller = self.unmarshallers_factory.create(
|
||||
self.schema, type_override=schema_type)
|
||||
|
@ -278,3 +282,17 @@ class AnyUnmarshaller(ComplexUnmarshaller):
|
|||
continue
|
||||
else:
|
||||
return subschema
|
||||
|
||||
def _get_all_of_schema(self, value):
|
||||
if not self.schema.all_of:
|
||||
return
|
||||
for subschema in self.schema.all_of:
|
||||
if subschema.type == SchemaType.ANY:
|
||||
continue
|
||||
unmarshaller = self.unmarshallers_factory.create(subschema)
|
||||
try:
|
||||
unmarshaller.validate(value)
|
||||
except ValidateError:
|
||||
continue
|
||||
else:
|
||||
return subschema
|
||||
|
|
|
@ -329,6 +329,7 @@ components:
|
|||
message:
|
||||
type: string
|
||||
ExtendedError:
|
||||
type: object
|
||||
x-model: ExtendedError
|
||||
allOf:
|
||||
- $ref: "#/components/schemas/Error"
|
||||
|
|
|
@ -466,6 +466,23 @@ class TestSchemaUnmarshallerCall(object):
|
|||
])
|
||||
assert unmarshaller_factory(schema)(['hello']) == ['hello']
|
||||
|
||||
def test_schema_any_all_of(self, unmarshaller_factory):
|
||||
schema = Schema(all_of=[
|
||||
Schema('array', items=Schema('string')),
|
||||
])
|
||||
assert unmarshaller_factory(schema)(['hello']) == ['hello']
|
||||
|
||||
def test_schema_any_all_of_any(self, unmarshaller_factory):
|
||||
schema = Schema(all_of=[
|
||||
Schema(),
|
||||
Schema('string', schema_format='date'),
|
||||
])
|
||||
value = '2018-01-02'
|
||||
|
||||
result = unmarshaller_factory(schema)(value)
|
||||
|
||||
assert result == datetime.date(2018, 1, 2)
|
||||
|
||||
def test_schema_any(self, unmarshaller_factory):
|
||||
schema = Schema()
|
||||
assert unmarshaller_factory(schema)('string') == 'string'
|
||||
|
|
Loading…
Add table
Reference in a new issue