【发布时间】:2021-01-30 13:13:29
【问题描述】:
我无法让 Swagger 正常工作。我可以获得请求正文的示例,但不能获得响应或 swagger-json。响应显示为{},swagger-json 为:
{
statusCode: 404,
message: "Cannot GET /swagger-json",
error: "Not Found",
}
我的nest-cli.json 文件是:
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"plugins": ["@nestjs/swagger/plugin"]
}
}
在我的 main.ts 我有:
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
...
const options = new DocumentBuilder()
.setTitle('ILuvCoffee')
.setDescription('Coffee Application')
.setVersion('1.0')
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);
我正在学习 Nest.js 课程,到目前为止,我一直非常忠实地学习。当我遇到这个问题时,我仔细检查了我的代码是否正确,甚至是复制/粘贴。我还仔细检查了我的 DTO 文件是否遵循 *.dto.ts 和我的实体文件 *.entity.ts。但我仍然无法让 Swagger 展示除请求之外的任何内容。想法?谁看到了我看不到的东西?
如果您想深入了解,这里是我的回购:https://github.com/jstrother/iluvcoffee
谢谢!
【问题讨论】: