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

Ref error on recursive type (typebox) usage #719

Open
2 tasks done
AmineKechroud opened this issue May 23, 2024 · 1 comment
Open
2 tasks done

Ref error on recursive type (typebox) usage #719

AmineKechroud opened this issue May 23, 2024 · 1 comment

Comments

@AmineKechroud
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.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/json-schema-ref-resolver@1.0.1/node_modules/json-schema-ref-resolver/index.js:36:13) at resolveRef (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:57:38) at buildArray (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:516:21) at buildSingleTypeSerializer (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:772:24) at buildValue (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:1010:13) at buildInnerObject (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:380:11) at buildObject (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:501:9) at buildSingleTypeSerializer (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:768:24) at buildValue (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/node_modules/fast-json-stringify/index.js:1010:13) at buildInnerObject (/app/node_modules/.pnpm/fast-json-stringify@5.16.0/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

@mcollina
Copy link
Member

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.

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

2 participants