从 typescript 接口生成 swagger 文档 [英] Generating swagger docs from typescript interfaces
问题描述
我正在使用 swager-jsdoc 来记录应用程序的所有 DTO.
I'm using swager-jsdoc to document all the DTOs of the app.
我想知道有没有办法从 typescript 接口自动生成 swagger 文档.
I was wondering is there any way to generate the swagger docs automatically from typescript interfaces.
我在项目中有很多,还有很多猫鼬模式和模型.让它们保持同步变得越来越乏味.另一方面,我不想使用 swagger 生成工具.我更喜欢自下而上的方法.
I have a lot of them in the project and also a lot of mongoose schemas and models. It is getting tedious to keep them in sync. On the other hand I do not want to use the swagger generation tools. I prefer the bottom-up approach.
干杯
推荐答案
tsoa 的另一个选项是 路由控制器 + 路由-控制器-openapi.两者之间的主要区别(AFAIK)是 tsoa
依赖于代码生成,而 routing-controllers
完全在运行时运行.这两种方法都有其优点: tsoa
能够例如利用更丰富的元数据(例如代码注释),而使用 routing-controllers
我们可以跳过生成步骤.我的建议是两个都去看看!
Another option to tsoa is routing-controllers + routing-controllers-openapi. The main difference between the two (AFAIK) is that tsoa
relies on code generation whereas routing-controllers
operates wholly on runtime. Both methods have their upsides: tsoa
is able to e.g. utilize richer metadata (such as code comments) whereas with routing-controllers
we can skip the generation step. My recommendation is to check both out!
还有一个选项是 typescript-json-schema,它会生成 JSON SchemaTypescript 接口;在 JSON Schema 中定义模型后,您与 OpenAPI 规范相差不远.
One more option is typescript-json-schema, which generates JSON Schema out of Typescript interfaces; after you have defined your models in JSON Schema you're not terribly far off from an OpenAPI spec.
这篇关于从 typescript 接口生成 swagger 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!