chen1tian / openapi2typescript

一个被大范围使用的小工具

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

使用说明

示例

在test目录下增加文件testgen.js

内容如下:

const openAPI = require('../dist/index');

openAPI.generateService({
  schemaPath: 'http://localhost:5000/ReleaseManager/swagger/v1/swagger.json',
  serversPath: './temp/relMgr-api',  
  namespace: 'relMgr',
  wrapResult: 'Api.Response'
});

package.jsonscript 中添加 api: "relMgr": "ts-node ./test/genSwagger.js",

生成api

npm run relMgr

参数

属性 必填 备注 类型 默认值
requestLibPath 自定义请求方法路径 string -
requestImportStatement 自定义请求方法表达式 string -
apiPrefix api 的前缀 string -
serversPath 生成的文件夹的路径 string -
schemaPath Swagger 2.0 或 OpenAPI 3.0 的地址 string -
projectName 项目名称 string -
namespace 命名空间名称 string API
mockFolder mock目录 string -
enumStyle 枚举样式 string-literal | enum string-literal
nullable 使用null代替可选 boolean false
dataFields response中数据字段 string[] -
wrapResult 用来包含response结果的对象 obj -

对于apiPrefix属性,默认是生成插入值变量,如果需要直接生成字符串,那么需要这样用apiPrefix:'"apiPrefix"'

About

一个被大范围使用的小工具


Languages

Language:TypeScript 85.6%Language:Nunjucks 8.5%Language:JavaScript 5.8%Language:Batchfile 0.0%