NestJS - Swagger JSON 导出

Ved*_*ic. 0 swagger swagger-ui nestjs

我有 Swagger,效果很好。但我找不到将路由导出为 JSON 的方法。我记得这样做过,只需在浏览器中访问一个 URL,但现在我不记得了。

我的招摇设置是这样的:

const swaggerOptions = new DocumentBuilder()
    .setTitle('Some API Docs')
    .setDescription('Some API description')
    .setVersion('1.0')
    .build();

  const swaggerDocument = SwaggerModule.createDocument(app, swaggerOptions);
  SwaggerModule.setup('docs', app, swaggerDocument);
Run Code Online (Sandbox Code Playgroud)

我可以使用以下命令访问 Swagger UI: localhost:3000/docs

我已阅读官方文档,他们提到使用:

  • http://localhost:3000/api/json 或 http://localhost:3000/api-json

另外,我看了SO,有这个线程

不幸的是,这些都不适用于我的情况。

获取 JSON 格式文档的 URL 是什么?

Jes*_*ter 10

根据您的 SwaggerModule 配置,JSON 的 URL 应位于/docs-json

官方文档提到api-json因为他们注册使用api作为第一个参数