|
|
@ -21,36 +21,51 @@ export function createImportRefsToModelMapper(solution: string, types: Record<st |
|
|
|
|
|
|
|
|
const reduceImportRefToImport = createImportRefToImportReducer(namespace); |
|
|
const reduceImportRefToImport = createImportRefToImportReducer(namespace); |
|
|
const imports = importRefs.reduce((accumulatedImports, ref) => { |
|
|
const imports = importRefs.reduce((accumulatedImports, ref) => { |
|
|
if (!types[ref].isEnum) model.interfaces.push(mapImportRefToInterface(ref)); |
|
|
const interfaceDirect = mapImportRefToInterface(ref); |
|
|
|
|
|
if (interfaceDirect && !types[ref].isEnum) model.interfaces.push(interfaceDirect); |
|
|
|
|
|
|
|
|
return reduceImportRefToImport(accumulatedImports, ref); |
|
|
return reduceImportRefToImport(accumulatedImports, ref); |
|
|
}, []); |
|
|
}, []); |
|
|
|
|
|
|
|
|
sortImports(imports); |
|
|
sortImports(imports); |
|
|
|
|
|
|
|
|
const selfPath = relativePathToModel(namespace, namespace); |
|
|
const selfPath = relativePathToModel(namespace, namespace); |
|
|
imports.forEach(i => { |
|
|
imports.forEach(_import => { |
|
|
if (i.path === selfPath) return; |
|
|
if (_import.path === selfPath) |
|
|
model.imports.push(i); |
|
|
return _import.refs.forEach(ref => { |
|
|
|
|
|
if (model.interfaces.some(i => i.ref === ref)) return; |
|
|
|
|
|
|
|
|
|
|
|
const interfaceIndirect = mapImportRefToInterface(ref); |
|
|
|
|
|
if (interfaceIndirect) model.interfaces.push(interfaceIndirect); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
model.imports.push(_import); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
model.interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1)); |
|
|
sortInterfaces(model.interfaces); |
|
|
|
|
|
|
|
|
return model; |
|
|
return model; |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function sortInterfaces(interfaces: Interface[]) { |
|
|
|
|
|
interfaces.sort((a, b) => (a.identifier > b.identifier ? 1 : -1)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function createImportRefToInterfaceMapper(solution: string, types: Record<string, Type>) { |
|
|
export function createImportRefToInterfaceMapper(solution: string, types: Record<string, Type>) { |
|
|
const simplifyType = createTypeSimplifier(solution); |
|
|
const simplifyType = createTypeSimplifier(solution); |
|
|
|
|
|
|
|
|
return (ref: string) => { |
|
|
return (ref: string) => { |
|
|
const typeDef = types[ref]; |
|
|
const typeDef = types[ref]; |
|
|
|
|
|
if (!typeDef) return; |
|
|
|
|
|
|
|
|
const identifier = (typeDef.genericArguments ?? []).reduce( |
|
|
const identifier = (typeDef.genericArguments ?? []).reduce( |
|
|
(acc, t, i) => acc.replace(`T${i}`, t), |
|
|
(acc, t, i) => acc.replace(`T${i}`, t), |
|
|
simplifyType(ref), |
|
|
simplifyType(ref), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; |
|
|
const base = typeDef.baseType ? simplifyType(typeDef.baseType) : null; |
|
|
const _interface = new Interface({ identifier, base }); |
|
|
const _interface = new Interface({ identifier, base, ref }); |
|
|
|
|
|
|
|
|
typeDef.properties?.forEach(({ name, typeSimple }) => { |
|
|
typeDef.properties?.forEach(({ name, typeSimple }) => { |
|
|
name = strings.camelize(name); |
|
|
name = strings.camelize(name); |
|
|
|