1

Introductory: have a NestJS app with 2 different swagger routes(api/test1 and api/test2). In main.ts construct swagger with

const app = await NestFactory.create(AppModule, {
  logger: new CustomLogger(),
});
await constructSwagger(app, test1SwaggerConfig);
await constructSwagger(app, test2SwaggerConfig);
// constructSwagger
 const filePromises = swaggerModules.map(async (module) => {
    const documentConfig = new DocumentBuilder()
      .setTitle(module.name)
      .build();

    const document = SwaggerModule.createDocument(app, documentConfig, {
      operationIdFactory: (controllerKey: string, methodKey: string) =>
        `[${controllerKey}] ${methodKey}`,
      include: module.include,
    });
    await writeFile(`./public/swagger/${module.file}`, dump(document));
  });

  await Promise.all(filePromises);
 const documentConfig = new DocumentBuilder()
    .setTitle(config.name)
    .build();

  const document = SwaggerModule.createDocument(app, documentConfig, {
    operationIdFactory: (controllerKey: string, methodKey: string) =>
      `[${controllerKey}] ${methodKey}`,
  });

  const modules = config.modules || swaggerModules;

  SwaggerModule.setup(config.path, app, document, {
    customSiteTitle: config.name,
    swaggerUrls: modules.map((m) => m.swaggerUrl),
  });

Example of test1SwaggerConfig:

export const test1SwaggerConfig: SwaggerConfig = {
  name: 'API TEST',
  path: '/api/test1/',
  version: '1.0.0',
  modules: [
    testSwagger,
  ],
};

const testSwagger: SwaggerModuleConfig = {
  name: 'TEST',
  include: [Test1Module],
  file: 'test1-api.yaml',
  swaggerUrl: {
    url: '/api/v1/test1/swagger/test1-api.yaml',
    name: 'Test1',
  },
};

Question: how to hide route from api/test1, but so that it remains in api/test2?

@ApiExcludeEndpoint doesn't apply to this, cause it's hide this route from all documents. Exptecting that in /api/test1 hide route, but in /api/test2 it exist.

Nikitonu4
  • 41
  • 2

0 Answers0