echoapi-converter 0.0.59 → 0.0.60
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.js +55 -34
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var urlParse = require('url-parse');
|
|
|
9
9
|
var MockSchema = require('apipost-mock-schema');
|
|
10
10
|
var axios = require('axios');
|
|
11
11
|
var SwaggerClient = require('swagger-client');
|
|
12
|
+
var toJsonSchemasecond = require('to-json-schema');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
@@ -17,6 +18,7 @@ var urlParse__default = /*#__PURE__*/_interopDefaultLegacy(urlParse);
|
|
|
17
18
|
var MockSchema__default = /*#__PURE__*/_interopDefaultLegacy(MockSchema);
|
|
18
19
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
19
20
|
var SwaggerClient__default = /*#__PURE__*/_interopDefaultLegacy(SwaggerClient);
|
|
21
|
+
var toJsonSchemasecond__default = /*#__PURE__*/_interopDefaultLegacy(toJsonSchemasecond);
|
|
20
22
|
|
|
21
23
|
/******************************************************************************
|
|
22
24
|
Copyright (c) Microsoft Corporation.
|
|
@@ -697,8 +699,8 @@ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
|
697
699
|
try {
|
|
698
700
|
let deepCount = lodash.cloneDeep(count);
|
|
699
701
|
const schema = lodash.cloneDeep(originSchema);
|
|
700
|
-
if (lodash.has(schema, '
|
|
701
|
-
const refsValue = schema === null || schema === void 0 ? void 0 : schema
|
|
702
|
+
if (lodash.has(schema, 'x-schema-refs')) {
|
|
703
|
+
const refsValue = schema === null || schema === void 0 ? void 0 : schema['x-schema-refs'];
|
|
702
704
|
if (!lodash.isEmpty(refsValue) &&
|
|
703
705
|
Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
|
|
704
706
|
const properties = Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]'
|
|
@@ -706,17 +708,22 @@ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
|
706
708
|
: {};
|
|
707
709
|
schema['properties'] = (_a = lodash.values(refsValue)) === null || _a === void 0 ? void 0 : _a.reduce((pre, item) => {
|
|
708
710
|
var _a, _b;
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
711
|
+
let refId = '';
|
|
712
|
+
let refPath = item === null || item === void 0 ? void 0 : item.$ref;
|
|
713
|
+
if (lodash.isString(refPath)) {
|
|
714
|
+
refId = refPath.split('/').pop() || '';
|
|
715
|
+
}
|
|
716
|
+
if (refId &&
|
|
717
|
+
lodash.has(schemaMap, refId) &&
|
|
718
|
+
!lodash.isEqual(startSchema || originSchema, (_a = schemaMap[refId]) === null || _a === void 0 ? void 0 : _a.schema)) {
|
|
719
|
+
const mapValue = schemaMap[refId];
|
|
713
720
|
if (mapValue && (mapValue === null || mapValue === void 0 ? void 0 : mapValue.name)) {
|
|
714
721
|
// 暂时没找到多ref引用的方案 先直接导出数据
|
|
715
722
|
// pre[mapValue?.name] = {
|
|
716
723
|
// $ref: mapValue?.path,
|
|
717
724
|
// };
|
|
718
725
|
let mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
719
|
-
if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, '
|
|
726
|
+
if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, 'x-schema-refs')) {
|
|
720
727
|
if (deepCount > MAX_DEEP_COUNT) {
|
|
721
728
|
mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
|
|
722
729
|
}
|
|
@@ -726,7 +733,7 @@ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
|
726
733
|
}
|
|
727
734
|
pre = Object.assign(Object.assign({}, pre), ((mapSchema === null || mapSchema === void 0 ? void 0 : mapSchema.properties) || {}));
|
|
728
735
|
}
|
|
729
|
-
if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[
|
|
736
|
+
if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[refId]) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
730
737
|
pre = {};
|
|
731
738
|
}
|
|
732
739
|
}
|
|
@@ -739,10 +746,10 @@ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
|
739
746
|
let properties_keys = lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties);
|
|
740
747
|
if (
|
|
741
748
|
// 优化展示顺序
|
|
742
|
-
(schema === null || schema === void 0 ? void 0 : schema
|
|
743
|
-
lodash.isArray(schema === null || schema === void 0 ? void 0 : schema
|
|
744
|
-
lodash.isEqual(lodash.sortBy(schema === null || schema === void 0 ? void 0 : schema
|
|
745
|
-
properties_keys = schema === null || schema === void 0 ? void 0 : schema
|
|
749
|
+
(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']) &&
|
|
750
|
+
lodash.isArray(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']) &&
|
|
751
|
+
lodash.isEqual(lodash.sortBy(schema === null || schema === void 0 ? void 0 : schema['x-schema-orders']), lodash.sortBy(lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties)))) {
|
|
752
|
+
properties_keys = schema === null || schema === void 0 ? void 0 : schema['x-schema-orders'];
|
|
746
753
|
}
|
|
747
754
|
schema['properties'] = properties_keys === null || properties_keys === void 0 ? void 0 : properties_keys.reduce((pre, key) => {
|
|
748
755
|
if (key && !lodash.isEmpty(schema === null || schema === void 0 ? void 0 : schema.properties[key])) {
|
|
@@ -765,8 +772,8 @@ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
|
|
|
765
772
|
}
|
|
766
773
|
}
|
|
767
774
|
// 处理数组的引用
|
|
768
|
-
schema === null || schema === void 0 ? true : delete schema
|
|
769
|
-
schema === null || schema === void 0 ? true : delete schema
|
|
775
|
+
schema === null || schema === void 0 ? true : delete schema['x-schema-orders'];
|
|
776
|
+
schema === null || schema === void 0 ? true : delete schema['x-schema-refs'];
|
|
770
777
|
return schema;
|
|
771
778
|
}
|
|
772
779
|
catch (err) {
|
|
@@ -2037,15 +2044,14 @@ const replaceRef = (schemaObj) => {
|
|
|
2037
2044
|
}
|
|
2038
2045
|
}
|
|
2039
2046
|
schemaObj[key] = {
|
|
2040
|
-
|
|
2047
|
+
['x-schema-refs']: {
|
|
2041
2048
|
[newIuid]: {
|
|
2042
2049
|
ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$$ref'])
|
|
2043
2050
|
},
|
|
2044
2051
|
},
|
|
2045
2052
|
properties: {},
|
|
2046
|
-
|
|
2047
|
-
type: "object"
|
|
2048
|
-
ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$$ref'])
|
|
2053
|
+
['x-schema-orders']: [newIuid],
|
|
2054
|
+
type: "object"
|
|
2049
2055
|
};
|
|
2050
2056
|
continue;
|
|
2051
2057
|
}
|
|
@@ -2061,16 +2067,14 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
|
|
|
2061
2067
|
try {
|
|
2062
2068
|
// x-apifox-orders 2 ECHOAPI_ORDERS x-apifox-refs 2 ECHOAPI_REFS $ref 2 ref x-apifox-overrides 2 ECHOAPI_OVERRIDES
|
|
2063
2069
|
let jsonSchemaStr = JSON.stringify(schemaObj);
|
|
2064
|
-
// 替换 x-apifox-orders 为
|
|
2065
|
-
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-orders\"/g, '\"
|
|
2066
|
-
// 替换 x-apifox-refs 为
|
|
2067
|
-
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-refs\"/g, '\"
|
|
2068
|
-
// 替换 $ref 为 ref
|
|
2069
|
-
jsonSchemaStr = jsonSchemaStr.replace(/\"\$ref\"/g, '\"ref\"');
|
|
2070
|
+
// 替换 x-apifox-orders 为 APIPOST_ORDERS
|
|
2071
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-orders\"/g, '\"x-schema-orders\"');
|
|
2072
|
+
// 替换 x-apifox-refs 为 APIPOST_REFS
|
|
2073
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-refs\"/g, '\"x-schema-refs\"');
|
|
2070
2074
|
// 替换 $ref 为 ref
|
|
2071
|
-
jsonSchemaStr = jsonSchemaStr.replace(/\"\$\$ref\"/g, '\"ref\"');
|
|
2072
|
-
// 替换 x-apifox-overrides 为
|
|
2073
|
-
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-overrides\"/g, '\"
|
|
2075
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"\$\$ref\"/g, '\"\$ref\"');
|
|
2076
|
+
// 替换 x-apifox-overrides 为 APIPOST_OVERRIDES
|
|
2077
|
+
jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-overrides\"/g, '\"x-schema-overrides\"');
|
|
2074
2078
|
// 还原为对象
|
|
2075
2079
|
jsonSchema = JSON.parse(jsonSchemaStr);
|
|
2076
2080
|
if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$$ref')) {
|
|
@@ -2083,13 +2087,13 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
|
|
|
2083
2087
|
}
|
|
2084
2088
|
}
|
|
2085
2089
|
jsonSchema = {
|
|
2086
|
-
|
|
2090
|
+
['x-schema-refs']: {
|
|
2087
2091
|
[newIuid]: {
|
|
2088
|
-
ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$$ref'])
|
|
2092
|
+
$ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$$ref'])
|
|
2089
2093
|
},
|
|
2090
2094
|
},
|
|
2091
2095
|
properties: {},
|
|
2092
|
-
|
|
2096
|
+
['x-schema-orders']: [newIuid],
|
|
2093
2097
|
type: "object",
|
|
2094
2098
|
};
|
|
2095
2099
|
}
|
|
@@ -2108,6 +2112,7 @@ const createNewModelData2 = (item, model_name) => {
|
|
|
2108
2112
|
model_id: `#/definitions/${model_name}`,
|
|
2109
2113
|
name: model_name || 'New Schema',
|
|
2110
2114
|
displayName: model_name || '',
|
|
2115
|
+
display_name: model_name || '',
|
|
2111
2116
|
model_type: 'model',
|
|
2112
2117
|
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
2113
2118
|
schema: {},
|
|
@@ -2133,6 +2138,7 @@ const createNewModelData = (item, key, folder_name) => {
|
|
|
2133
2138
|
model_id: `#/components/${folder_name}/${key}`,
|
|
2134
2139
|
name: (item === null || item === void 0 ? void 0 : item.title) || key || 'New Schema',
|
|
2135
2140
|
displayName: (item === null || item === void 0 ? void 0 : item.title) || '',
|
|
2141
|
+
display_name: (item === null || item === void 0 ? void 0 : item.title) || '',
|
|
2136
2142
|
model_type: 'model',
|
|
2137
2143
|
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
2138
2144
|
schema: {},
|
|
@@ -3701,11 +3707,11 @@ class ApifoxToApipost {
|
|
|
3701
3707
|
if (key === "x-apifox-refs" && lodash.keys(schema[key])) {
|
|
3702
3708
|
(_a = lodash.keys(schema[key])) === null || _a === void 0 ? void 0 : _a.map((e) => {
|
|
3703
3709
|
if (lodash.has(schema[key][e], "$ref")) {
|
|
3704
|
-
schema[key][e]["ref"] = modelsMap === null || modelsMap === void 0 ? void 0 : modelsMap[schema[key][e]["$ref"]];
|
|
3705
|
-
delete schema[key][e]["$ref"];
|
|
3710
|
+
schema[key][e]["$ref"] = modelsMap === null || modelsMap === void 0 ? void 0 : modelsMap[schema[key][e]["$ref"]];
|
|
3711
|
+
// delete schema[key][e]["$ref"];
|
|
3706
3712
|
}
|
|
3707
3713
|
});
|
|
3708
|
-
schema["
|
|
3714
|
+
schema["x-schema-refs"] = schema[key];
|
|
3709
3715
|
delete schema[key];
|
|
3710
3716
|
}
|
|
3711
3717
|
if (key === "properties" &&
|
|
@@ -3720,7 +3726,7 @@ class ApifoxToApipost {
|
|
|
3720
3726
|
schema[key] = this.recursionSchema(schema[key], modelsMap);
|
|
3721
3727
|
}
|
|
3722
3728
|
if (key === "x-apifox-orders") {
|
|
3723
|
-
schema["
|
|
3729
|
+
schema["x-schema-orders"] = schema[key];
|
|
3724
3730
|
delete schema[key];
|
|
3725
3731
|
}
|
|
3726
3732
|
}
|
|
@@ -6590,6 +6596,9 @@ class PostmanToApipost {
|
|
|
6590
6596
|
break;
|
|
6591
6597
|
}
|
|
6592
6598
|
params["raw"] = lodash.isString(body === null || body === void 0 ? void 0 : body.raw) ? getBeautifulRaw(body === null || body === void 0 ? void 0 : body.raw) : "";
|
|
6599
|
+
if (apipostTools.isJson(params["raw"])) {
|
|
6600
|
+
params.raw_schema = toJsonSchemasecond__default["default"](JSON.parse(params["raw"]));
|
|
6601
|
+
}
|
|
6593
6602
|
}
|
|
6594
6603
|
}
|
|
6595
6604
|
return Object.assign({ mode: "none", parameter: [], raw: "", raw_parameter: [], raw_schema: {
|
|
@@ -7017,6 +7026,12 @@ class YapiToApipost {
|
|
|
7017
7026
|
else if ((item === null || item === void 0 ? void 0 : item.req_body_type) === "raw") {
|
|
7018
7027
|
body["mode"] = "json";
|
|
7019
7028
|
body["raw"] = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.req_body_other) || "");
|
|
7029
|
+
if (apipostTools.isJson(body["raw"])) {
|
|
7030
|
+
try {
|
|
7031
|
+
body["raw_schema"] = toJsonSchemasecond__default["default"](JSON.parse(body["raw"]));
|
|
7032
|
+
}
|
|
7033
|
+
catch (error) { }
|
|
7034
|
+
}
|
|
7020
7035
|
}
|
|
7021
7036
|
}
|
|
7022
7037
|
return {
|
|
@@ -7050,6 +7065,12 @@ class YapiToApipost {
|
|
|
7050
7065
|
if (lodash.has(item, "res_body_type")) {
|
|
7051
7066
|
if ((item === null || item === void 0 ? void 0 : item.res_body_type) === "raw") {
|
|
7052
7067
|
raw = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.res_body) || "");
|
|
7068
|
+
if (apipostTools.isJson(raw)) {
|
|
7069
|
+
try {
|
|
7070
|
+
schema = toJsonSchemasecond__default["default"](JSON.parse(raw));
|
|
7071
|
+
}
|
|
7072
|
+
catch (error) { }
|
|
7073
|
+
}
|
|
7053
7074
|
}
|
|
7054
7075
|
else if ((item === null || item === void 0 ? void 0 : item.res_body_type) === "json") {
|
|
7055
7076
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "echoapi-converter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.60",
|
|
4
4
|
"description": "echoapi to swagger",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"ts-jest": "^29.2.5"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
34
35
|
"@types/lodash": "^4.14.202",
|
|
35
36
|
"apipost-mock-schema": "^0.0.37",
|
|
36
37
|
"apipost-tools": "0.0.34",
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"lodash": "^4.17.21",
|
|
42
43
|
"path": "^0.12.7",
|
|
43
44
|
"swagger-client": "3.18.5",
|
|
45
|
+
"to-json-schema": "^0.2.5",
|
|
44
46
|
"ts-jest": "^29.2.5",
|
|
45
47
|
"tsc": "^2.0.4",
|
|
46
48
|
"typescript": "^5.3.3",
|