fast-json-stringify icon indicating copy to clipboard operation
fast-json-stringify copied to clipboard

Ref error on recursive type (typebox) usage

Open AmineKechroud opened this issue 1 year ago • 1 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] 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

AmineKechroud avatar May 23 '24 12:05 AmineKechroud

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

mcollina avatar May 23 '24 20:05 mcollina