-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathfunction-import.ts
65 lines (60 loc) · 1.97 KB
/
function-import.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { ServiceNameFormatter } from '../../service-name-formatter';
import { transformFunctionImportBase } from '../common';
import { swaggerDefinitionForFunctionImport } from '../../swagger-parser/swagger-parser';
import {
EdmxFunction,
EdmxFunctionImport,
parseFunctionImports,
parseFunctions
} from '../../edmx-parser/v4';
import { ServiceMetadata } from '../../edmx-parser/edmx-file-reader';
import { VdmComplexType, VdmEntity, VdmFunctionImport } from '../../vdm-types';
import { parseFunctionImportReturnTypes } from '../common/action-function-return-types';
import { findActionFunctionByImportName } from './action-function-util';
function findFunctionForFunctionImport(
functions: EdmxFunction[],
functionImport: EdmxFunctionImport
): EdmxFunction {
return findActionFunctionByImportName(
functions,
functionImport.Function,
'function'
);
}
export function generateFunctionImportsV4(
serviceMetadata: ServiceMetadata,
entities: VdmEntity[],
complexTypes: Omit<VdmComplexType, 'factoryName'>[],
formatter: ServiceNameFormatter
): VdmFunctionImport[] {
const functions = parseFunctions(serviceMetadata.edmx.root);
const functionImports = parseFunctionImports(serviceMetadata.edmx.root);
return functionImports.map(functionImport => {
const edmxFunction = findFunctionForFunctionImport(
functions,
functionImport
);
const httpMethod = 'get';
const swaggerDefinition = swaggerDefinitionForFunctionImport(
functionImport.Name,
httpMethod,
serviceMetadata.swagger
);
return {
...transformFunctionImportBase(
functionImport,
edmxFunction.Parameter,
swaggerDefinition,
formatter
),
httpMethod,
returnType: parseFunctionImportReturnTypes(
edmxFunction.ReturnType?.Type,
entities,
complexTypes,
serviceMetadata.edmx.oDataVersion
)
};
});
}