cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

References to references fail as "cyclic reference" #57

Closed someniatko closed 4 years ago

someniatko commented 4 years ago

Consider this simple YAML:

openapi: 3.0.2
info:
  title: 'City API'
  version: dev
paths:
  '/city':
    get:
      description: 'Get City'
      responses:
        '200':
          description: 'success'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/City'

components:
  schemas:
    City:
      $ref: '#/components/schemas/Named'
    Named:
      type: string
(new League\OpenAPIValidation\PSR7\ValidatorBuilder)
    ->fromYaml($yaml)
    ->getResponseValidator();

Response schema references "City" schema, which itself references "Named" schema, which is perfectly valid. However, the library throws the following exception:

cebe\openapi\exceptions\UnresolvableReferenceException : Cyclic reference detected, setReferenceContext() called on a Reference Object.
cebe commented 4 years ago

Fixed, thanks for reporting!