Refactor schema ID handling and reduce parse depth

Changed MAX_PARSE_DEPTH from 10 to 6 to limit nesting. Improved schema ID retrieval to only use $id if present, and added a utility to collect all $id values in a schema for better circular reference detection. Updated font file AaCute.woff.
This commit is contained in:
手瓜一十雪 2026-01-28 16:01:43 +08:00
parent a71219062a
commit bf073b544b
2 changed files with 34 additions and 4 deletions

View File

@ -22,14 +22,44 @@ export const BaseResponseSchema = Type.Object({
});
// 最大解析深度,防止过深的嵌套
const MAX_PARSE_DEPTH = 10;
const MAX_PARSE_DEPTH = 6;
/**
* schema
* 使 $id使
* 使 $id
*/
function getSchemaId (schema: TSchema): string | TSchema {
return schema.$id || schema;
function getSchemaId (schema: TSchema): string | undefined {
// 优先使用 $id
if (schema.$id) {
return schema.$id;
}
return undefined;
}
/**
* schema $id
*/
function collectSchemaIds (schema: TSchema, ids: Set<string> = new Set()): Set<string> {
if (!schema) return ids;
if (schema.$id) {
ids.add(schema.$id);
}
if (schema.anyOf) {
(schema.anyOf as TSchema[]).forEach(s => collectSchemaIds(s, ids));
}
if (schema.oneOf) {
(schema.oneOf as TSchema[]).forEach(s => collectSchemaIds(s, ids));
}
if (schema.allOf) {
(schema.allOf as TSchema[]).forEach(s => collectSchemaIds(s, ids));
}
if (schema.items) {
collectSchemaIds(schema.items as TSchema, ids);
}
if (schema.properties) {
Object.values(schema.properties).forEach(s => collectSchemaIds(s as TSchema, ids));
}
return ids;
}
export function parseTypeBox (