Skip to content

Commit aafedb5

Browse files
Unresolved reference while instantiating Encoding
If there's a `$ref` within a `multipart/form-data` `requestBody`, the `Encoding` will be instantiated with a `Reference` object instead of a `Schema` object as expected resulting in a `TypeErrorException`. Since this parameter is only ever used to guess the default encoding type of a property if and when it is not explicitly defined, I propose to skip the schema parameter altogether if during instantiation it is still an unresolved reference (otherwise we would have to pre-resolve references during instantiation leading to all other kinds of mishaps and a very substantial rewrite of the whole project).
1 parent 98fedaf commit aafedb5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/spec/MediaType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ public function __construct(array $data)
5353
if ($encodingData instanceof Encoding) {
5454
$encoding[$property] = $encodingData;
5555
} elseif (is_array($encodingData)) {
56-
$encoding[$property] = new Encoding($encodingData, $this->schema->properties[$property] ?? null);
56+
// Don't pass the schema if it's still an unresolved reference.
57+
if (this->schema->properties[$property] instanceof Reference) {
58+
$encoding[$property] = new Encoding($encodingData);
59+
}
60+
else {
61+
$encoding[$property] = new Encoding($encodingData, $this->schema->properties[$property] ?? null);
62+
}
5763
} else {
5864
$givenType = gettype($encodingData);
5965
if ($givenType === 'object') {

0 commit comments

Comments
 (0)