echoapi-converter 0.0.64 → 0.0.66

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 +44 -39
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1125,11 +1125,7 @@ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
1125
1125
  if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
1126
1126
  item.key.length > 0 &&
1127
1127
  (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
1128
- lastData[item.key] = {
1129
- type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string',
1130
- description: (item === null || item === void 0 ? void 0 : item.description) || "",
1131
- example: (item === null || item === void 0 ? void 0 : item.value) || "",
1132
- };
1128
+ lastData[item.key] = Object.assign({ type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string', description: (item === null || item === void 0 ? void 0 : item.description) || "", example: (item === null || item === void 0 ? void 0 : item.value) || "" }, (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.schema) ? item.schema : {}));
1133
1129
  }
1134
1130
  return lastData;
1135
1131
  }, {})
@@ -1143,8 +1139,17 @@ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
1143
1139
  (pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
1144
1140
  }
1145
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
+ };
1146
1151
  const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, target_type) => {
1147
- 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;
1148
1153
  const path = recursiveFolderPath("", sourceObj, pid, pidName);
1149
1154
  const pathItem = {
1150
1155
  'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || '',
@@ -1163,7 +1168,7 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1163
1168
  pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.updated_at;
1164
1169
  }
1165
1170
  if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
1166
- 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);
1167
1172
  }
1168
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)) {
1169
1174
  pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
@@ -1173,16 +1178,16 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1173
1178
  }
1174
1179
  if (['http', 'sse'].includes(target_type)) {
1175
1180
  // 处理 Query 和 Header 参数
1176
- 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);
1177
- 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);
1178
- 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);
1179
- 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);
1180
1185
  // 处理请求体参数(根据 Swagger 版本)
1181
1186
  if (apiVersion === "2.0") {
1182
- 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);
1183
1188
  }
1184
1189
  else {
1185
- 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);
1186
1191
  }
1187
1192
  // 添加路径标签
1188
1193
  if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
@@ -1197,35 +1202,35 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
1197
1202
  switch (target_type) {
1198
1203
  case 'socketio':
1199
1204
  pathItem.description = `${pathItem.description}
1200
- ${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.shake_hands_path) ? t('securityConnectionMessage', {
1201
- 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'),
1202
- version: ((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.socket_version) || 'v4',
1203
- 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
1204
1209
  }) : t('securityConnectionMessageNoPath', {
1205
- 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'),
1206
- 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',
1207
1212
  })}
1208
1213
  `;
1209
1214
  break;
1210
1215
  case 'websocket2':
1211
1216
  pathItem.description = `${pathItem.description}
1212
1217
  ${t('wsConfigMessage', {
1213
- 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'),
1214
- 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`
1215
1220
  })}
1216
1221
  `;
1217
1222
  break;
1218
1223
  }
1219
1224
  }
1220
- 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);
1221
- 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);
1222
- 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);
1223
- 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);
1224
1229
  if (target_type == 'socketio')
1225
- 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);
1226
1231
  // 处理请体
1227
1232
  if (target_type == 'graphql') {
1228
- 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);
1229
1234
  }
1230
1235
  else {
1231
1236
  handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
@@ -1237,23 +1242,23 @@ ${t('wsConfigMessage', {
1237
1242
  }
1238
1243
  else if (target_type == 'socket_method') {
1239
1244
  // 拼接description
1240
- 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;
1241
1246
  if (lodash.isPlainObject(configs)) {
1242
- 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 ?
1243
- `\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) => {
1244
1249
  let str = getTcpMethodFucString(r);
1245
1250
  return str;
1246
1251
  })}`
1247
1252
  : ''}`;
1248
- 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 ?
1249
- `${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) => {
1250
1255
  let str = getTcpMethodFucString(r);
1251
1256
  return str;
1252
1257
  })}`
1253
1258
  : '';
1254
1259
  pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
1255
1260
  }
1256
- 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);
1257
1262
  // 处理响应
1258
1263
  pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
1259
1264
  // 添加路径标签
@@ -2051,7 +2056,7 @@ const replaceRef = (schemaObj) => {
2051
2056
  schemaObj[key] = {
2052
2057
  ['x-schema-refs']: {
2053
2058
  [newIuid]: {
2054
- 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'])
2055
2060
  },
2056
2061
  },
2057
2062
  properties: {},
@@ -2598,7 +2603,7 @@ class SwaggerToApipost {
2598
2603
  const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
2599
2604
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
2600
2605
  ? JSON.stringify(Raw)
2601
- : Raw;
2606
+ : String(Raw);
2602
2607
  const Raw_text = this.getBeautifulRaw(originRaw);
2603
2608
  let jsonSchema = {};
2604
2609
  if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
@@ -2690,7 +2695,7 @@ class SwaggerToApipost {
2690
2695
  originRaw = JSON.stringify(Object.assign({}, example));
2691
2696
  }
2692
2697
  else {
2693
- originRaw = example;
2698
+ originRaw = String(example);
2694
2699
  }
2695
2700
  }
2696
2701
  catch (error) {
@@ -2751,7 +2756,7 @@ class SwaggerToApipost {
2751
2756
  const Raw = handleBodyJsonSchema(bodyData.schema, raw_parameter);
2752
2757
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
2753
2758
  ? JSON.stringify(Raw)
2754
- : Raw;
2759
+ : String(Raw);
2755
2760
  const Raw_text = this.getBeautifulRaw(originRaw);
2756
2761
  if (status == 200 || status == 404) {
2757
2762
  response.example.push({
@@ -3082,7 +3087,7 @@ class SwaggerToApipost {
3082
3087
  const Raw = handleBodyJsonSchema(element.schema, raw_parameter);
3083
3088
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
3084
3089
  ? JSON.stringify(Raw)
3085
- : Raw;
3090
+ : String(Raw);
3086
3091
  const Raw_text = this.getBeautifulRaw(originRaw);
3087
3092
  let jsonSchema = {};
3088
3093
  if (Object.prototype.toString.call((_b = element === null || element === void 0 ? void 0 : element.schema) === null || _b === void 0 ? void 0 : _b["$$ref"]) ===
@@ -3152,7 +3157,7 @@ class SwaggerToApipost {
3152
3157
  const Raw = handleBodyJsonSchema(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema, raw_parameter);
3153
3158
  const originRaw = lodash.isPlainObject(Raw) || Array.isArray(Raw)
3154
3159
  ? JSON.stringify(Raw)
3155
- : Raw;
3160
+ : String(Raw);
3156
3161
  const Raw_text = this.getBeautifulRaw(originRaw);
3157
3162
  let jsonSchema = {};
3158
3163
  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.64",
3
+ "version": "0.0.66",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [