-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdescription-util.ts
86 lines (80 loc) · 2.36 KB
/
description-util.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { toTitleFormat } from '@sap-cloud-sdk/core';
import { endWithDot, ensureString } from '../generator-utils';
import {
EdmxDocumented,
EdmxEntitySetBase,
EdmxParameter,
EdmxProperty,
JoinedEntityMetadata
} from '../edmx-parser/common';
import {
SwaggerDescribed,
SwaggerPath,
SwaggerPathParameter,
SwaggerProperty
} from '../swagger-parser/swagger-types';
export function longDescription(
documented: EdmxDocumented,
described?: SwaggerDescribed
): string {
let docs = '';
if (documented.Documentation) {
const summmary = ensureString(documented.Documentation.Summary);
const longDesc = ensureString(documented.Documentation.LongDescription);
docs = `${summmary}\n${longDesc}`.trim();
}
if (!docs && described) {
docs = ensureString(described.description);
}
return endWithDot(docs.trim());
}
export function shortPropertyDescription(
property: EdmxProperty,
swaggerProperty?: SwaggerProperty
): string {
const desc =
property['sap:quickinfo'] ||
property['sap:label'] ||
swaggerProperty?.title ||
'';
return endWithDot(desc.trim());
}
export function propertyDescription(
property: EdmxProperty,
swaggerProperty?: SwaggerProperty
): string {
const short = shortPropertyDescription(property, swaggerProperty);
const long = longDescription(property, swaggerProperty);
return `${short}\n${long}`.trim();
}
export function parameterDescription(
parameter: EdmxParameter,
swaggerParameter?: SwaggerPathParameter
): string {
const short = endWithDot(toTitleFormat(parameter.Name));
const long = longDescription(parameter, swaggerParameter);
return endWithDot((long || short).trim());
}
export function functionImportDescription(
swaggerDefinition: SwaggerPath | undefined,
originalName: string
): string {
return endWithDot(swaggerDefinition?.summary || toTitleFormat(originalName));
}
export function actionImportDescription(
swaggerDefinition: SwaggerPath | undefined,
originalName: string
): string {
return functionImportDescription(swaggerDefinition, originalName);
}
export function entityDescription(
entity: JoinedEntityMetadata<EdmxEntitySetBase, any>,
className: string
): string {
return (
entity.entityType['sap:label'] ||
entity.swaggerDefinition?.title ||
toTitleFormat(className)
);
}