typescript - 如何使用 Typescript 和 Node 生成 REST API 文档?
问题描述
我可以使用https://github.com/TypeStrong/typedoc创建像https://apidocjs.com/这样的 REST API 文档吗?
欢迎任何关于如何重用 TypeScript 类型来生成 REST API 文档的建议(使用 Next.js)
解决方案
如果您真正想要的是在 TypeScript 中描述您的 API 并从中得出 Swagger/OpenAPI 定义,请尝试https://github.com/airtasker/spot
IT 不仅会生成 REST API 文档,还会让您运行一个模拟服务器,其中包含符合 REST API 定义(用于测试客户端)的随机数据和一个数据模型验证器(用于测试服务器)。
项目自述文件中的示例:
import { api, endpoint, request, response, body } from "@airtasker/spot";
@api({
name: "My API"
})
class Api {}
@endpoint({
method: "POST",
path: "/users"
})
class CreateUser {
@request
request(@body body: CreateUserRequest) {}
@response({ status: 201 })
response(@body body: CreateUserResponse) {}
}
interface CreateUserRequest {
firstName: string;
lastName: string;
}
interface CreateUserResponse {
firstName: string;
lastName: string;
role: string;
}
推荐阅读
- javascript - 滑块在 wordpress 网站中无法正常工作
- node.js - 将包发布到 npm 注册表时 bundledDependencies 会做什么?(使用“npm publish”时,而不是使用“npm pack”时)
- c# - 如何在 C# 中处理带有转义字符的变量字符串?
- android - android支持所有屏幕尺寸
- angular - Angular - Mat 选项选择的值不起作用
- dependency-injection - 在 WPF 应用程序中使用带有 Prism Unity 的 [Dependency] 属性
- node.js - 没有返回结果的firestore
- python - 未能在列表中添加项目:“无类型”对象没有属性“附加”
- google-apps-script - 如何使用谷歌应用脚本修改每个 API 请求的 JSON 数组中的值
- network-traffic - D-ITG 流量生成器 绑定到接收方错误 接收方错误