首页 > 解决方案 > NestJS Swagger 错误 this.getVersionMetadata(metatype, applicationConfig.getVersioning()); applicationConfig.getVersioning 不是函数

问题描述

我已经重新安装了@nestjs/swagger 和 swagger-ui-express。我所有的依赖项都是最新的。但我得到这个错误:

applicationConfig.getVersioning 不是 SwaggerExplorer.exploreRoutePathAndMethod 的功能

我也更新了 tsconfig.ts 文件中的元数据标签。调试后,我可以发现主要问题在于createDocument从 Swagger Module 类调用函数的行。在此之前的每个代码行都可以正常工作。

在控制台日志记录中,我什至可以正确提取配置​​的值。但是,一旦createDocument调用该方法,API 就会因上述错误而崩溃。

我的 main.ts 文件如下所示:

import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';

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

  const config = new DocumentBuilder()
      .setTitle('Invoice Manager API')
      .setDescription('API for Invoice Manager App')
      .setVersion('0.0')
      .addTag('iv-manager')
      .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('/', app, document);
  await app.listen(3000);

}

bootstrap();

标签: swaggernestjs

解决方案


推荐阅读