Skip to content

Getting Maximum call stack size exceeded when having more than one recursive union (anyOf) in the schema #762

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

Closed
2 tasks done
grreeenn opened this issue Feb 13, 2025 · 0 comments

Comments

@grreeenn
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.2.1

Plugin version

No response

Node.js version

18.20.3, 20.16.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

macOS

Description

When having more than 1 recursive anyOf in the schema, the server fails to start, throwing FastifyError [Error]: Failed building the serialization schema for GET: /, due to error Maximum call stack size exceeded.

The example code throwing the error:

app.get('/', {
  schema: {
    response: {
      200: {
        "$id": "T0",
        "type": "object",
        "properties": {
          "items": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "$ref": "T0"
              }
            ]
          },
          "additionalProperties": {
            "anyOf": [
              {
                "type": "boolean"
              },
              {
                "$ref": "T0"
              }
            ]
          }
        }
      }
    }
  }
}, async (request, reply) => {
  return {};
})

here's a stackblitz illustrating the issue.

This is a reduction from an attempt to write a validation schema for JSON Schema specification itself.

Link to code that reproduces the bug

https://github.com/grreeenn/fast-json-stringify-max-call-stack-exceeded-bug

Expected Behavior

App starting without an error

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

1 participant