从打字稿界面生成swagger文档 [英] Generating swagger docs from typescript interfaces

查看:139
本文介绍了从打字稿界面生成swagger文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 swager-jsdoc 来记录该应用程序的所有DTO. /p>

我想知道有什么方法可以从打字稿界面自动生成swagger文档.

我在项目中有很多,还有很多猫鼬的模式和模型.使它们保持同步变得很乏味.另一方面,我不想使用招摇工具.我更喜欢自下而上的方法.

欢呼

解决方案

tsoa 的另一个选项是路由控制器 + https://github.com/YousefED/typescript-json-schema ,它从Typescript接口生成JSONS chema;在JSON Schema中定义了模型之后,您与OpenAPI规范就相距不远了.

I'm using swager-jsdoc to document all the DTOs of the app.

I was wondering is there any way to generate the swagger docs automatically from typescript interfaces.

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.

Cheers

解决方案

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!

One more option is https://github.com/YousefED/typescript-json-schema, which generates JSONS chema out of Typescript interfaces; after you've got your models defined in JSON Schema you're not terribly far off from an OpenAPI spec.

这篇关于从打字稿界面生成swagger文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆