1.0.18 • Published 1 month ago

swaggerconvapi2 v1.0.18

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
1 month ago

useNode

node ./index.cjs JSON config

installGlobalUse

swapi JSON config

swaggerConvApi2

-- 已完成 swaggerConvApi2 工厂化 新增配置项,配置文件 新增模板 独立函数解析封装 ts 迁移

-- 下次迭代 esbuild 打包支持 rollup-plugin-esbuild ts 打包支持 minimist 参数支持 prettier 格式化支持 更友好的错误提示

-- 下下次迭代 线上化


使用说明:需生成 dist 文件使用

源码 index.cjs 运行:

yarn 进行安装。

运行的完整命令

node index.cjs ./JSON/jwai.json ./config/jwai.json 【ps: node index.js {apiJSONPath} {configJSONPath}

安装方式运行:

1.组件方式运行: 现可以直接 yarn add swaggerconvapi2 进行安装.npx swapi JSON config 运行

MacOS:安装时文件夹必须含有 package.json,否则会在你的系统目录下生成 node_modules,安装到全局目录环境.
将所需的 JSON 与 config 文件放入该文件夹,执行命令即可。
例如:npx swapi ./JSON/jwai.json ./config/jwai.json

2.全局方式运行: 可进行全局安装 —— yarn global add swaggerconvapi2 执行此命令, 全局安装后,再进行 swapi ./JSON/jwai.json 即可。

【注:需有 config 文件夹,若无,则需指定路径即可如:wapi ./JSON/jwai.json xxx/xxx/config/jwai.json】

ConfigFile

输出用配置

outDir = 'dist'; //主要输出文件夹string outMode = 1; //1 单文件模式 single;2 多文件模式 mutilenumber mainPath = ''; //输出到的路径/目录string main = 'index'; //主要标志命名string paramsPath = ''; //typeparams路径/目录string paramsMain = ''; //typeparams文件名称前缀string modelPath = ''; //modeltype路径/目录string modelMain = ''; //modeltype路径文件名称string

基础配置

baseUrl = ''; //默认路径 baseUrlMode = 1; //1 忽略模式将会忽略 path 中的 baseUrl;2 统一添加模式将会统一添加 baseUrl

模板

_ paramsLocation //params 的位置不存在时不设置修改后改为特定的 option 值
_ bodyLocation // bodyLocation 不存在时会尝试清理{body},替换{body}
_ template //模板用字符串
_ 模板说明大括号连续将进行覆盖覆盖会进行替换覆盖完后不含大括号!!!
_ {apiKey} 工具名不是很重要
_ {name} 接口名位置 formatPath 格式化
_ {arg} 传参位置
_ {request} 返回类型位置
_ {protocol} 协议类型不是很重要
_ {path} 路径位置
_ {option} 扩展配置位置
_ {body} body 位置

topReference = TopReference; //文件顶部注入的字符串模板 getTemplate = GetTemplate; //get 协议的模板 postTemplate = PostTemplate; //post 协议的模板 putTemplate = PutTemplate; //put 协议的模板 deleteTemplate = DeleteTemplate; //del 协议的模板

钩子

formatPath = undefined; //格式化 api 路径 formatInterfaceName = undefined; //格式化接口名称

API 相关配置

ignoreParams = []; //需要忽略处理的字段列表 DefaultOption = {}; //API 对象默认的 options

特殊处理路径

bufferPath = []; //手动定义为 bufferRequest 的路径

API 解析相关

apiKey = 'api'; //api 的默认引用 version = '3'; //解析的 openApi 版本 tagsKey = 'tags'; //openapi 的 Tags 对象 key pathsKey = 'paths'; //openapi 的 PathsKey 对象 key classTypesPath = undefined; //openapi 的 ClassTypes 对象 key,api.components.schemas(v3)\api.definitions(v2)默认不传入自动识别 defaultResponseBody = 'form'; //默认主体类型 json(application/json)form(multipart/form-data)

1.0.18

1 month ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago