File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff 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 ' ) {
Original file line number Diff line number Diff line change @@ -239,4 +239,54 @@ public function testSpecs($openApiFile)
239239 }
240240
241241 }
242+
243+ public function testUnresolvedReferencesInEncoding ($ config , $ expectedException )
244+ {
245+ $ yaml = Yaml::parse (<<<'YAML'
246+ openapi: "3.0.0"
247+ info:
248+ version: 1.0.0
249+ title: Encoding test
250+ paths:
251+ /pets:
252+ post:
253+ summary: Create a pet
254+ operationId: createPets
255+ requestBody:
256+ content:
257+ multipart/form-data:
258+ schema:
259+ type: object
260+ properties:
261+ pet:
262+ $ref: '#/components/schemas/Pet'
263+ petImage:
264+ type: string
265+ format: binary
266+ encoding:
267+ pet:
268+ contentType: application/json
269+ petImage:
270+ contentType: image/*
271+ application/json:
272+ schema:
273+ $ref: '#/components/schemas/Pet'
274+ responses:
275+ '201':
276+ description: Null response
277+ components:
278+ schemas:
279+ Pet:
280+ type: object
281+ properties:
282+ name:
283+ type: string
284+ YAML
285+ );
286+ $ openapi = new OpenApi ($ yaml );
287+ $ result = $ openapi ->validate ();
288+
289+ $ this ->assertEquals ([], $ openapi ->getErrors ());
290+ $ this ->assertTrue ($ result );
291+ }
242292}
You can’t perform that action at this time.
0 commit comments