samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.76k stars 91 forks source link

TransformerError when generating Swagger #848

Closed samirotiv closed 1 month ago

samirotiv commented 5 months ago

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.

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
sto-exec-core@0.0.1 /home/samir/git/repo/server
├─┬ @nestia/core@2.6.0
│ └── typia@5.5.7 deduped
├─┬ @nestia/sdk@2.6.0
│ └── typia@5.5.7 deduped
└── typia@5.5.7

samir@Samir-G14:~/git/repo/server$ npm ls nestia
sto-exec-core@0.0.1 /home/samir/git/repo/server
└── nestia@5.3.0
samchon commented 5 months ago

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\@nestia+sdk@2.6.0_@nestia+fetcher@2.6.0_@nestjs+common@10.3.5_@nestjs+core@10.3.5_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\@nestia+sdk@2.6.0_@nestia+fetcher@2.6.0_@nestjs+common@10.3.5_@nestjs+core@10.3.5_reflect-met_4jhrkegpi6yclokwk3axwtrrcu\node_modules\@nestia\sdk\lib\generates\SwaggerGenerator.js:5:58)
samirotiv commented 5 months ago

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 commented 5 months ago

You are using undefined type in somewhere.

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

samirotiv commented 5 months ago

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 commented 5 months ago

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.

samchon commented 1 month ago

Fixed this issue by enhancing @nestia/sdk.

niklonskyidb commented 2 weeks ago
  • bigint type is not allowed.

TypeError: Invalid type detected

How come bigint type could be invalid, if on the swagger page of nestia docs it is listed as one of the types for DTO properties?

samchon commented 2 weeks ago

@niklonskyidb it is because JSON does not support it.