Skip to content

Circular reference in OpenAPI schema causes stack overflow error #15

@davbrito

Description

@davbrito

Problem

When using a circular reference in the OpenAPI schema, the application fails with a stack overflow error.

Details

  • Creating a schema with self-referencing models (such as a Todo class containing a collection of Todo as children) triggers a Maximum call stack size exceeded error.
  • The stack trace points to an issue in the massimo-cli's get-type.js when processing the circular reference.

Steps to Reproduce

  1. Define a model with a circular reference:
  2. Generate the OpenAPI schema and attempt to use it with massimo-cli.
  3. Observe the error (see image below).

Error Output

Image

Example Model

public class Todo
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public bool IsComplete { get; set; }
    public ICollection<Todo>? Children { get; set; }
}

Example Schema

{
  ...
  "components": {
    "schemas": {
      "Todo": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "integer",
            "format": "int32"
          },
          "name": {
            "type": "string",
            "nullable": true
          },
          "isComplete": {
            "type": "boolean"
          },
          "nestedTodos": {
            "type": "array",
            "nullable": true,
            "items": {
              "$ref": "#/components/schemas/Todo"
            }
          }
        }
      }
    }
  }
}

Expected Behavior

The tool should handle circular references gracefully without crashing or exceeding the call stack size.

Actual Behavior

  • Throws a Maximum call stack size exceeded error.
  • Fails to process the OpenAPI schema with circular references.

Environment

  • massimo-cli@0.4.0
  • Node.js v22.19.0

Additional Notes

  • This issue appears to be related to circular reference handling in the OpenAPI schema parser/processor.
  • Other libraries, such as openapi-typescript, are able to handle circular references in OpenAPI schemas successfully. Investigating their approach might provide insights for resolving this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions