Skip to content

Commit ed96467

Browse files
committed
added test case for #54
it is a duplicate of #57 fixes #54
1 parent 5b89a81 commit ed96467

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/spec/ReferenceTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,44 @@ public function testTransitiveReference()
346346
$this->assertEquals('string', $openapi->paths['/city']->get->responses[200]->content['application/json']->schema->type);
347347
}
348348

349+
/**
350+
* References to references fail as "cyclic reference"
351+
* @see https://github.com/cebe/php-openapi/issues/54
352+
*/
353+
public function testTransitiveReferenceToFile()
354+
{
355+
$schema = <<<'YAML'
356+
openapi: 3.0.2
357+
info:
358+
title: 'Dog API'
359+
version: dev
360+
paths:
361+
'/dog':
362+
get:
363+
description: 'Get Dog'
364+
responses:
365+
'200':
366+
description: 'success'
367+
content:
368+
application/json:
369+
schema:
370+
$ref: '#/components/schemas/Dog'
371+
components:
372+
schemas:
373+
Dog:
374+
$ref: 'definitions.yaml#/Dog'
375+
376+
YAML;
377+
378+
$openapi = Reader::readFromYaml($schema);
379+
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, 'file://' . __DIR__ . '/data/reference/definitions.yaml'));
380+
381+
$this->assertTrue(isset($openapi->components->schemas['Dog']));
382+
$this->assertEquals('object', $openapi->components->schemas['Dog']->type);
383+
$this->assertEquals('object', $openapi->components->schemas['Dog']->type);
384+
$this->assertEquals('object', $openapi->paths['/dog']->get->responses[200]->content['application/json']->schema->type);
385+
}
386+
349387
public function testTransitiveReferenceCyclic()
350388
{
351389
$schema = <<<'YAML'

0 commit comments

Comments
 (0)