Skip to content

Commit 79dc69e

Browse files
committed
docs: add inline comments explaining casting edge cases for composite schemas
1 parent 812cc8a commit 79dc69e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

openapi_core/casting/schemas/casters.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,27 @@ def cast(self, value: Any) -> Any:
4545
if "allOf" in self.schema:
4646
for subschema in self.schema / "allOf":
4747
try:
48+
# Note: Mutates `value` iteratively. This sequentially
49+
# resolves standard overlapping types but can cause edge cases
50+
# if a string is casted to an int and passed to a string schema.
4851
value = self.schema_caster.evolve(subschema).cast(value)
4952
except (ValueError, TypeError, CastError):
5053
pass
5154

5255
if "oneOf" in self.schema:
5356
for subschema in self.schema / "oneOf":
5457
try:
58+
# Note: Greedy resolution. Will return the first successful
59+
# cast based on the order of the oneOf array.
5560
return self.schema_caster.evolve(subschema).cast(value)
5661
except (ValueError, TypeError, CastError):
5762
pass
5863

5964
if "anyOf" in self.schema:
6065
for subschema in self.schema / "anyOf":
6166
try:
67+
# Note: Greedy resolution. Will return the first successful
68+
# cast based on the order of the anyOf array.
6269
return self.schema_caster.evolve(subschema).cast(value)
6370
except (ValueError, TypeError, CastError):
6471
pass

0 commit comments

Comments
 (0)