Merge e18334729bbe1d06c7361a574bae1323de645188 into 2c6c05988e1042061a8431a2a77f965e200fbb6b

This commit is contained in:
Aleš Ferlan 2025-05-26 09:33:08 +05:30 committed by GitHub
commit e870f38999
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -171,7 +171,35 @@ export function mapOpenApiSchemaToJsonSchema(
if (typeof schema === 'boolean') return schema;
// Create a copy of the schema to modify
const jsonSchema: JSONSchema7 = { ...schema } as any;
let jsonSchema: JSONSchema7 = { ...schema } as any;
if (schema.oneOf || schema.anyOf || schema.allOf) {
const oneSchema = structuredClone(schema.oneOf || schema.anyOf || schema.allOf);
if (oneSchema) {
const combinedSchema = mapOpenApiSchemaToJsonSchema(oneSchema[0]);
for (let i = 1; i < oneSchema.length; i++) {
const mappedSubSchema = mapOpenApiSchemaToJsonSchema(oneSchema[i]);
if (typeof mappedSubSchema === 'object' && typeof combinedSchema === 'object') {
// Handle enum values
if (mappedSubSchema.enum) {
if (!combinedSchema.enum) {
combinedSchema.enum = [];
}
// Combine enum values from both schemas
const uniqueEnums = new Set([
...combinedSchema.enum,
...(mappedSubSchema.enum || [])
]);
combinedSchema.enum = Array.from(uniqueEnums);
}
}
}
jsonSchema = combinedSchema as JSONSchema7;
}
}
// Convert integer type to number (JSON Schema compatible)
if (schema.type === 'integer') jsonSchema.type = 'number';