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

Multiple fields with anyOf and self ref causes Maximum call stack size exceeded #724

Open
2 tasks done
JJCella opened this issue Jun 20, 2024 · 1 comment · May be fixed by #729
Open
2 tasks done

Multiple fields with anyOf and self ref causes Maximum call stack size exceeded #724

JJCella opened this issue Jun 20, 2024 · 1 comment · May be fixed by #729
Labels
bug Confirmed bug

Comments

@JJCella
Copy link

JJCella commented Jun 20, 2024

Prerequisites

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

Fastify version

4.28.0 (latest)

Plugin version

5.16.1 (latest)

Node.js version

20.11.0 (LTS)

Operating system

macOS Sonoma 14.5

Description

When defining a schema with at least two anyOf fields or oneOf fields with self ref like so :

import fastJson from 'fast-json-stringify';

const schema = {
  $schema: 'http://json-schema.org/draft-07/schema#',
  type: 'object',
  properties: {
    field: { type: 'string' },
    field1: { anyOf: [{ $ref: '#' }, { type: 'null' }] },
    field2: { anyOf: [{ $ref: '#' }, { type: 'null' }] },
  },
};

fastJson(schema.valueOf());

I'm getting this following error :

    RangeError: Maximum call stack size exceeded

      at RefResolver.#addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:143:14)
      at RefResolver.#addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:165:24)
      at RefResolver.#addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:165:24)
      at RefResolver.#addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:165:24)
      at RefResolver.#addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:165:24)
      at RefResolver.addSchema (../../node_modules/.pnpm/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:30:20)
      at mergeLocations (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:433:23)
      at buildOneOf (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:868:24)
      at buildValue (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:979:12)
      at buildInnerObject (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:380:11)
      at buildObject (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:501:9)
      at buildSingleTypeSerializer (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:768:24)
      at buildValue (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:1010:13)
      at buildOneOf (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:874:26)
      at buildValue (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify/index.js:979:12)
      at buildInnerObject (../../node_modules/.pnpm/fast-json-stringify@5.16.1/node_modules/fast-json-stringify

(output truncated for readability)

Fastify fails to start when using this schema in routes

Is this kind of schema possible ? in my case, anyOf / oneOf + self reference & null are required.

@mcollina mcollina added the bug Confirmed bug label Jun 21, 2024
@mcollina
Copy link
Member

Currently this schema is not supported. However it would be cool if it was.
I'm not sure how hard it would be, but if you are willing to give it a shot it would be amazing.

@DamienVicet DamienVicet linked a pull request Jun 26, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants