|
|
|
@ -1,4 +1,15 @@ |
|
|
|
import { Action, Body, Controller, Import, Method, Property, Service, Signature } from '../models'; |
|
|
|
import { |
|
|
|
Action, |
|
|
|
Body, |
|
|
|
Controller, |
|
|
|
Import, |
|
|
|
Method, |
|
|
|
Property, |
|
|
|
Service, |
|
|
|
Signature, |
|
|
|
Type, |
|
|
|
TypeWithEnum, |
|
|
|
} from '../models'; |
|
|
|
import { sortImports } from './import'; |
|
|
|
import { parseNamespace } from './namespace'; |
|
|
|
import { parseGenerics } from './tree'; |
|
|
|
@ -8,14 +19,18 @@ export function serializeParameters(parameters: Property[]) { |
|
|
|
return parameters.map(p => p.name + p.optional + ': ' + p.type + p.default, '').join(', '); |
|
|
|
} |
|
|
|
|
|
|
|
export function createControllerToServiceMapper(solution: string, apiName: string) { |
|
|
|
export function createControllerToServiceMapper( |
|
|
|
solution: string, |
|
|
|
types: Record<string, Type>, |
|
|
|
apiName: string, |
|
|
|
) { |
|
|
|
const mapActionToMethod = createActionToMethodMapper(solution); |
|
|
|
|
|
|
|
return (controller: Controller) => { |
|
|
|
const name = controller.controllerName; |
|
|
|
const namespace = parseNamespace(solution, controller.type); |
|
|
|
const actions = Object.values(controller.actions); |
|
|
|
const imports = actions.reduce(createActionToImportsReducer(solution, namespace), []); |
|
|
|
const imports = actions.reduce(createActionToImportsReducer(solution, types, namespace), []); |
|
|
|
imports.push(new Import({ path: '@abp/ng.core', specifiers: ['RestService'] })); |
|
|
|
imports.push(new Import({ path: '@angular/core', specifiers: ['Injectable'] })); |
|
|
|
sortImports(imports); |
|
|
|
@ -75,18 +90,22 @@ function getMethodNameFromAction(action: Action): string { |
|
|
|
return action.uniqueName.split('Async')[0]; |
|
|
|
} |
|
|
|
|
|
|
|
function createActionToImportsReducer(solution: string, namespace: string) { |
|
|
|
function createActionToImportsReducer( |
|
|
|
solution: string, |
|
|
|
types: Record<string, Type>, |
|
|
|
namespace: string, |
|
|
|
) { |
|
|
|
const mapTypesToImports = createTypesToImportsReducer(solution, namespace); |
|
|
|
|
|
|
|
return (imports: Import[], { parametersOnMethod, returnValue }: Action) => |
|
|
|
mapTypesToImports( |
|
|
|
imports, |
|
|
|
[returnValue, ...parametersOnMethod].reduce((types: string[], { type }) => { |
|
|
|
parseGenerics(type) |
|
|
|
[returnValue, ...parametersOnMethod].reduce((acc: TypeWithEnum[], param) => { |
|
|
|
parseGenerics(param.type) |
|
|
|
.toGenerics() |
|
|
|
.forEach(t => types.push(t)); |
|
|
|
.forEach(type => acc.push({ type, isEnum: types[type]?.isEnum })); |
|
|
|
|
|
|
|
return types; |
|
|
|
return acc; |
|
|
|
}, []), |
|
|
|
); |
|
|
|
} |
|
|
|
|