2
const app = await NestFactory.create(AppModule);
app.useGlobalFilters(new AllExceptionsFilter());
app.enableCors();
app.useGlobalPipes(new ValidationPipe());

const config = new DocumentBuilder()
               .setTitle('API')
               .setDescription('Node Api to connec')
               .setVersion('1.0.0')
               .build();
const document = `SwaggerModule.createDocument`(app, config);
SwaggerModule.setup('api', app, document);

await app.listen(8000);

I have some modules like user module(UserModule), driver module(DriverModule). I only want driver module's api to be shown in swagger.

I know SwaggerModule.createDocument have third parameter for SwaggerOption.

const option:SwaggerDocumentOptions = {
 include: [() => DriversModule],
 deepScanRoutes: true
}
const document = SwaggerModule.createDocument(app, config, option);

But after writing like this Swagger is not showing any api. I am getting No operations defined in spec! message from swagger in UI. I am unable to figure out what I am doing wrong.

Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27

1 Answers1

3
const option:SwaggerDocumentOptions = {
  include: [() => DriversModule],
  deepScanRoutes: true
}
const document = SwaggerModule.createDocument(app, config, option);

The problem was in include property. I was giving a function which return module. When I wrote module directly then it works.

const option:SwaggerDocumentOptions = {
  include: [DriversModule],
  deepScanRoutes: true
}
const document = SwaggerModule.createDocument(app, config, option);

This will work.

Mritunjay Upadhyay
  • 1,004
  • 1
  • 15
  • 27