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

TransformerError when generating Swagger #848

Open
samirotiv opened this issue Mar 25, 2024 · 5 comments
Open

TransformerError when generating Swagger #848

samirotiv opened this issue Mar 25, 2024 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@samirotiv
Copy link

Bug Report

Firstly, really appreciate your hard work, @samchon ! Thanks for having this issue tracker so that we can request your support. Thanks again.

Summary

Write a short summary of the bug in here.

  • Nestia Version: 5.3.0
  • Expected behavior: npx nestia swagger should generate swagger files
  • Actual behavior: I get the error TransformerError: invalid type on argument

I am trying to generate Swagger documentation using Nestia. I fixed every issue it was reporting, I am unfortunately not able to make sense of this error. If you could help me make sense of this error, I will be able to fix my code.

The reason I've reported this as a bug is this seems to be an exception not handled gracefully, maybe handling it and showing a friendly error would help users like me.

If I am missing something obvious, apologies in advance.

I get an error like:

TransformerError: invalid type on argument - (undefined, 2)
    at new TransformerError (/home/samir/git/sto-exec-core/server/node_modules/typia/src/transformers/TransformerError.ts:11:10)
    at /home/samir/git/sto-exec-core/server/node_modules/typia/src/programmers/json/JsonApplicationProgrammer.ts:39:19
    at Array.map (<anonymous>)
    at /home/samir/git/sto-exec-core/server/node_modules/typia/src/programmers/json/JsonApplicationProgrammer.ts:36:28
    at /home/samir/git/sto-exec-core/server/node_modules/@nestia/sdk/src/generates/SwaggerGenerator.ts:91:9
    at Generator.next (<anonymous>)
    at fulfilled (/home/samir/git/sto-exec-core/server/node_modules/@nestia/sdk/lib/generates/SwaggerGenerator.js:5:58) {
  code: 'typia.json.application'
}

Code occuring the bug

// nestia configuration file
import type sdk from '@nestia/sdk';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from "@nestjs/platform-fastify";

import { AppModule } from './src/app.module';
import fastifyCookie from '@fastify/cookie';

const NESTIA_CONFIG: sdk.INestiaConfig = {
    input: () => {
        let appPromise = NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
        return appPromise.then((app)=>{
            return app.register(fastifyCookie).then((value)=>{
                return app;
            })
        })
    },
    //output: 'packages/api',
    swagger: {
        output: 'swagger/swagger.json',
        servers: [
            {
                url: 'http://localhost:3000',
                description: 'Local Server',
            },
        ],
        beautify: true,
    },
    //distribute: 'packages/api',
    //primitive: false,
    //simulate: true,
};
export default NESTIA_CONFIG;

Versions:

samir@Samir-G14:~/git/repo/server$ npm ls typia
[email protected] /home/samir/git/repo/server
├─┬ @nestia/[email protected]
│ └── [email protected] deduped
├─┬ @nestia/[email protected]
│ └── [email protected] deduped
└── [email protected]

samir@Samir-G14:~/git/repo/server$ npm ls nestia
[email protected] /home/samir/git/repo/server
└── [email protected]
@samchon
Copy link
Owner

samchon commented Mar 25, 2024

You're using some type(s) that is not supported in the JSON.

If you see the detailed message, you can find out which type is occuring the error.

Also, you can earily get the error mesage by using @nestia/core decorators with tsc command.

-----------------------------------------------------------
 Nestia Swagger Generator
-----------------------------------------------------------
Analyzing reflections
  - controllers: #2
  - paths: #2
  - routes: #2
Analyzing source codes
Generating Swagger Documents
..\..\..:BbsArticlesController.update:input - error TS(@nestia/sdk): invalid type detected.

  - bigint type is not allowed.


TypeError: Invalid type detected
    at D:\github\samchon\nestia\test\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]_reflect-met_4jhrkegpi6yclokwk3axwtrrcu\node_modules\@nestia\sdk\src\generates\SwaggerGenerator.ts:124:15
    at Generator.next (<anonymous>)
    at fulfilled (D:\github\samchon\nestia\test\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected]_@[email protected]_reflect-met_4jhrkegpi6yclokwk3axwtrrcu\node_modules\@nestia\sdk\lib\generates\SwaggerGenerator.js:5:58)

@samchon samchon self-assigned this Mar 25, 2024
@samchon samchon added the question Further information is requested label Mar 25, 2024
@samirotiv
Copy link
Author

samirotiv commented Mar 25, 2024

Thanks a lot for your prompt reply, @samchon , but unfortunately I am not being shown any such helpful debug message.

Could you please suggest any further possibilities of how I could fix this?

Sharing the complete log here for reference:

-----------------------------------------------------------
 Nestia Swagger Generator
-----------------------------------------------------------
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [NestFactory] Starting Nest application...
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullModule dependencies initialized +25ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BoardModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullBoardModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] PrismaModule dependencies initialized +1ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] HttpModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullBoardFeatureModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullBoardRootModule dependencies initialized +1ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] ClsModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] LoggerModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] ConfigModule dependencies initialized +4ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] EventEmitterModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] TenancyModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] BullModule dependencies initialized +1ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] PeopleModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] ProjectModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] AuthModule dependencies initialized +1ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] TaskModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] AssetsModule dependencies initialized +0ms
[Nest] 28531  - 03/25/2024, 11:20:21 PM     LOG [InstanceLoader] TransactionsModule dependencies initialized +0ms
Analyzing reflections
  - controllers: #7
  - paths: #43
  - routes: #43
Analyzing source codes
Generating Swagger Documents
TransformerError: invalid type on argument - (undefined, 2)
    at new TransformerError (/home/samir/git/repo/server/node_modules/typia/src/transformers/TransformerError.ts:11:10)
    at /home/samir/git/repo/server/node_modules/typia/src/programmers/json/JsonApplicationProgrammer.ts:39:19
    at Array.map (<anonymous>)
    at /home/samir/git/repo/server/node_modules/typia/src/programmers/json/JsonApplicationProgrammer.ts:36:28
    at /home/samir/git/repo/server/node_modules/@nestia/sdk/src/generates/SwaggerGenerator.ts:91:9
    at Generator.next (<anonymous>)
    at fulfilled (/home/samir/git/repo/server/node_modules/@nestia/sdk/lib/generates/SwaggerGenerator.js:5:58) {
  code: 'typia.json.application'
}

@samchon
Copy link
Owner

samchon commented Mar 25, 2024

You are using undefined type in somewhere.

If possible, hope to be provided the reproducible repo for detailed debugging.

@samirotiv
Copy link
Author

Hi @samchon , you were indeed correct - the repo had some APIs which were directly responding using Fastify instead of using NestJS by returning the object. This is fixed and is working now.

It took me a long time to find this out by trial and error, and I tried doing this by inserting logs in the Nestia / Typia code, but failed at getting any useful info. The error came out of Typia, but there was no source info there, and I couldn't find the right place to put in some debugging info in Nestia.

image

If there is some way to inject some dog tags (debugging / source info) into this LazySchemas object, it will enable Typia to give an error message which is more informative about things like the function name, file name, which is causing trouble.

If you can give me any hints as to how to do this, happy to contribute and send a PR.

@samirotiv
Copy link
Author

Although my problem is solved, I am not closing the issue since it could still bother other users (even me myself) to easily locate the source of trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants