Skip to content

Commit

Permalink
added test case for #54
Browse files Browse the repository at this point in the history
it is a duplicate of #57

fixes #54
  • Loading branch information
cebe committed Feb 28, 2020
1 parent 5b89a81 commit ed96467
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/spec/ReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,44 @@ public function testTransitiveReference()
$this->assertEquals('string', $openapi->paths['/city']->get->responses[200]->content['application/json']->schema->type);
}

/**
* References to references fail as "cyclic reference"
* @see https://github.com/cebe/php-openapi/issues/54
*/
public function testTransitiveReferenceToFile()
{
$schema = <<<'YAML'
openapi: 3.0.2
info:
title: 'Dog API'
version: dev
paths:
'/dog':
get:
description: 'Get Dog'
responses:
'200':
description: 'success'
content:
application/json:
schema:
$ref: '#/components/schemas/Dog'
components:
schemas:
Dog:
$ref: 'definitions.yaml#/Dog'

YAML;

$openapi = Reader::readFromYaml($schema);
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, 'file://' . __DIR__ . '/data/reference/definitions.yaml'));

$this->assertTrue(isset($openapi->components->schemas['Dog']));
$this->assertEquals('object', $openapi->components->schemas['Dog']->type);
$this->assertEquals('object', $openapi->components->schemas['Dog']->type);
$this->assertEquals('object', $openapi->paths['/dog']->get->responses[200]->content['application/json']->schema->type);
}

public function testTransitiveReferenceCyclic()
{
$schema = <<<'YAML'
Expand Down

0 comments on commit ed96467

Please sign in to comment.