-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathfunction-import.ts
51 lines (47 loc) · 1.8 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
import { ServiceNameFormatter } from '../../service-name-formatter';
import { transformFunctionImportBase } from '../common';
import { VdmComplexType, VdmEntity, VdmFunctionImport } from '../../vdm-types';
import { swaggerDefinitionForFunctionImport } from '../../swagger-parser/swagger-parser';
import { parseFunctionImports } from '../../edmx-parser/v2';
import { ServiceMetadata } from '../../edmx-parser/edmx-file-reader';
import { parseFunctionImportReturnTypes } from '../common/action-function-return-types';
import { hasUnsupportedParameterTypes } from '../edmx-to-vdm-util';
const extractResponse = (functionName: string) => (response: string) =>
`${response}.${functionName}`;
export function generateFunctionImportsV2(
serviceMetadata: ServiceMetadata,
entities: VdmEntity[],
complexTypes: Omit<VdmComplexType, 'factoryName'>[],
formatter: ServiceNameFormatter
): VdmFunctionImport[] {
const edmxFunctionImports = parseFunctionImports(serviceMetadata.edmx.root);
return (
edmxFunctionImports
// TODO 1571 remove when supporting entity type as parameter
.filter(functionImport => !hasUnsupportedParameterTypes(functionImport))
.map(f => {
const httpMethod = f['m:HttpMethod'].toLowerCase();
const swaggerDefinition = swaggerDefinitionForFunctionImport(
f.Name,
httpMethod,
serviceMetadata.swagger
);
return {
...transformFunctionImportBase(
f,
f.Parameter,
swaggerDefinition,
formatter
),
httpMethod,
returnType: parseFunctionImportReturnTypes(
f.ReturnType,
entities,
complexTypes,
extractResponse(f.Name),
serviceMetadata.edmx.oDataVersion
)
};
})
);
}