Files

19 lines
646 B
TypeScript
Executable File

const typeMap: Record<string, any> = {
number: { type: 'integer', format: 'int64' },
string: { type: 'string' },
Date: { type: 'string', format: 'date-time' },
boolean: { type: 'boolean' },
}
export async function modelToSchema(model: any) {
const properties: Record<string, any> = {}
for (const [key, meta] of model.$columnsDefinitions.entries()) {
const tsType = meta.meta?.designType?.name || 'string'
const mapped = typeMap[tsType] ?? { type: 'string' }
properties[meta?.serializeAs || key] = {
...mapped,
description: key.replace(/([A-Z])/g, ' $1').trim(),
}
}
return JSON.stringify(properties)
}