diff --git a/src/spec/MediaType.php b/src/spec/MediaType.php index 1e891050..0466f7d8 100644 --- a/src/spec/MediaType.php +++ b/src/spec/MediaType.php @@ -53,7 +53,13 @@ public function __construct(array $data) if ($encodingData instanceof Encoding) { $encoding[$property] = $encodingData; } elseif (is_array($encodingData)) { - $encoding[$property] = new Encoding($encodingData, $this->schema->properties[$property] ?? null); + // Don't pass the schema if it's still an unresolved reference. + if (this->schema->properties[$property] instanceof Reference) { + $encoding[$property] = new Encoding($encodingData); + } + else { + $encoding[$property] = new Encoding($encodingData, $this->schema->properties[$property] ?? null); + } } else { $givenType = gettype($encodingData); if ($givenType === 'object') { diff --git a/tests/spec/OpenApiTest.php b/tests/spec/OpenApiTest.php index dc9dd449..de107380 100644 --- a/tests/spec/OpenApiTest.php +++ b/tests/spec/OpenApiTest.php @@ -239,4 +239,54 @@ public function testSpecs($openApiFile) } } + + public function testUnresolvedReferencesInEncoding($config, $expectedException) + { + $yaml = Yaml::parse(<<<'YAML' +openapi: "3.0.0" +info: + version: 1.0.0 + title: Encoding test +paths: + /pets: + post: + summary: Create a pet + operationId: createPets + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + pet: + $ref: '#/components/schemas/Pet' + petImage: + type: string + format: binary + encoding: + pet: + contentType: application/json + petImage: + contentType: image/* + application/json: + schema: + $ref: '#/components/schemas/Pet' + responses: + '201': + description: Null response +components: + schemas: + Pet: + type: object + properties: + name: + type: string +YAML +); + $openapi = new OpenApi($yaml); + $result = $openapi->validate(); + + $this->assertEquals([], $openapi->getErrors()); + $this->assertTrue($result); + } }