Skip to content

Commit 85c7373

Browse files
committed
refac
1 parent 11e0768 commit 85c7373

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

backend/open_webui/utils/tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,13 @@ def resolve_schema(schema, components, resolved_schemas=None):
802802
if 'items' in resolved_schema:
803803
resolved_schema['items'] = resolve_schema(resolved_schema['items'], components)
804804

805+
# Resolve composition keywords (oneOf, anyOf, allOf) which may contain $ref
806+
for keyword in ('oneOf', 'anyOf', 'allOf'):
807+
if keyword in resolved_schema and isinstance(resolved_schema[keyword], list):
808+
resolved_schema[keyword] = [
809+
resolve_schema(inner, components, resolved_schemas) for inner in resolved_schema[keyword]
810+
]
811+
805812
return resolved_schema
806813

807814

src/lib/utils/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,9 +1377,35 @@ function resolveSchema(schemaRef, components, resolvedSchemas = new Set()) {
13771377
// for primitive types (string, integer, etc.), just use as is
13781378
break;
13791379
}
1380+
1381+
// Resolve composition keywords (oneOf, anyOf, allOf) which may contain $ref
1382+
for (const keyword of ['oneOf', 'anyOf', 'allOf']) {
1383+
if (Array.isArray(schemaRef[keyword])) {
1384+
schemaObj[keyword] = schemaRef[keyword].map((inner) =>
1385+
resolveSchema(inner, components, resolvedSchemas)
1386+
);
1387+
}
1388+
}
1389+
13801390
return schemaObj;
13811391
}
13821392

1393+
// Handle schemas that only have composition keywords without an explicit type
1394+
const compositionObj: Record<string, any> = {};
1395+
let hasComposition = false;
1396+
for (const keyword of ['oneOf', 'anyOf', 'allOf']) {
1397+
if (Array.isArray(schemaRef[keyword])) {
1398+
compositionObj[keyword] = schemaRef[keyword].map((inner) =>
1399+
resolveSchema(inner, components, resolvedSchemas)
1400+
);
1401+
hasComposition = true;
1402+
}
1403+
}
1404+
if (hasComposition) {
1405+
if (schemaRef.description) compositionObj.description = schemaRef.description;
1406+
return compositionObj;
1407+
}
1408+
13831409
// fallback for schemas without explicit type
13841410
return {};
13851411
}

0 commit comments

Comments
 (0)