Skip to content

Ref error on recursive type (typebox) usage #719

@AmineKechroud

Description

@AmineKechroud

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.16.0

Plugin version

No response

Node.js version

21.1.0

Operating system

macOS

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

14.4.1

Description

When defining a type as recursive using typebox, for example:
export const TPopulatedThing = Type.Recursive(This => Type.Composite([ Tthing Type.Object({ children: Type.Array(This), }), ]));

And trying to confirm the type on response:
return resp(res).ok.pg( myVariable.data, TPopulatedThing, myVariable.meta );

I get the following error:

"type": "Error", "message": "Cannot resolve ref \"T0#\". Schema with id \"T0\" is not found.", "stack": Error: Cannot resolve ref "T0#". Schema with id "T0" is not found. at RefResolver.getSchema (/app/node_modules/.pnpm/[email protected]/node_modules/json-schema-ref-resolver/index.js:36:13) at resolveRef (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:57:38) at buildArray (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:516:21) at buildSingleTypeSerializer (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:772:24) at buildValue (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:1010:13) at buildInnerObject (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:380:11) at buildObject (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:501:9) at buildSingleTypeSerializer (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:768:24) at buildValue (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:1010:13) at buildInnerObject (/app/node_modules/.pnpm/[email protected]/node_modules/fast-json-stringify/index.js:380:11)

Any idea how to resolve this? Tried all sorts of structures but the existence of a recursive type always causes the same error.

Link to code that reproduces the bug

No response

Expected Behavior

No response

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