Open machendos opened 5 months ago
I know that default nest.js swagger generator regenerates document every time I save any changes and product is getting restart. Probably there're might be some hooks https://docs.nestjs.com/openapi/cli-plugin
Consider nestjs hook: onApplicationBootstrap()
https://docs.nestjs.com/fundamentals/lifecycle-events#lifecycle-events-1
I've researched and studied the automatic re-generation of Swagger Documents from the @nestia/sdk
library. However, I could not find the solution. It's because the NestJS.onApplicationBootstrap()
function is of runtime, and nestia swagger generator is of compilation time.
Instead, I though another idea to accomplish this issue. If NestJS core team decides to support OpenAPI v3.1, and adapts typia
's JSON schema generator on their @nestjs/swagger
library in the compiler plugin mode, I can solve this problem by contributing to @nestjs/swagger
(maybe @nestia/sdk
would not be used more for OpenAPI generation).
So I wanna ask to the NestJS developers @kamilmysliwiec, @flamewow and @micalevisk. How do you think about this plan?
As you know, current @nestia/sdk
constructs OpenAPI operations and JSON schema definitions automatically just by analyzing the TypeScript source code in the compliation level. It is possible to doing the same thing in the @nestjs/swagger
with compiler plugin function of https://github.com/nestjs/swagger/blob/master/lib/plugin/compiler-plugin.ts
as you can see, I'm the last person who can opine about @nestjs/swagger
but if you find a nice way to hijack the compiler plugin from @nestjs/swagger
without introducing code related to 3rd-party packages onto it in order to make it more flexible for such integrations, it would be really cool.
About OpenAPI v3.1, I guess @nestjs/swagger
must support it one day or at least allow consumers to define which version they want to generate. There's no ETA, tho.
@micalevisk Well, to convert TypeScript type to JSON schema or OpenAPI operation, have to make complicate type schema system. So it is hard to accomplish the goal without 3rd party library (of my typia
). It may possible to duplicate below codes to the @nestjs/swagger
, but it seems not a good strategy.
If my suggestion be rejected, @machendos @Untaek you should just run the cp.execSync("npx nestia swagger", ...)
statement through the NestJS.onApplicationBootstrap()
function.
@micalevisk By the way, about the multiple OpenAPI versions supporting, I am using this strategy.
Don't know how to.