"Maximum call stack size exceeded" in SwaggerEditor's "Generate Client > html2" and "File > Download Resolved YAML" functions.
Q&A (please complete the following information)
- OS: Windows 11
- Browser: Chrome
- Version: 123.0.6312.60 (64 bits)
- Method of installation: SwaggerEditor
- Swagger-UI version: 3.0.54
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.1
info:
title: Test API
version: v1
paths:
/v{version}/projects/{projectId}/compounds:
get:
tags:
- Compounds
summary: Get all compounds.
operationId: GetCompounds
parameters:
- name: version
in: path
description: 'API version (e.g.: 1)'
required: true
schema:
type: string
- name: projectId
in: path
description: The project id
required: true
schema:
type: integer
format: int32
example: 15
responses:
'200':
description: Success
content:
text/plain:
schema:
$ref: '#/components/schemas/ArrayJobDto'
application/json:
schema:
$ref: '#/components/schemas/ArrayJobDto'
text/json:
schema:
$ref: '#/components/schemas/ArrayJobDto'
'202':
description: Accepted
content:
text/plain:
schema:
$ref: '#/components/schemas/ArrayJobDto'
application/json:
schema:
$ref: '#/components/schemas/ArrayJobDto'
text/json:
schema:
$ref: '#/components/schemas/ArrayJobDto'
components:
schemas:
ArrayJobDto:
type: object
properties:
id:
type: string
format: uuid
status:
allOf:
- $ref: '#/components/schemas/ArrayJobDto'
error:
allOf:
- $ref: '#/components/schemas/ArrayJobDto'
nullable: true
payload:
type: array
items:
$ref: '#/components/schemas/ArrayJobDto'
nullable: true
additionalProperties: false
Swagger-UI configuration options:
N/A
N/A
Describe the bug you're encountering
Generator Client for "html2" is failing to render the schemas when they have circular references. Also, SwaggerEditor fails when trying to "Download Resolved JSON/YAML". The error shown is "Maximum call stack size exceeded".
To reproduce...
Steps to reproduce the behavior: Scenario 1:
- Go to https://editor-next.swagger.io/ or https://editor.swagger.io/
- Paste the provided OpenAPI spec content in the corresponding area of the editor.
- Click on "Generate Client > html2" to trigger the download.
- Save the zip file in your computer and extract.
- Open index.html file.
- Open browser's console to observe the errors.
Scenario 2:
- Go to https://editor-next.swagger.io/ or https://editor.swagger.io/
- Paste the provided OpenAPI spec content in the corresponding area of the editor.
- Click on "File > Download Resolved YAML".
- Observe the error thrown by the web app.
Expected behavior
Scenario 1: Browser's console doesn't display any "Maximum call stack size exceeded" errors, meaning that it processes Circular References correctly and schemas are rendered properly. (Consider using a dictionary of the visited nodes).
Scenario 2: Browser throws a file to download that includes the resolved YAML file.
Screenshots
Scenario 1:
Scenario 2:
Additional context or thoughts
A similar problemas was resolved in Issue #8537, but they exclusively impacted the Editor's UI and the issue persists in (at least) this other functions. @char0n your input is greatly appreciated. The provided spec file was created specifically to replicate this issue.
Hi @jorgemk85,
Your definition contains cycles and even though https://editor-next.swagger.io/ (SwaggerEditor@5) is based on ApiDOM which can handle cycles easily, we still seeing that error.
The issue is that for resolving the definitions, we currently use dereference algorithm (reference removal). Dereferencing can create cycles (circular references) and cycles cannot be serialized into JSON or YAML. In order to resolve this issue properly we need to use bundling algorithm. We've already started some initial work on bundling in https://github.com/swagger-api/apidom/issues/692.
What we can do for now to mitigate the issue (before we have bundling) is to run the dereferencing in replace mode and use circularReplacer to make the circular reference absolute and skip resolving it.
Hello @char0n,
Thank you for your reply.
I am using this "https://generator3.swagger.io/index.html#/clients/generate" endpoint to procedurally transform my spec files into "html2" static websites. Could you please indicate how to specify the dereferencing property in the request body? I have tried the following without making any difference:
{
"lang":"html2",
"spec":"...",
"specURL":null,
"type":"CLIENT",
"codegenVersion":"V3",
"options":{
"dereference":{
"circular":"replace"
}
}
}