samchon / nestia

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

Can swagger generation happens automatically when the app locally is restarted after save action? #836

Open machendos opened 5 months ago

samchon commented 5 months ago

Don't know how to.

machendos commented 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

Untaek commented 3 months ago

Consider nestjs hook: onApplicationBootstrap()

https://docs.nestjs.com/fundamentals/lifecycle-events#lifecycle-events-1

samchon commented 2 months ago

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

micalevisk commented 2 months ago

image

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.

samchon commented 2 months ago

@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.

samchon commented 2 months ago

@micalevisk By the way, about the multiple OpenAPI versions supporting, I am using this strategy.

  1. Just make the OpenAPI v3.1 specified document
  2. If wanna another versions, just downgrade it from the v3.1 spec
  3. Here is the related repo: https://github.com/samchon/openapi