Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Maximum call stack size exceeded" in SwaggerEditor's "Generate Client > html2" and "File > Download Resolved YAML" functions. #9761

Open
jorgemk85 opened this issue Mar 27, 2024 · 2 comments

Comments

@jorgemk85
Copy link

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:

  1. Go to https://editor-next.swagger.io/ or https://editor.swagger.io/
  2. Paste the provided OpenAPI spec content in the corresponding area of the editor.
  3. Click on "Generate Client > html2" to trigger the download.
  4. Save the zip file in your computer and extract.
  5. Open index.html file.
  6. Open browser's console to observe the errors.

Scenario 2:

  1. Go to https://editor-next.swagger.io/ or https://editor.swagger.io/
  2. Paste the provided OpenAPI spec content in the corresponding area of the editor.
  3. Click on "File > Download Resolved YAML".
  4. 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:
image
image

Scenario 2:
image

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.

@jorgemk85 jorgemk85 changed the title Maximum call stack size exceeded in SwaggerEditor's "Generate Client > html2" and "File > Download Resolved YAML" functions. "Maximum call stack size exceeded" in SwaggerEditor's "Generate Client > html2" and "File > Download Resolved YAML" functions. Mar 27, 2024
@char0n
Copy link
Member

char0n commented Mar 29, 2024

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 swagger-api/apidom#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.

@jorgemk85
Copy link
Author

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"
      }
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants