生成Swagger JSON文件而无需运行Nest JS服务器
does anyone know of a way(either official or through a 3rd-party tool) to generate swagger json files without needing the nest js server to run?
我有一个带有控制器路由的Nest JS应用程序,并用 @Nest/Swagger Decorator进行了注释,用于文档。我知道我可以通过启动服务器和访问 /api-json来获取Swagger JSON文件,但是我需要能够生成此文件而无需先启动服务器。
does anyone know of a way(either official or through a 3rd-party tool) to generate swagger json files without needing the nest js server to run?
I have a nest js application with controller routes and DTO's annotated with @nest/swagger decorators for documentation. I know I can get the swagger json files by starting the server and visiting /api-json but I need the ability to generate this file without having to start the server first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在没有启动服务器的情况下从我的E2E测试中生成了一个摇摇欲坠的文件。
下面的代码在一个 *.json文件中生成了一个摇摇欲坠的规格,您可以将其粘贴到 https://editor.swagger.io/
注意:我的包装中的 @nestjs/Swagger的版本是5.2.0
I managed to generate a swagger file from my e2e tests without starting the server.
The code below generates a swagger spec in a *.json file that you can paste into https://editor.swagger.io/
Note: My version of @nestjs/swagger in my package.json is 5.2.0
就我而言,PostgreSQL数据源是一种依赖性,因此我最终决定使用内存数据库,
pg-mem
在E2E测试上运行。这是我实现Swagger.json
导出的方式。src/app.module.ts
test/swagger.e2e-spec.ts
如果您依赖
” > nest-cli.json
,例如用于架构定义属性生成,默认情况下,该配置不是在e2e
执行上应用于ts-jest
在存储器中即时编译您的源代码文件(参考:noreferrer”> https://docs.nestjs.com/openapi/cli-plugin#integration-with-with-ts-jest-e2e-tests ),因此您需要在 test/Swagger 。
In my case, PostgreSQL datasource was a dependency, so I eventually decided to use memory database,
pg-mem
to run on e2e test. Here is how I achieved theswagger.json
export.src/app.module.ts
test/swagger.e2e-spec.ts
If you rely on
"@nestjs/swagger
plugin atnest-cli.json
such as for schema definition property generation, the config is not applied one2e
execution by default asts-jest
compiles your source code files on the fly, in memory (Ref: https://docs.nestjs.com/openapi/cli-plugin#integration-with-ts-jest-e2e-tests) So you need to create a config file belowtest/swagger.transformer.config.js
and update
jest-e2e.json
in transform block