swagger-parser
swagger-parser copied to clipboard
Circular dependencies are not resolved properly with resolveFully
OpenAPIV3Parser does not seem to work as one would expect when openapi components have circular dependencies of any kind.
Expected behaviour:
All $refs are resolved. If the schema references itself or has a cycle then the same Schema object should be used multiple times.
For example, TreeNode schema that has property parentNode of type TreeNode should be resolved to the ObjectSchema instance (let's say ObjectSchema@123) with property parentNode equal to the same instance (ObjectSchema@123)
Actual behaviour:
First $ref is resolved but the following references are not resolved and remain only with non-null $ref field.
From the example above we get properly resolved ObjectSchema instance with property parentNode which is in turn not resolved and remains a Schema without any properties but with $ref pointing to TreeNode.
Here is an openapi with 3 problematic cases I tested. The working example can be found here.
It this is indeed a bug, I could try to contribute a fix.
openapi: 3.0.0
info:
title: Circular Reference Example
version: 1.0.0
components:
schemas:
TreeNode:
type: object
properties:
id:
type: string
value:
$ref: '#/components/schemas/TreeNodeValue' # Circular reference through another object
parentNode:
$ref: '#/components/schemas/TreeNode' # Circular reference in object
childNodes:
type: array
items:
$ref: '#/components/schemas/TreeNode' # Circular reference in array
required:
- name
TreeNodeValue:
type: object
properties:
val:
type: string
ofNode:
$ref: '#/components/schemas/TreeNode' # Circular reference through another object
paths:
/tree/{id}:
get:
summary: Get a TreeNode
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
'200':
description: TreeNode found
content:
application/json:
schema:
$ref: '#/components/schemas/TreeNode'