Skip to content

Commit ab78913

Browse files
authored
Merge pull request #286 from p1c2u/fix/any-unmarshaller-use-all-of
AnyUnmarshaller use allOf schemas
2 parents 667795d + c40bd4d commit ab78913

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ def __call__(self, value=NoValue):
253253
if one_of_schema:
254254
return self.unmarshallers_factory.create(one_of_schema)(value)
255255

256+
all_of_schema = self._get_all_of_schema(value)
257+
if all_of_schema:
258+
return self.unmarshallers_factory.create(all_of_schema)(value)
259+
256260
for schema_type in self.SCHEMA_TYPES_ORDER:
257261
unmarshaller = self.unmarshallers_factory.create(
258262
self.schema, type_override=schema_type)
@@ -278,3 +282,17 @@ def _get_one_of_schema(self, value):
278282
continue
279283
else:
280284
return subschema
285+
286+
def _get_all_of_schema(self, value):
287+
if not self.schema.all_of:
288+
return
289+
for subschema in self.schema.all_of:
290+
if subschema.type == SchemaType.ANY:
291+
continue
292+
unmarshaller = self.unmarshallers_factory.create(subschema)
293+
try:
294+
unmarshaller.validate(value)
295+
except ValidateError:
296+
continue
297+
else:
298+
return subschema

tests/integration/data/v3.0/petstore.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ components:
329329
message:
330330
type: string
331331
ExtendedError:
332+
type: object
332333
x-model: ExtendedError
333334
allOf:
334335
- $ref: "#/components/schemas/Error"

tests/unit/unmarshalling/test_unmarshal.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,23 @@ def test_schema_any_one_of(self, unmarshaller_factory):
466466
])
467467
assert unmarshaller_factory(schema)(['hello']) == ['hello']
468468

469+
def test_schema_any_all_of(self, unmarshaller_factory):
470+
schema = Schema(all_of=[
471+
Schema('array', items=Schema('string')),
472+
])
473+
assert unmarshaller_factory(schema)(['hello']) == ['hello']
474+
475+
def test_schema_any_all_of_any(self, unmarshaller_factory):
476+
schema = Schema(all_of=[
477+
Schema(),
478+
Schema('string', schema_format='date'),
479+
])
480+
value = '2018-01-02'
481+
482+
result = unmarshaller_factory(schema)(value)
483+
484+
assert result == datetime.date(2018, 1, 2)
485+
469486
def test_schema_any(self, unmarshaller_factory):
470487
schema = Schema()
471488
assert unmarshaller_factory(schema)('string') == 'string'

0 commit comments

Comments
 (0)