DEV Community

Vishad Patel
Vishad Patel

Posted on

Why Your Swagger Docs Suck (And How to Fix Them in NestJS)

If you’re like most teams, your Swagger docs are a mess. They’re either outdated, too generic, or just a checkbox on your project to-do list. But here’s a truth bomb: Swagger docs aren’t just developer fluff. They’re your API’s first impression, your dev team’s secret weapon, and a business enabler.

If you’re using NestJS, you already have a powerful Swagger module at your fingertips. Yet, many projects barely scratch the surface of what’s possible. Let’s fix that today.

This article will guide you through building clean, descriptive, and production-ready Swagger docs in NestJS, adding rich HTML formatting, exporting OpenAPI JSON, creating a dynamic Swagger JSON endpoint, and auto-generating Postman collections for your team.

📖 Read more here

Top comments (4)

Collapse
 
micalevisk profile image
Micael Levi L. C.

you have this in your code examples:

constructor(@Inject('APP_INSTANCE') private readonly app: INestApplicationContext) {}
Enter fullscreen mode Exit fullscreen mode

I'd like to know how did you create that APP_INSTANCE provider

Collapse
 
vishad_patel_f54e007e16e5 profile image
Vishad Patel • Edited

Hope below code helps you


async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.enableShutdownHooks(); // Optional, if needed

  // Register APP_INSTANCE globally
  app.select(AppModule).get(Reflector).constructor.prototype['APP_INSTANCE'] = app;

  // Alternative method using a custom provider
  app.useGlobalProviders([
    {
      provide: 'APP_INSTANCE',
      useValue: app,
    },
  ]);

  await app.listen(3000);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
micalevisk profile image
Micael Levi L. C.

there is no such thing as app.useGlobalProviders in NestJS, tho.

Collapse
 
devops_fundamental profile image
DevOps Fundamental

Insightful and well-written as always!