关于openAPI
什么是OpenAPI ?
OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API, including:
Available endpoints (/users) and operations on each endpoint (GET /users, POST /users)
Operation parameters Input and output for each operation
Authentication methods
Contact information, license, terms of use and other information.
API specifications can be written in YAML or JSON. The format is easy to learn and readable to both humans and machines. The complete OpenAPI Specification can be found on GitHub: OpenAPI 3.0 Specification。
以上来源于what is open api openAPI 是对REST API 的描述。 一个 openAPI 文档包含下列内容:
- 接口的path和方法
- 调用接口输入输出参数
- 认证方式
- 协议信息及其他信息
根据api的描述文件可以做很多事情,在前端能够想到的事情就是去自动生成 ts types, 或者 生成接口调用文件(axios 或者 fetch 等)
自动生成 typescript type 类型
目前搜集到已有的这些工具
- openapi-generator
- dtsgenerator:TypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file. 这个支持namespace
- json-schema-to-typescript
- quickType can convert json schema to all languages
目前来看只有 quickType 有online tool quickType