diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 015edff8..ef0fdb70 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -253,6 +253,10 @@ def __call__(self, value=NoValue): 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 @@ def _get_one_of_schema(self, value): 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 diff --git a/tests/integration/data/v3.0/petstore.yaml b/tests/integration/data/v3.0/petstore.yaml index a056d3ff..1785a5b7 100644 --- a/tests/integration/data/v3.0/petstore.yaml +++ b/tests/integration/data/v3.0/petstore.yaml @@ -329,6 +329,7 @@ components: message: type: string ExtendedError: + type: object x-model: ExtendedError allOf: - $ref: "#/components/schemas/Error" diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index b97b7f81..72033fd9 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -466,6 +466,23 @@ def test_schema_any_one_of(self, unmarshaller_factory): ]) 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'