1
0
Fork 0
mirror of https://github.com/correl/openapi-core.git synced 2025-03-20 01:09:23 -09:00

Merge pull request from p1c2u/fix/any-unmarshaller-use-all-of

AnyUnmarshaller use allOf schemas
This commit is contained in:
A 2021-02-09 22:07:43 +00:00 committed by GitHub
commit ab78913945
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 0 deletions
openapi_core/unmarshalling/schemas
tests
integration/data/v3.0
unit/unmarshalling

View file

@ -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

View file

@ -329,6 +329,7 @@ components:
message:
type: string
ExtendedError:
type: object
x-model: ExtendedError
allOf:
- $ref: "#/components/schemas/Error"

View file

@ -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'