我已经按照创建 Swagger 文档的说明 https://docs.nestjs.com/recipes/swagger,我的文档现在可以使用 Swagger UI 获取。我还想将文档生成为 JSON 或 YAML,这样就可以轻松导入,例如邮递员,但我在 中找不到任何合适的方法SwaggerModule
,Swagger UI 也没有任何导出按钮。
根据这个github问题 https://github.com/nestjs/swagger/issues/57#issuecomment-368238060你可以将创建的 Swagger 字符串化document
以及例如像这样将其写入文件系统:
const app = await NestFactory.create(ApplicationModule);
const options = new DocumentBuilder()
.setTitle("Title")
.setDescription("description")
.setVersion("1.0")
.build();
const document = SwaggerModule.createDocument(app, options);
fs.writeFileSync("./swagger-spec.json", JSON.stringify(document));
SwaggerModule.setup("/api", app, document);
await app.listen(80);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)