Open
Description
Describe the bug
using npm run start:dev in nestjs, error comes out. but the problem is that UserDoc is only one in the whole project
/node_modules/tspec/dist/chunks/index.cjs:603
throw new Error(`Duplicate name: ${name}`);
^
Error: Duplicate name: UserDoc
To Reproduce
Steps to reproduce the behavior:
- define
main.ts
async function bootstrap() {
initializeTransactionalContext({ storageDriver: StorageDriver.AUTO });
const app = await NestFactory.create(AppModule, {
abortOnError: true,
logger: new CustomLogger(),
});
app.setGlobalPrefix('/api/v1');
app.useGlobalInterceptors(
new ClassSerializerInterceptor(app.get(Reflector)),
);
app.useGlobalPipes(new ValidationPipe({ transform: true }));
app.use('/docs', await TspecDocsMiddleware(TspecConfig));
await app.listen(3000);
}
- then make the file
user-doc.ts
export type UserDoc = Tspec.DefineApiSpec<{
tags: ['user'];
basePath: '/api/v1/user';
paths: {
'/': {
get: {
summary: 'yeahyeah';
responses: {
200: {
status: 2000;
};
};
};
};
};
}>;
- then enter the terminal
npm run start:dev
- error comes out even if the variable UserDoc is only one in whole project
/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:603
throw new Error(`Duplicate name: ${name}`);
^
Error: Duplicate name: UserDoc
at /Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:603:15
at visitNodes (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:27716:24)
at forEachChildInSourceFile (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:28338:18)
at forEachChild (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:27801:37)
at SourceFileObject.forEachChild (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/typescript-json-schema/node_modules/typescript/lib/typescript.js:141047:18)
at /Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:585:13
at Array.forEach (<anonymous>)
at getTspecSignatures (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:584:15)
at getOpenapiSchemas (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:687:24)
at generateTspec (/Users/jh/Documents/intellij/nestjs/nillily-manbo/node_modules/tspec/dist/chunks/index.cjs:767:13)
Node.js v20.12.0
Expected behavior
I want to solve this problem. actually the solution is to guide to set this code in this environment. and fix the code
I made this section annotated
if (names.includes(name)) {
throw new Error(`Duplicate name: ${name}`);
}
then it worked
Screenshots
this is error log
it is exactly same with no.4 error logs in To Reproduce
Desktop (please complete the following information):
- OS: Macos
- node 20.12.0
- nest: 10.0.0
- typescript: 5.1.3
Metadata
Metadata
Assignees
Labels
No labels