echoapi-converter 0.0.7 → 0.0.9

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.
package/dist/index.d.ts CHANGED
@@ -185,6 +185,7 @@ declare class InsomniaToApipost {
185
185
  private completionWsRequest;
186
186
  private completionWsTarget;
187
187
  private completionApiTarget;
188
+ private getEnvVarList;
188
189
  private completionApis;
189
190
  private initApis;
190
191
  private initFolders;
package/dist/index.js CHANGED
@@ -634,6 +634,28 @@ const yapiGenRestfulByUrl = (url, oldParameter) => {
634
634
  catch (error) { }
635
635
  return restfulList;
636
636
  };
637
+ const fixUrlPath = (url) => {
638
+ try {
639
+ const index = url.indexOf('://');
640
+ let path;
641
+ let protocolAndDomain = '';
642
+ if (index === -1) {
643
+ path = url;
644
+ }
645
+ else {
646
+ // 分开协议和路径部分
647
+ protocolAndDomain = url.slice(0, index + 3);
648
+ path = url.slice(index + 3);
649
+ }
650
+ // 修正路径中的 '//'
651
+ const fixedPath = path.replace(/\/\/+/g, '/');
652
+ // 拼接返回
653
+ return `${protocolAndDomain}${fixedPath}`;
654
+ }
655
+ catch (err) {
656
+ return url;
657
+ }
658
+ };
637
659
 
638
660
  class ApipostToSwagger {
639
661
  constructor() {
@@ -1677,15 +1699,20 @@ class SwaggerToApipost {
1677
1699
  else if (lodash.isPlainObject(bodyData === null || bodyData === void 0 ? void 0 : bodyData.schema)) {
1678
1700
  jsonSchema = bodyData.schema;
1679
1701
  }
1680
- if (lodash.has(bodyData, 'example') && Object.prototype.toString.call(bodyData === null || bodyData === void 0 ? void 0 : bodyData.example) === '[object Object]') {
1702
+ if (lodash.has(bodyData, 'example')) {
1681
1703
  const example = bodyData.example;
1682
1704
  if (status == 200 || status == 404) {
1683
1705
  let originRaw;
1684
1706
  try {
1685
- originRaw = JSON.stringify(Object.assign({}, example));
1707
+ if (Object.prototype.toString.call(example) === '[object Object]') {
1708
+ originRaw = JSON.stringify(Object.assign({}, example));
1709
+ }
1710
+ else {
1711
+ originRaw = example;
1712
+ }
1686
1713
  }
1687
1714
  catch (error) {
1688
- originRaw = String(Object.assign({}, example));
1715
+ originRaw = String(example);
1689
1716
  }
1690
1717
  const Raw_text = this.getBeautifulRaw(originRaw);
1691
1718
  response.example.push({
@@ -1708,10 +1735,15 @@ class SwaggerToApipost {
1708
1735
  const newUUID = ATools.snowflakeId();
1709
1736
  let originRaw;
1710
1737
  try {
1711
- originRaw = JSON.stringify(Object.assign({}, example));
1738
+ if (Object.prototype.toString.call(example) === '[object Object]') {
1739
+ originRaw = JSON.stringify(Object.assign({}, example));
1740
+ }
1741
+ else {
1742
+ originRaw = example;
1743
+ }
1712
1744
  }
1713
1745
  catch (error) {
1714
- originRaw = String(Object.assign({}, example));
1746
+ originRaw = String(example);
1715
1747
  }
1716
1748
  const Raw_text = this.getBeautifulRaw(originRaw);
1717
1749
  response.example.push({
@@ -1844,6 +1876,7 @@ class SwaggerToApipost {
1844
1876
  return __awaiter(this, void 0, void 0, function* () {
1845
1877
  let url = path;
1846
1878
  url = decodeURI(this.basePath + url);
1879
+ url = fixUrlPath(url);
1847
1880
  for (const method in pathItem) {
1848
1881
  const swaggerApi = pathItem[method];
1849
1882
  if (Object.prototype.toString.call(swaggerApi) !== '[object Object]')
@@ -4144,6 +4177,21 @@ class InsomniaToApipost {
4144
4177
  is_force: -1,
4145
4178
  };
4146
4179
  }
4180
+ getEnvVarList(data) {
4181
+ if (lodash.isObject(data) && lodash.keys(data).length) {
4182
+ return lodash.keys(data).reduce((pre, key) => {
4183
+ pre[key] = {
4184
+ current_value: lodash.isNil(data === null || data === void 0 ? void 0 : data[key]) ? '' : data === null || data === void 0 ? void 0 : data[key],
4185
+ description: '',
4186
+ key,
4187
+ value: lodash.isNil(data === null || data === void 0 ? void 0 : data[key]) ? '' : data === null || data === void 0 ? void 0 : data[key],
4188
+ };
4189
+ return pre;
4190
+ }, {});
4191
+ }
4192
+ return {};
4193
+ }
4194
+ ;
4147
4195
  completionApis(resources) {
4148
4196
  return resources === null || resources === void 0 ? void 0 : resources.reduce((pre, item) => {
4149
4197
  if ((item === null || item === void 0 ? void 0 : item._type) === 'request_group' && lodash.has(this.foldersMap, item === null || item === void 0 ? void 0 : item._id)) {
@@ -4176,9 +4224,9 @@ class InsomniaToApipost {
4176
4224
  {
4177
4225
  env_id: ATools.snowflakeId(),
4178
4226
  name: item === null || item === void 0 ? void 0 : item.name,
4179
- is_private: -1,
4227
+ is_private: (item === null || item === void 0 ? void 0 : item.isPrivate) ? 1 : -1,
4180
4228
  server_list: [],
4181
- env_var_list: {},
4229
+ env_var_list: this.getEnvVarList(item === null || item === void 0 ? void 0 : item.data),
4182
4230
  },
4183
4231
  ]);
4184
4232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [