Improve schema parsing and error handling in API debug tools

Enhances the TypeBox schema parser to better handle deep nesting, circular references, and union truncation, and adds error handling for schema parsing and default value generation in the OneBot API debug UI. Updates the display component to show clear messages for circular or truncated schemas, and improves robustness in HTTP debug command execution. Also synchronizes the ParsedSchema type in the Zod utility for consistency.
This commit is contained in:
手瓜一十雪
2026-01-28 16:07:23 +08:00
parent c39df932bf
commit 4b2b9b8cfc
5 changed files with 152 additions and 103 deletions

View File

@@ -112,9 +112,17 @@ export default function HttpDebug () {
const executeCommand = (commandId: string, mode: CommandPaletteExecuteMode) => {
const api = commandId as OneBotHttpApiPath;
const item = oneBotHttpApi[api];
const body = item?.payloadExample
? JSON.stringify(item.payloadExample, null, 2)
: (item?.payload ? JSON.stringify(generateDefaultFromTypeBox(item.payload), null, 2) : '{}');
let body = '{}';
if (item?.payloadExample) {
body = JSON.stringify(item.payloadExample, null, 2);
} else if (item?.payload) {
try {
body = JSON.stringify(generateDefaultFromTypeBox(item.payload), null, 2);
} catch (e) {
console.error('Error generating default:', e);
body = '{}';
}
}
handleSelectApi(api);
// 确保请求参数可见