echoapi-converter 0.0.79 → 0.0.80

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 +31 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -67,6 +67,15 @@ const DEFAULT_FIELD_TYPE$2 = [
67
67
  "undefined",
68
68
  "null",
69
69
  ];
70
+ const OLD_FIELD_TYPES$1 = {
71
+ 'function': { type: 'string', format: 'function-expression' },
72
+ 'nan': { type: 'string', format: 'nan' },
73
+ 'float': { type: 'number', format: 'float' },
74
+ 'regexp': { type: 'string', format: 'regex' },
75
+ 'undefined': { type: 'null' },
76
+ 'date': { type: 'string', format: 'date-time' },
77
+ 'file': { type: 'string', format: 'binary' },
78
+ };
70
79
  const MODE_TYPE = {
71
80
  "form-data": "multipart/form-data",
72
81
  urlencoded: "application/x-www-form-urlencoded",
@@ -922,7 +931,7 @@ const completionParameter = (parameter) => {
922
931
  if (lodash.isArray(parameter)) {
923
932
  return parameter.map((p) => {
924
933
  var _a, _b;
925
- return {
934
+ const param = {
926
935
  is_checked: 1, // 是否选择
927
936
  key: (p === null || p === void 0 ? void 0 : p.name) || "", //参数名
928
937
  value: transExample(p === null || p === void 0 ? void 0 : p.example) ||
@@ -935,6 +944,15 @@ const completionParameter = (parameter) => {
935
944
  param_id: apipostTools.snowflakeId(),
936
945
  schema: (p === null || p === void 0 ? void 0 : p.schema) || {}
937
946
  };
947
+ const oldFiledObj = OLD_FIELD_TYPES$1 === null || OLD_FIELD_TYPES$1 === void 0 ? void 0 : OLD_FIELD_TYPES$1[lodash.toLower(param.field_type)];
948
+ if (oldFiledObj) {
949
+ param.field_type = oldFiledObj.type;
950
+ param.schema.type = oldFiledObj.type;
951
+ if (oldFiledObj === null || oldFiledObj === void 0 ? void 0 : oldFiledObj.format) {
952
+ param.schema.format = oldFiledObj === null || oldFiledObj === void 0 ? void 0 : oldFiledObj.format;
953
+ }
954
+ }
955
+ return param;
938
956
  });
939
957
  }
940
958
  return [];
@@ -2001,7 +2019,7 @@ const formatTags = (tag = "") => {
2001
2019
  return tag.split("/") || [];
2002
2020
  };
2003
2021
  const handlePathItemParameters = (type, arr, pathItem) => {
2004
- var _a;
2022
+ var _a, _b;
2005
2023
  if (lodash.isArray(arr) && arr.length > 0) {
2006
2024
  if (!lodash.has(pathItem, "parameters")) {
2007
2025
  pathItem.parameters = [];
@@ -2010,14 +2028,23 @@ const handlePathItemParameters = (type, arr, pathItem) => {
2010
2028
  if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
2011
2029
  item.key.length > 0 &&
2012
2030
  (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
2013
- pathItem.parameters.push({
2031
+ const param = {
2014
2032
  name: item.key,
2015
2033
  in: type,
2016
2034
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
2017
2035
  required: (item === null || item === void 0 ? void 0 : item.not_null) === 1,
2018
2036
  example: String((item === null || item === void 0 ? void 0 : item.value) || ""),
2019
2037
  schema: Object.assign({ type: (_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase() }, ((item === null || item === void 0 ? void 0 : item.schema) || {})),
2020
- });
2038
+ };
2039
+ const oldFiledObj = OLD_FIELD_TYPES === null || OLD_FIELD_TYPES === void 0 ? void 0 : OLD_FIELD_TYPES[((_b = param === null || param === void 0 ? void 0 : param.schema) === null || _b === void 0 ? void 0 : _b.type) || ''];
2040
+ if (oldFiledObj) {
2041
+ param.field_type = oldFiledObj.type;
2042
+ param.schema.type = oldFiledObj.type;
2043
+ if (oldFiledObj === null || oldFiledObj === void 0 ? void 0 : oldFiledObj.format) {
2044
+ param.schema.format = oldFiledObj === null || oldFiledObj === void 0 ? void 0 : oldFiledObj.format;
2045
+ }
2046
+ }
2047
+ pathItem.parameters.push(param);
2021
2048
  }
2022
2049
  }
2023
2050
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [