Skip to content

[BUG] Infinite recursion causes stack overflow for circular tuple schemas in AsyncAPIInputProcessor #2436

@Varadraj75

Description

@Varadraj75

Describe the bug.

A valid AsyncAPI document containing a circular schema inside an array tuple causes Modelina to crash at runtime with:

RangeError: Maximum call stack size exceeded

The crash occurs in AsyncAPIInputProcessor.convertToInternalSchema because the recursion guard (alreadyIteratedSchemas) is not propagated when iterating over schema.items() using Array.map().

As a result, circular schemas inside tuple-based arrays are processed with a fresh recursion state on every iteration, leading to infinite recursion.

This affects both CLI and programmatic usage and can be triggered by valid real-world schemas.

Expected behavior

Modelina should safely process circular schemas (including tuple-based arrays) without crashing, using the existing recursion guard to prevent infinite recursion.

Screenshots

Not applicable — this is a runtime crash.

How to Reproduce

  1. Create the following AsyncAPI document:
asyncapi: 2.6.0
info:
  title: Circular Array Crash Repro
  version: 1.0.0

channels:
  test/channel:
    publish:
      message:
        payload:
          type: array
          items:
            - $ref: '#/components/schemas/Node'
            - $ref: '#/components/schemas/Node'

components:
  schemas:
    Node:
      type: object
      properties:
        children:
          type: array
          items:
            - $ref: '#/components/schemas/Node'
  1. Run Modelina programmatically:
const { TypeScriptGenerator } = require('@asyncapi/modelina');


await new TypeScriptGenerator().generate(doc);
  1. Observe the runtime crash:
RangeError: Maximum call stack size exceeded

🖥️ Device Information [optional]

  • Operating System (OS): macOS
  • Browser: (N/A)
  • Browser Version: (N/A)

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions