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

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

Open
machendos opened this issue Mar 19, 2024 · 7 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested wontfix This will not be worked on

Comments

@machendos
Copy link

No description provided.

@samchon
Copy link
Owner

samchon commented Mar 21, 2024

Don't know how to.

@samchon samchon added the help wanted Extra attention is needed label Mar 21, 2024
@machendos
Copy link
Author

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
Copy link

Untaek commented May 25, 2024

Consider nestjs hook: onApplicationBootstrap()

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

@samchon
Copy link
Owner

samchon commented Jun 12, 2024

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

@samchon samchon self-assigned this Jun 12, 2024
@samchon samchon added question Further information is requested wontfix This will not be worked on good first issue Good for newcomers labels Jun 12, 2024
@micalevisk
Copy link

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
Copy link
Owner

samchon commented Jun 12, 2024

@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
Copy link
Owner

samchon commented Jun 12, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants