Circular references caused by YAML anchors not handled
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.
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-client"></script>
<script>
window.onload = function () {
SwaggerClient.resolve({ url: 'your.yaml' })
.then(function (client) {
window.ui = SwaggerUIBundle({
spec: client.spec,
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
layout: 'StandaloneLayout',
validatorUrl: 'none',
});
});
};
</script>