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

Duplicate name noticed #64

Open
NewEgoDoc opened this issue Sep 11, 2024 · 0 comments
Open

Duplicate name noticed #64

NewEgoDoc opened this issue Sep 11, 2024 · 0 comments
Assignees

Comments

@NewEgoDoc
Copy link

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:

  1. 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);
}
  1. 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;
                    };
                };
            };
        };
    };
}>;
  1. then enter the terminal npm run start:dev
  2. 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
Uploading image.png…
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
@hyeonss0417 hyeonss0417 self-assigned this Sep 13, 2024
@hyeonss0417 hyeonss0417 added bug Something isn't working and removed bug Something isn't working labels Sep 13, 2024
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