swagger-api / swagger-api/swagger-ui
Circular references caused by YAML anchors not handled
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Windows, Linux
- Browser: Firefox
- Version: 67.0.4
- Method of installation: swagger-ui-dist from NPM
- Swagger-UI version: 3.22.0
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.0
info:
title: Test
version: '1.0'
servers:
- url: http://localhost
paths:
/test:
get:
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
graph: &ref_1
type: object
properties:
children:
type: array
items: *ref_1
Swagger-UI configuration options:
SwaggerUI({
urls:[{url:"yamls/circular-refs.yaml",name:"circular-refs"}],
"urls.primaryName":"circular-refs",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
defaultModelsExpandDepth:-1,
validatorUrl:null
})
Describe the bug you're encountering
Our YAML files contain many references to external files. To simplify deployment we first run everything through the swagger-combine tool to inline the external references. This tool also further shortens the YAML by replacing objects with anchors.
One of our APIs has a circular reference in it that is used to represent a graph of variable size. This gets turned into the YAML anchors shown in the greatly simplified example above. With this YAML we get the Unable to render this definition error.
Swagger UI handles the YAML with external references in place by simply not showing the children object, but rather an empty array. But apparently when this circular reference is created by YAML anchors it fails to load.
To reproduce...
Steps to reproduce the behavior:
- Load to example YAML
- See error
Expected behavior
I would expect Swagger UI to gracefully handle the YAML anchor circular reference just like it does the normal ones.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the example YAML containing the ref_1 anchor and the SwaggerUI configuration shown in the issue, then load it in Swagger UI to reproduce the rendering error. Compare this with the stated behavior for external references; done means the circular anchor is handled gracefully instead of producing “Unable to render this definition.”
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, yaml
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100