|
|
|
@ -4,7 +4,7 @@ import { parseNamespace } from './namespace'; |
|
|
|
import { createTypeSimplifier } from './type'; |
|
|
|
|
|
|
|
export function createImportRefsToModelMapper(solution: string, types: Record<string, Type>) { |
|
|
|
const simplifyType = createTypeSimplifier(solution); |
|
|
|
const mapImportRefToInterface = createImportRefToInterfaceMapper(solution, types); |
|
|
|
|
|
|
|
return (importRefs: string[]) => { |
|
|
|
const model = new Model({ |
|
|
|
@ -12,28 +12,36 @@ export function createImportRefsToModelMapper(solution: string, types: Record<st |
|
|
|
}); |
|
|
|
|
|
|
|
importRefs.forEach(ref => { |
|
|
|
const typeDef = types[ref]; |
|
|
|
let identifier = simplifyType(ref); |
|
|
|
(typeDef.genericArguments ?? []).forEach((t, i) => { |
|
|
|
identifier = identifier.replace(`T${i}`, t); |
|
|
|
}); |
|
|
|
model.interfaces.push(mapImportRefToInterface(ref)); |
|
|
|
}); |
|
|
|
|
|
|
|
model.interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1)); |
|
|
|
|
|
|
|
return model; |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; |
|
|
|
const _interface = new Interface({ identifier, base }); |
|
|
|
export function createImportRefToInterfaceMapper(solution: string, types: Record<string, Type>) { |
|
|
|
const simplifyType = createTypeSimplifier(solution); |
|
|
|
|
|
|
|
typeDef.properties?.forEach(({ name, typeSimple }) => { |
|
|
|
name = strings.camelize(name); |
|
|
|
const type = simplifyType(typeSimple); |
|
|
|
const optional = typeSimple.endsWith('?') ? '?' : ''; |
|
|
|
return (ref: string) => { |
|
|
|
const typeDef = types[ref]; |
|
|
|
let identifier = simplifyType(ref); |
|
|
|
(typeDef.genericArguments ?? []).forEach((t, i) => { |
|
|
|
identifier = identifier.replace(`T${i}`, t); |
|
|
|
}); |
|
|
|
|
|
|
|
_interface.properties.push(new Property({ name, type, optional })); |
|
|
|
}); |
|
|
|
const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; |
|
|
|
const _interface = new Interface({ identifier, base }); |
|
|
|
|
|
|
|
console.log(_interface); |
|
|
|
typeDef.properties?.forEach(({ name, typeSimple }) => { |
|
|
|
name = strings.camelize(name); |
|
|
|
const optional = typeSimple.endsWith('?') ? '?' : ''; |
|
|
|
const type = simplifyType(typeSimple); |
|
|
|
|
|
|
|
model.interfaces.push(_interface); |
|
|
|
_interface.properties.push(new Property({ name, optional, type })); |
|
|
|
}); |
|
|
|
|
|
|
|
return model; |
|
|
|
return _interface; |
|
|
|
}; |
|
|
|
} |
|
|
|
|