This commit is contained in:
Timothy Jaeryang Baek
2026-05-09 07:37:53 +09:00
parent 11e076817a
commit 85c7373f68
2 changed files with 33 additions and 0 deletions
+7
View File
@@ -802,6 +802,13 @@ def resolve_schema(schema, components, resolved_schemas=None):
if 'items' in resolved_schema:
resolved_schema['items'] = resolve_schema(resolved_schema['items'], components)
# Resolve composition keywords (oneOf, anyOf, allOf) which may contain $ref
for keyword in ('oneOf', 'anyOf', 'allOf'):
if keyword in resolved_schema and isinstance(resolved_schema[keyword], list):
resolved_schema[keyword] = [
resolve_schema(inner, components, resolved_schemas) for inner in resolved_schema[keyword]
]
return resolved_schema
+26
View File
@@ -1377,9 +1377,35 @@ function resolveSchema(schemaRef, components, resolvedSchemas = new Set()) {
// for primitive types (string, integer, etc.), just use as is
break;
}
// Resolve composition keywords (oneOf, anyOf, allOf) which may contain $ref
for (const keyword of ['oneOf', 'anyOf', 'allOf']) {
if (Array.isArray(schemaRef[keyword])) {
schemaObj[keyword] = schemaRef[keyword].map((inner) =>
resolveSchema(inner, components, resolvedSchemas)
);
}
}
return schemaObj;
}
// Handle schemas that only have composition keywords without an explicit type
const compositionObj: Record<string, any> = {};
let hasComposition = false;
for (const keyword of ['oneOf', 'anyOf', 'allOf']) {
if (Array.isArray(schemaRef[keyword])) {
compositionObj[keyword] = schemaRef[keyword].map((inner) =>
resolveSchema(inner, components, resolvedSchemas)
);
hasComposition = true;
}
}
if (hasComposition) {
if (schemaRef.description) compositionObj.description = schemaRef.description;
return compositionObj;
}
// fallback for schemas without explicit type
return {};
}