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

FastifyError: Schema with id 'Schema' already declared! #3

Open
immohanravi opened this issue Oct 20, 2022 · 2 comments
Open

FastifyError: Schema with id 'Schema' already declared! #3

immohanravi opened this issue Oct 20, 2022 · 2 comments

Comments

@immohanravi
Copy link

hi,
First of all, the video is great I have learned a lot, thank you so much.

Looks like there is something has changed in fastify, i have followed your tutorial video everything went great up until I add product.schema to addschema() function in fastify app.ts file. I am getting the below error.

(node:27437) [FST_MODULE_DEP_FASTIFY-JWT] FastifyWarning.fastify-jwt: fastify-jwt has been deprecated. Use @fastify/[email protected] instead. (Use node --trace-warnings ... to show where the warning was created) FastifyError: Schema with id 'Schema' already declared! at Schemas.add (/home/mohan/Programming/fastify/tutorial/node_modules/fastify/lib/schemas.js:33:11) at SchemaController.add (/home/mohan/Programming/fastify/tutorial/node_modules/fastify/lib/schema-controller.js:62:30) at Object.addSchema (/home/mohan/Programming/fastify/tutorial/node_modules/fastify/fastify.js:606:29) at /home/mohan/Programming/fastify/tutorial/src/app.ts:39:16 at Generator.next (<anonymous>) at /home/mohan/Programming/fastify/tutorial/src/app.ts:8:71 at new Promise (<anonymous>) at __awaiter (/home/mohan/Programming/fastify/tutorial/src/app.ts:4:12) at main (/home/mohan/Programming/fastify/tutorial/src/app.ts:41:12) at Object.<anonymous> (/home/mohan/Programming/fastify/tutorial/src/app.ts:56:1) [ERROR] 21:10:41 FastifyError: Schema with id 'Schema' already declared! Child got SIGTERM, exiting.

Error is because of that id, see below console.log of schema

Screenshot_20221020_212101

I have no idea how to solve it, I thought I made some error but the same problem persist even when I clone and run this project. please have a look

@RomainMarcazzan
Copy link

You can specify a unique $id for each schemas
export const { schemas: userSchemas, $ref } = buildJsonSchemas( { registerSchema, registerResponseSchema, loginSchema, loginResponseSchema, getUsersResponseSchema, }, { $id: "UserSchema", } );

export const { schemas: postSchemas, $ref } = buildJsonSchemas( { createPostSchema, postResponseSchema, postsResponseSchema, }, { $id: "PostSchema", } );

I think it's not post but product in the tutorial but it's the same idea

@cwgabel
Copy link

cwgabel commented Jul 31, 2023

I too had the same problem. I was keying along with Tom and then halfway through I got the same error. I suspect it was something I keyed in wrong. I cloned the repo and everything executed as expected.

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

3 participants