ssui-openapi3-2ts
v2.0.4
Published
[](https://github.com/chenshuai2144/openapi2typescript) [](https://www.npmjs.com/package/openapi
Readme
介绍
根据 OpenApi3 文档生成 request 请求代码。
如果你使用 umi ,你可以使用@umijs/plugin-openapi 插件。
使用
npm i --save-dev openapi2ts在项目根目录新建 openapi.config.ts
const { generateService } = require('openapi2ts')
generateService({
schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
serversPath: './servers',
})
在 package.json 的 script 中添加 api: "openapi": "ts-node openapi.config.ts",
生成api
npm run openapi参数
| 属性 | 必填 | 备注 | 类型 |
| ---- | ---- | ---- | ---- |
| requestLibPath | 否 | 自定义请求方法路径 | string |
| requestImportStatement | 否 | 自定义请求方法表达式 | string |
| apiPrefix | 否 | api 的前缀 | string |
| serversPath | 否 | 生成的文件夹的路径 | string |
| schemaPath | 否 | openAPI 3.0 的地址 | string |
| projectName | 否 | 项目名称 | string |
| namespace | 否 | 命名空间名称 | string |
| optionsParamType | 否 | 自定义生成函数中 options 参数的类型,默认 {[key: string]: any} | string |
