echoapi-converter 0.0.65 → 0.0.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +47 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1139,8 +1139,17 @@ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
1139
1139
  (pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
1140
1140
  }
1141
1141
  };
1142
+ const getUserShowName = (data) => {
1143
+ if (lodash.isString(data === null || data === void 0 ? void 0 : data.alias_name) && (data === null || data === void 0 ? void 0 : data.alias_name.length) > 0) {
1144
+ return data === null || data === void 0 ? void 0 : data.alias_name;
1145
+ }
1146
+ if (lodash.isString(data === null || data === void 0 ? void 0 : data.nick_name) && (data === null || data === void 0 ? void 0 : data.nick_name.length) > 0) {
1147
+ return data === null || data === void 0 ? void 0 : data.nick_name;
1148
+ }
1149
+ return '';
1150
+ };
1142
1151
  const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, target_type) => {
1143
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19;
1152
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
1144
1153
  const path = recursiveFolderPath("", sourceObj, pid, pidName);
1145
1154
  const pathItem = {
1146
1155
  'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || '',
@@ -1159,7 +1168,7 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1159
1168
  pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.updated_at;
1160
1169
  }
1161
1170
  if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
1162
- pathItem['x-updated-user-name'] = (_b = item === null || item === void 0 ? void 0 : item.updated_user) === null || _b === void 0 ? void 0 : _b.nick_name;
1171
+ pathItem['x-updated-user-name'] = getUserShowName(item === null || item === void 0 ? void 0 : item.updated_user);
1163
1172
  }
1164
1173
  if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.attribute_info) && !lodash.isEmpty(item === null || item === void 0 ? void 0 : item.attribute_info)) {
1165
1174
  pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
@@ -1169,16 +1178,16 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1169
1178
  }
1170
1179
  if (['http', 'sse'].includes(target_type)) {
1171
1180
  // 处理 Query 和 Header 参数
1172
- handlePathItemParameters("query", ((_d = (_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.parameter) || [], pathItem);
1173
- handlePathItemParameters("header", ((_f = (_e = item === null || item === void 0 ? void 0 : item.request) === null || _e === void 0 ? void 0 : _e.header) === null || _f === void 0 ? void 0 : _f.parameter) || [], pathItem);
1174
- handlePathItemParameters("cookie", ((_h = (_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.cookie) === null || _h === void 0 ? void 0 : _h.parameter) || [], pathItem);
1175
- handlePathItemParameters("path", ((_k = (_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.restful) === null || _k === void 0 ? void 0 : _k.parameter) || [], pathItem);
1181
+ handlePathItemParameters("query", ((_c = (_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.query) === null || _c === void 0 ? void 0 : _c.parameter) || [], pathItem);
1182
+ handlePathItemParameters("header", ((_e = (_d = item === null || item === void 0 ? void 0 : item.request) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.parameter) || [], pathItem);
1183
+ handlePathItemParameters("cookie", ((_g = (_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.cookie) === null || _g === void 0 ? void 0 : _g.parameter) || [], pathItem);
1184
+ handlePathItemParameters("path", ((_j = (_h = item === null || item === void 0 ? void 0 : item.request) === null || _h === void 0 ? void 0 : _h.restful) === null || _j === void 0 ? void 0 : _j.parameter) || [], pathItem);
1176
1185
  // 处理请求体参数(根据 Swagger 版本)
1177
1186
  if (apiVersion === "2.0") {
1178
- handlePathItemBodyParameters(((_l = item === null || item === void 0 ? void 0 : item.request) === null || _l === void 0 ? void 0 : _l.body) || {}, pathItem, modelsObj);
1187
+ handlePathItemBodyParameters(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
1179
1188
  }
1180
1189
  else {
1181
- handlePathItemRequestBody(((_m = item === null || item === void 0 ? void 0 : item.request) === null || _m === void 0 ? void 0 : _m.body) || {}, pathItem, modelsObj);
1190
+ handlePathItemRequestBody(((_l = item === null || item === void 0 ? void 0 : item.request) === null || _l === void 0 ? void 0 : _l.body) || {}, pathItem, modelsObj);
1182
1191
  }
1183
1192
  // 添加路径标签
1184
1193
  if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
@@ -1193,35 +1202,35 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1193
1202
  switch (target_type) {
1194
1203
  case 'socketio':
1195
1204
  pathItem.description = `${pathItem.description}
1196
- ${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.shake_hands_path) ? t('securityConnectionMessage', {
1197
- enable: ((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1198
- version: ((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.socket_version) || 'v4',
1199
- path: (_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.shake_hands_path
1205
+ ${((_m = item === null || item === void 0 ? void 0 : item.config) === null || _m === void 0 ? void 0 : _m.shake_hands_path) ? t('securityConnectionMessage', {
1206
+ enable: ((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1207
+ version: ((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.socket_version) || 'v4',
1208
+ path: (_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.shake_hands_path
1200
1209
  }) : t('securityConnectionMessageNoPath', {
1201
- enable: ((_s = item === null || item === void 0 ? void 0 : item.config) === null || _s === void 0 ? void 0 : _s.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1202
- version: ((_t = item === null || item === void 0 ? void 0 : item.config) === null || _t === void 0 ? void 0 : _t.socket_version) || 'v4',
1210
+ enable: ((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1211
+ version: ((_s = item === null || item === void 0 ? void 0 : item.config) === null || _s === void 0 ? void 0 : _s.socket_version) || 'v4',
1203
1212
  })}
1204
1213
  `;
1205
1214
  break;
1206
1215
  case 'websocket2':
1207
1216
  pathItem.description = `${pathItem.description}
1208
1217
  ${t('wsConfigMessage', {
1209
- enable: ((_u = item === null || item === void 0 ? void 0 : item.config) === null || _u === void 0 ? void 0 : _u.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1210
- content: !((_v = item === null || item === void 0 ? void 0 : item.config) === null || _v === void 0 ? void 0 : _v.information_size) || ((_w = item === null || item === void 0 ? void 0 : item.config) === null || _w === void 0 ? void 0 : _w.information_size) == 0 ? t('unlimited') : `${(_x = item === null || item === void 0 ? void 0 : item.config) === null || _x === void 0 ? void 0 : _x.information_size}M`
1218
+ enable: ((_t = item === null || item === void 0 ? void 0 : item.config) === null || _t === void 0 ? void 0 : _t.certificate_verification) == -1 ? t('notNeedEnable') : t('needEnable'),
1219
+ content: !((_u = item === null || item === void 0 ? void 0 : item.config) === null || _u === void 0 ? void 0 : _u.information_size) || ((_v = item === null || item === void 0 ? void 0 : item.config) === null || _v === void 0 ? void 0 : _v.information_size) == 0 ? t('unlimited') : `${(_w = item === null || item === void 0 ? void 0 : item.config) === null || _w === void 0 ? void 0 : _w.information_size}M`
1211
1220
  })}
1212
1221
  `;
1213
1222
  break;
1214
1223
  }
1215
1224
  }
1216
- handlePathItemParameters("query", ((_z = (_y = item === null || item === void 0 ? void 0 : item.request) === null || _y === void 0 ? void 0 : _y.query) === null || _z === void 0 ? void 0 : _z.parameter) || [], pathItem);
1217
- handlePathItemParameters("header", ((_1 = (_0 = item === null || item === void 0 ? void 0 : item.request) === null || _0 === void 0 ? void 0 : _0.header) === null || _1 === void 0 ? void 0 : _1.parameter) || [], pathItem);
1218
- handlePathItemParameters("cookie", ((_3 = (_2 = item === null || item === void 0 ? void 0 : item.request) === null || _2 === void 0 ? void 0 : _2.cookie) === null || _3 === void 0 ? void 0 : _3.parameter) || [], pathItem);
1219
- handlePathItemParameters("path", ((_5 = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.restful) === null || _5 === void 0 ? void 0 : _5.parameter) || [], pathItem);
1225
+ handlePathItemParameters("query", ((_y = (_x = item === null || item === void 0 ? void 0 : item.request) === null || _x === void 0 ? void 0 : _x.query) === null || _y === void 0 ? void 0 : _y.parameter) || [], pathItem);
1226
+ handlePathItemParameters("header", ((_0 = (_z = item === null || item === void 0 ? void 0 : item.request) === null || _z === void 0 ? void 0 : _z.header) === null || _0 === void 0 ? void 0 : _0.parameter) || [], pathItem);
1227
+ handlePathItemParameters("cookie", ((_2 = (_1 = item === null || item === void 0 ? void 0 : item.request) === null || _1 === void 0 ? void 0 : _1.cookie) === null || _2 === void 0 ? void 0 : _2.parameter) || [], pathItem);
1228
+ handlePathItemParameters("path", ((_4 = (_3 = item === null || item === void 0 ? void 0 : item.request) === null || _3 === void 0 ? void 0 : _3.restful) === null || _4 === void 0 ? void 0 : _4.parameter) || [], pathItem);
1220
1229
  if (target_type == 'socketio')
1221
- handlePathItemParameters("event", ((_7 = (_6 = item === null || item === void 0 ? void 0 : item.request) === null || _6 === void 0 ? void 0 : _6.event) === null || _7 === void 0 ? void 0 : _7.parameter) || [], pathItem);
1230
+ handlePathItemParameters("event", ((_6 = (_5 = item === null || item === void 0 ? void 0 : item.request) === null || _5 === void 0 ? void 0 : _5.event) === null || _6 === void 0 ? void 0 : _6.parameter) || [], pathItem);
1222
1231
  // 处理请体
1223
1232
  if (target_type == 'graphql') {
1224
- handleGraphqlRequestBody(((_9 = (_8 = item === null || item === void 0 ? void 0 : item.request) === null || _8 === void 0 ? void 0 : _8.body) === null || _9 === void 0 ? void 0 : _9.query_list) || [], ((_11 = (_10 = item === null || item === void 0 ? void 0 : item.request) === null || _10 === void 0 ? void 0 : _10.body) === null || _11 === void 0 ? void 0 : _11.query_schema) || {}, pathItem, modelsObj);
1233
+ handleGraphqlRequestBody(((_8 = (_7 = item === null || item === void 0 ? void 0 : item.request) === null || _7 === void 0 ? void 0 : _7.body) === null || _8 === void 0 ? void 0 : _8.query_list) || [], ((_10 = (_9 = item === null || item === void 0 ? void 0 : item.request) === null || _9 === void 0 ? void 0 : _9.body) === null || _10 === void 0 ? void 0 : _10.query_schema) || {}, pathItem, modelsObj);
1225
1234
  }
1226
1235
  else {
1227
1236
  handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
@@ -1233,23 +1242,23 @@ ${t('wsConfigMessage', {
1233
1242
  }
1234
1243
  else if (target_type == 'socket_method') {
1235
1244
  // 拼接description
1236
- const configs = (_12 = item === null || item === void 0 ? void 0 : item.request) === null || _12 === void 0 ? void 0 : _12.configs;
1245
+ const configs = (_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.configs;
1237
1246
  if (lodash.isPlainObject(configs)) {
1238
- let requestString = `${t('requestEncodingFormat', { format: configs === null || configs === void 0 ? void 0 : configs.charset })} ${lodash.isArray((_13 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _13 === void 0 ? void 0 : _13.request) && ((_14 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _14 === void 0 ? void 0 : _14.request.length) > 0 ?
1239
- `\n${t('needAddRequestDataHandleFunction')}\n${(_15 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _15 === void 0 ? void 0 : _15.request.map((r, index) => {
1247
+ let requestString = `${t('requestEncodingFormat', { format: configs === null || configs === void 0 ? void 0 : configs.charset })} ${lodash.isArray((_12 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _12 === void 0 ? void 0 : _12.request) && ((_13 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _13 === void 0 ? void 0 : _13.request.length) > 0 ?
1248
+ `\n${t('needAddRequestDataHandleFunction')}\n${(_14 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _14 === void 0 ? void 0 : _14.request.map((r, index) => {
1240
1249
  let str = getTcpMethodFucString(r);
1241
1250
  return str;
1242
1251
  })}`
1243
1252
  : ''}`;
1244
- let responseString = lodash.isArray((_16 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _16 === void 0 ? void 0 : _16.response) && ((_17 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _17 === void 0 ? void 0 : _17.response.length) > 0 ?
1245
- `${t('needAddResponseDataHandleFunction')}\n${(_18 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _18 === void 0 ? void 0 : _18.response.map((r, index) => {
1253
+ let responseString = lodash.isArray((_15 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _15 === void 0 ? void 0 : _15.response) && ((_16 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _16 === void 0 ? void 0 : _16.response.length) > 0 ?
1254
+ `${t('needAddResponseDataHandleFunction')}\n${(_17 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _17 === void 0 ? void 0 : _17.response.map((r, index) => {
1246
1255
  let str = getTcpMethodFucString(r);
1247
1256
  return str;
1248
1257
  })}`
1249
1258
  : '';
1250
1259
  pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
1251
1260
  }
1252
- handleSocketMethodRequestBody(((_19 = item === null || item === void 0 ? void 0 : item.request) === null || _19 === void 0 ? void 0 : _19.body) || {}, pathItem);
1261
+ handleSocketMethodRequestBody(((_18 = item === null || item === void 0 ? void 0 : item.request) === null || _18 === void 0 ? void 0 : _18.body) || {}, pathItem);
1253
1262
  // 处理响应
1254
1263
  pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
1255
1264
  // 添加路径标签
@@ -2047,7 +2056,7 @@ const replaceRef = (schemaObj) => {
2047
2056
  schemaObj[key] = {
2048
2057
  ['x-schema-refs']: {
2049
2058
  [newIuid]: {
2050
- ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
2059
+ $ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
2051
2060
  },
2052
2061
  },
2053
2062
  properties: {},
@@ -2405,6 +2414,10 @@ class SwaggerToApipost {
2405
2414
  const swaggerApi = pathItem[method];
2406
2415
  if (Object.prototype.toString.call(swaggerApi) !== "[object Object]")
2407
2416
  return;
2417
+ // 先过滤其他协议
2418
+ if (lodash.has(swaggerApi, "x-protocol") && swaggerApi['x-protocol'] !== 'http') {
2419
+ return;
2420
+ }
2408
2421
  if (lodash.has(swaggerApi, "tags") && swaggerApi.tags.length > 0) {
2409
2422
  this.handleTags(lodash.uniq(swaggerApi.tags), tags);
2410
2423
  }
@@ -2594,7 +2607,7 @@ class SwaggerToApipost {
2594
2607
  const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
2595
2608
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
2596
2609
  ? JSON.stringify(Raw)
2597
- : Raw;
2610
+ : String(Raw);
2598
2611
  const Raw_text = this.getBeautifulRaw(originRaw);
2599
2612
  let jsonSchema = {};
2600
2613
  if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
@@ -2686,7 +2699,7 @@ class SwaggerToApipost {
2686
2699
  originRaw = JSON.stringify(Object.assign({}, example));
2687
2700
  }
2688
2701
  else {
2689
- originRaw = example;
2702
+ originRaw = String(example);
2690
2703
  }
2691
2704
  }
2692
2705
  catch (error) {
@@ -2747,7 +2760,7 @@ class SwaggerToApipost {
2747
2760
  const Raw = handleBodyJsonSchema(bodyData.schema, raw_parameter);
2748
2761
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
2749
2762
  ? JSON.stringify(Raw)
2750
- : Raw;
2763
+ : String(Raw);
2751
2764
  const Raw_text = this.getBeautifulRaw(originRaw);
2752
2765
  if (status == 200 || status == 404) {
2753
2766
  response.example.push({
@@ -3078,7 +3091,7 @@ class SwaggerToApipost {
3078
3091
  const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
3079
3092
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
3080
3093
  ? JSON.stringify(Raw)
3081
- : Raw;
3094
+ : String(Raw);
3082
3095
  const Raw_text = this.getBeautifulRaw(originRaw);
3083
3096
  let jsonSchema = {};
3084
3097
  if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
@@ -3148,7 +3161,7 @@ class SwaggerToApipost {
3148
3161
  const Raw = handleBodyJsonSchema(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema, raw_parameter);
3149
3162
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
3150
3163
  ? JSON.stringify(Raw)
3151
- : Raw;
3164
+ : String(Raw);
3152
3165
  const Raw_text = this.getBeautifulRaw(originRaw);
3153
3166
  let jsonSchema = {};
3154
3167
  if (Object.prototype.toString.call((_c = bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema) === null || _c === void 0 ? void 0 : _c["$$ref"]) ===
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.65",
3
+ "version": "0.0.67",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [