whistle.mock-plugins 1.0.6-beta.9 → 1.1.0
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/app/cgi-bin/interfaces.js +35 -0
- package/app/cgi-bin/test-interface.js +5 -10
- package/app/public/js/index.js +1 -1
- package/app/public/js/index.js.LICENSE.txt +7 -3
- package/lib/routes/interfaces.js +174 -29
- package/package.json +1 -1
- package/ui/src/components/interface-management/InterfaceTestModal.js +313 -0
- package/ui/src/components/interface-management/PreviewModal.js +50 -0
- package/ui/src/components/interface-management/README.md +184 -0
- package/ui/src/components/interface-management/ResponseContentEditor.js +427 -0
- package/ui/src/components/interface-management/constants.js +36 -0
- package/ui/src/components/interface-management/index.js +6 -0
- package/ui/src/components/interface-management/utils.js +103 -0
- package/ui/src/pages/InterfaceManagement.js +253 -836
|
@@ -69,12 +69,16 @@
|
|
|
69
69
|
|
|
70
70
|
/** */
|
|
71
71
|
|
|
72
|
+
/** */
|
|
73
|
+
|
|
72
74
|
/** */
|
|
73
75
|
|
|
74
76
|
/** */
|
|
75
77
|
|
|
76
78
|
/** */
|
|
77
79
|
|
|
80
|
+
/** */
|
|
81
|
+
|
|
78
82
|
/** */
|
|
79
83
|
|
|
80
84
|
/** */
|
|
@@ -103,7 +107,7 @@
|
|
|
103
107
|
|
|
104
108
|
/** */
|
|
105
109
|
|
|
106
|
-
/** */
|
|
107
111
|
|
|
108
112
|
/** */
|
|
109
113
|
|
|
@@ -129,12 +133,12 @@
|
|
|
129
133
|
|
|
130
134
|
/** */
|
|
131
135
|
|
|
132
|
-
/** */
|
|
133
|
-
|
|
134
136
|
/** */
|
|
135
137
|
|
|
136
138
|
/** */
|
|
137
139
|
|
|
140
|
+
/** */
|
|
141
|
+
|
|
138
142
|
/** */
|
|
139
143
|
|
|
140
144
|
/** */
|
package/lib/routes/interfaces.js
CHANGED
|
@@ -19,8 +19,68 @@ fs.ensureDirSync(DATA_DIR);
|
|
|
19
19
|
const processInterfaceData = (data) => {
|
|
20
20
|
const result = { ...data };
|
|
21
21
|
|
|
22
|
-
//
|
|
23
|
-
|
|
22
|
+
// 调试日志
|
|
23
|
+
console.log('=== 开始处理接口数据 ===');
|
|
24
|
+
console.log('原始数据:', JSON.stringify({
|
|
25
|
+
name: result.name,
|
|
26
|
+
hasResponses: !!result.responses,
|
|
27
|
+
responsesType: typeof result.responses,
|
|
28
|
+
responsesLength: result.responses ? result.responses.length : 0,
|
|
29
|
+
responses: result.responses,
|
|
30
|
+
responseContent: !!result.responseContent,
|
|
31
|
+
activeResponseId: result.activeResponseId
|
|
32
|
+
}, null, 2));
|
|
33
|
+
|
|
34
|
+
// 处理 responses 数组
|
|
35
|
+
if (result.responses && Array.isArray(result.responses) && result.responses.length > 0) {
|
|
36
|
+
console.log('发现 responses 数组,直接处理多响应数据');
|
|
37
|
+
|
|
38
|
+
// 确保每个响应都有合法的 id, name 和 content
|
|
39
|
+
result.responses = result.responses.map((resp, index) => {
|
|
40
|
+
console.log(`处理响应 ${index}:`, resp);
|
|
41
|
+
|
|
42
|
+
if (!resp.id) {
|
|
43
|
+
resp.id = Math.random().toString(36).substring(2, 15);
|
|
44
|
+
console.log(`为响应 ${index} 添加 ID:`, resp.id);
|
|
45
|
+
}
|
|
46
|
+
if (!resp.name) {
|
|
47
|
+
resp.name = `响应 ${index + 1}`;
|
|
48
|
+
console.log(`为响应 ${index} 添加默认名称:`, resp.name);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const processedResp = {
|
|
52
|
+
id: resp.id,
|
|
53
|
+
name: resp.name,
|
|
54
|
+
description: resp.description || '',
|
|
55
|
+
content: resp.content || '{}'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
console.log(`处理后的响应 ${index}:`, processedResp);
|
|
59
|
+
return processedResp;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
console.log('处理后的响应数组长度:', result.responses.length);
|
|
63
|
+
console.log('所有处理后的响应:', result.responses);
|
|
64
|
+
|
|
65
|
+
// 如果有响应但没有设置 activeResponseId,默认使用第一个
|
|
66
|
+
if (!result.activeResponseId) {
|
|
67
|
+
result.activeResponseId = result.responses[0].id;
|
|
68
|
+
console.log('设置默认激活响应:', result.activeResponseId);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 确保 responseContent 字段始终存在(向后兼容)
|
|
72
|
+
const activeResponse = result.activeResponseId
|
|
73
|
+
? result.responses.find(r => r.id === result.activeResponseId)
|
|
74
|
+
: result.responses[0];
|
|
75
|
+
|
|
76
|
+
if (activeResponse) {
|
|
77
|
+
result.responseContent = activeResponse.content;
|
|
78
|
+
console.log('设置 responseContent 为当前激活响应内容');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} else if (result.responseContent) {
|
|
82
|
+
// 如果没有提供 responses 但有 responseContent,创建默认响应(向后兼容)
|
|
83
|
+
console.log('创建默认响应,因为没有 responses 数组但有 responseContent');
|
|
24
84
|
result.responses = [{
|
|
25
85
|
id: Math.random().toString(36).substring(2, 15),
|
|
26
86
|
name: '默认响应',
|
|
@@ -28,18 +88,32 @@ const processInterfaceData = (data) => {
|
|
|
28
88
|
content: result.responseContent
|
|
29
89
|
}];
|
|
30
90
|
result.activeResponseId = result.responses[0].id;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
91
|
+
console.log('创建的默认响应:', result.responses[0]);
|
|
92
|
+
|
|
93
|
+
} else {
|
|
94
|
+
// 如果既没有 responses 也没有 responseContent,创建一个空的默认响应
|
|
95
|
+
console.log('创建空的默认响应');
|
|
96
|
+
result.responses = [{
|
|
97
|
+
id: Math.random().toString(36).substring(2, 15),
|
|
98
|
+
name: '默认响应',
|
|
99
|
+
description: '',
|
|
100
|
+
content: '{}'
|
|
101
|
+
}];
|
|
35
102
|
result.activeResponseId = result.responses[0].id;
|
|
103
|
+
result.responseContent = '{}';
|
|
104
|
+
console.log('创建的空默认响应:', result.responses[0]);
|
|
36
105
|
}
|
|
37
106
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
result.
|
|
42
|
-
|
|
107
|
+
// 最终日志
|
|
108
|
+
console.log('=== 处理后的最终接口数据 ===');
|
|
109
|
+
console.log('最终数据:', JSON.stringify({
|
|
110
|
+
name: result.name,
|
|
111
|
+
responsesLength: result.responses.length,
|
|
112
|
+
responses: result.responses,
|
|
113
|
+
activeResponseId: result.activeResponseId,
|
|
114
|
+
hasResponseContent: !!result.responseContent
|
|
115
|
+
}, null, 2));
|
|
116
|
+
console.log('=== 接口数据处理完成 ===\n');
|
|
43
117
|
|
|
44
118
|
return result;
|
|
45
119
|
};
|
|
@@ -54,33 +128,69 @@ const initRouter = () => {
|
|
|
54
128
|
// 获取所有接口
|
|
55
129
|
router.get('/interfaces', (req, res) => {
|
|
56
130
|
try {
|
|
131
|
+
const { featureId } = req.query;
|
|
132
|
+
|
|
57
133
|
// 读取所有功能
|
|
58
134
|
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
59
135
|
if (!fs.existsSync(featuresFile)) {
|
|
60
|
-
return res.json([]);
|
|
136
|
+
return res.json({ code: 0, data: [] });
|
|
61
137
|
}
|
|
62
138
|
|
|
63
139
|
const features = fs.readJsonSync(featuresFile);
|
|
64
140
|
let allInterfaces = [];
|
|
65
141
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const interfacesFile = path.join(DATA_DIR, `interfaces-${
|
|
142
|
+
if (featureId) {
|
|
143
|
+
// 获取特定功能的接口
|
|
144
|
+
const interfacesFile = path.join(DATA_DIR, `interfaces-${featureId}.json`);
|
|
69
145
|
if (fs.existsSync(interfacesFile)) {
|
|
70
146
|
const interfaces = fs.readJsonSync(interfacesFile);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
147
|
+
console.log('=== 获取接口:从文件读取的原始数据 ===');
|
|
148
|
+
console.log(`文件路径: ${interfacesFile}`);
|
|
149
|
+
console.log('原始接口数据:', JSON.stringify(interfaces, null, 2));
|
|
150
|
+
|
|
151
|
+
const processedInterfaces = interfaces.map((item, index) => {
|
|
152
|
+
console.log(`=== 处理接口 ${index}: ${item.name} ===`);
|
|
153
|
+
console.log('处理前的接口数据:', JSON.stringify(item, null, 2));
|
|
154
|
+
|
|
155
|
+
// 确保每个接口都经过数据处理
|
|
156
|
+
const processed = processInterfaceData(item);
|
|
157
|
+
console.log('处理后的接口数据:', JSON.stringify(processed, null, 2));
|
|
158
|
+
|
|
159
|
+
const feature = features.find(f => f.id === featureId);
|
|
160
|
+
const result = {
|
|
161
|
+
...processed,
|
|
162
|
+
featureName: feature ? feature.name : '未知功能'
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
console.log('最终接口数据:', JSON.stringify(result, null, 2));
|
|
166
|
+
return result;
|
|
167
|
+
});
|
|
168
|
+
allInterfaces = processedInterfaces;
|
|
77
169
|
}
|
|
78
|
-
}
|
|
170
|
+
} else {
|
|
171
|
+
// 读取每个功能的接口
|
|
172
|
+
features.forEach(feature => {
|
|
173
|
+
const interfacesFile = path.join(DATA_DIR, `interfaces-${feature.id}.json`);
|
|
174
|
+
if (fs.existsSync(interfacesFile)) {
|
|
175
|
+
const interfaces = fs.readJsonSync(interfacesFile);
|
|
176
|
+
// 确保每个接口都经过数据处理
|
|
177
|
+
const processedInterfaces = interfaces.map(item => {
|
|
178
|
+
const processed = processInterfaceData(item);
|
|
179
|
+
return {
|
|
180
|
+
...processed,
|
|
181
|
+
featureName: feature.name
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
allInterfaces = allInterfaces.concat(processedInterfaces);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
79
188
|
|
|
80
|
-
|
|
189
|
+
console.log(`获取接口列表成功,共 ${allInterfaces.length} 个接口`);
|
|
190
|
+
res.json({ code: 0, data: allInterfaces });
|
|
81
191
|
} catch (err) {
|
|
82
192
|
console.error('获取接口列表失败:', err);
|
|
83
|
-
res.status(500).json({
|
|
193
|
+
res.status(500).json({ code: 1, message: '获取接口列表失败: ' + err.message });
|
|
84
194
|
}
|
|
85
195
|
});
|
|
86
196
|
|
|
@@ -90,7 +200,7 @@ const initRouter = () => {
|
|
|
90
200
|
// 读取所有功能
|
|
91
201
|
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
92
202
|
if (!fs.existsSync(featuresFile)) {
|
|
93
|
-
return res.status(404).json({
|
|
203
|
+
return res.status(404).json({ code: 1, message: '接口不存在' });
|
|
94
204
|
}
|
|
95
205
|
|
|
96
206
|
const features = fs.readJsonSync(featuresFile);
|
|
@@ -103,8 +213,10 @@ const initRouter = () => {
|
|
|
103
213
|
const interfaces = fs.readJsonSync(interfacesFile);
|
|
104
214
|
const found = interfaces.find(item => item.id === req.params.id);
|
|
105
215
|
if (found) {
|
|
216
|
+
// 确保数据经过处理
|
|
217
|
+
const processed = processInterfaceData(found);
|
|
106
218
|
foundInterface = {
|
|
107
|
-
...
|
|
219
|
+
...processed,
|
|
108
220
|
featureName: feature.name
|
|
109
221
|
};
|
|
110
222
|
break;
|
|
@@ -113,13 +225,14 @@ const initRouter = () => {
|
|
|
113
225
|
}
|
|
114
226
|
|
|
115
227
|
if (!foundInterface) {
|
|
116
|
-
return res.status(404).json({
|
|
228
|
+
return res.status(404).json({ code: 1, message: '接口不存在' });
|
|
117
229
|
}
|
|
118
230
|
|
|
119
|
-
|
|
231
|
+
console.log(`获取接口详情成功: ${foundInterface.name},响应数量: ${foundInterface.responses ? foundInterface.responses.length : 0}`);
|
|
232
|
+
res.json({ code: 0, data: foundInterface });
|
|
120
233
|
} catch (err) {
|
|
121
234
|
console.error('获取接口详情失败:', err);
|
|
122
|
-
res.status(500).json({
|
|
235
|
+
res.status(500).json({ code: 1, message: '获取接口详情失败: ' + err.message });
|
|
123
236
|
}
|
|
124
237
|
});
|
|
125
238
|
|
|
@@ -160,7 +273,10 @@ const initRouter = () => {
|
|
|
160
273
|
: [];
|
|
161
274
|
|
|
162
275
|
// 处理接口数据,确保兼容多响应格式
|
|
276
|
+
console.log('=== 创建接口:开始处理数据 ===');
|
|
277
|
+
console.log('接收到的接口数据:', JSON.stringify(interfaceData, null, 2));
|
|
163
278
|
const processedData = processInterfaceData(interfaceData);
|
|
279
|
+
console.log('处理后的接口数据:', JSON.stringify(processedData, null, 2));
|
|
164
280
|
|
|
165
281
|
// 创建新接口
|
|
166
282
|
const newInterface = {
|
|
@@ -170,10 +286,20 @@ const initRouter = () => {
|
|
|
170
286
|
updatedAt: new Date().toISOString()
|
|
171
287
|
};
|
|
172
288
|
|
|
289
|
+
console.log('=== 创建接口:准备保存的完整接口数据 ===');
|
|
290
|
+
console.log('完整的新接口数据:', JSON.stringify(newInterface, null, 2));
|
|
291
|
+
|
|
173
292
|
interfaces.push(newInterface);
|
|
174
293
|
|
|
175
294
|
// 保存接口列表
|
|
176
295
|
fs.writeJsonSync(interfacesFile, interfaces, { spaces: 2 });
|
|
296
|
+
console.log('接口数据已保存到文件:', interfacesFile);
|
|
297
|
+
|
|
298
|
+
// 验证保存后从文件读取的数据
|
|
299
|
+
const savedInterfaces = fs.readJsonSync(interfacesFile);
|
|
300
|
+
const savedInterface = savedInterfaces.find(item => item.id === newInterface.id);
|
|
301
|
+
console.log('=== 创建接口:验证保存后的数据 ===');
|
|
302
|
+
console.log('从文件读取的保存后数据:', JSON.stringify(savedInterface, null, 2));
|
|
177
303
|
|
|
178
304
|
// 更新功能模块的接口数量
|
|
179
305
|
const featureIndex = features.findIndex(f => f.id === interfaceData.featureId);
|
|
@@ -181,6 +307,9 @@ const initRouter = () => {
|
|
|
181
307
|
features[featureIndex].updatedAt = new Date().toISOString();
|
|
182
308
|
fs.writeJsonSync(featuresFile, features, { spaces: 2 });
|
|
183
309
|
|
|
310
|
+
console.log('=== 创建接口:准备返回的数据 ===');
|
|
311
|
+
console.log('返回给前端的数据:', JSON.stringify(newInterface, null, 2));
|
|
312
|
+
|
|
184
313
|
res.json({
|
|
185
314
|
code: 0,
|
|
186
315
|
message: '接口创建成功',
|
|
@@ -253,7 +382,10 @@ const initRouter = () => {
|
|
|
253
382
|
}
|
|
254
383
|
|
|
255
384
|
// 处理接口数据,确保兼容多响应格式
|
|
385
|
+
console.log('=== 更新接口:开始处理数据 ===');
|
|
386
|
+
console.log('接收到的接口数据:', JSON.stringify(interfaceData, null, 2));
|
|
256
387
|
const processedData = processInterfaceData(interfaceData);
|
|
388
|
+
console.log('处理后的接口数据:', JSON.stringify(processedData, null, 2));
|
|
257
389
|
|
|
258
390
|
// 更新接口
|
|
259
391
|
const updatedInterface = {
|
|
@@ -262,10 +394,23 @@ const initRouter = () => {
|
|
|
262
394
|
updatedAt: new Date().toISOString()
|
|
263
395
|
};
|
|
264
396
|
|
|
397
|
+
console.log('=== 更新接口:准备保存的完整接口数据 ===');
|
|
398
|
+
console.log('完整的更新接口数据:', JSON.stringify(updatedInterface, null, 2));
|
|
399
|
+
|
|
265
400
|
interfaces[index] = updatedInterface;
|
|
266
401
|
|
|
267
402
|
// 保存接口列表
|
|
268
403
|
fs.writeJsonSync(interfacesFile, interfaces, { spaces: 2 });
|
|
404
|
+
console.log('接口数据已保存到文件:', interfacesFile);
|
|
405
|
+
|
|
406
|
+
// 验证保存后从文件读取的数据
|
|
407
|
+
const savedInterfaces = fs.readJsonSync(interfacesFile);
|
|
408
|
+
const savedInterface = savedInterfaces.find(item => item.id === id);
|
|
409
|
+
console.log('=== 更新接口:验证保存后的数据 ===');
|
|
410
|
+
console.log('从文件读取的保存后数据:', JSON.stringify(savedInterface, null, 2));
|
|
411
|
+
|
|
412
|
+
console.log('=== 更新接口:准备返回的数据 ===');
|
|
413
|
+
console.log('返回给前端的数据:', JSON.stringify(updatedInterface, null, 2));
|
|
269
414
|
|
|
270
415
|
res.json({
|
|
271
416
|
code: 0,
|