-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateApiFile.js
56 lines (45 loc) · 1.54 KB
/
validateApiFile.js
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
const assert = require("./assert");
const { propertyPlaceholderAnywhereRegEx } = require("./constants");
const expectedOnPremListenerConfig = "standardHTTPS";
const expectedListenerPathRegEx = /^\/(?:console|api)\/.+\/v1\/(?:.+\/)?\*$/;
const validateApiFile = (apiFileName, xml, pomInfo) => {
xml.mule.flow.map(flow => {
let listener = flow["http:listener"];
if (listener) {
let listenerAttributes = listener[0]["$"];
if (pomInfo.isOnPrem) {
assert.equals(
expectedOnPremListenerConfig,
listenerAttributes["config-ref"],
`${apiFileName} http:listener config`
);
}
// Skip the check if there's a property placeholder (like ${api.basepath}) present.
if (!propertyPlaceholderAnywhereRegEx.test(listenerAttributes["path"])) {
assert.matches(
expectedListenerPathRegEx,
listenerAttributes["path"],
`${apiFileName} http:listener path`
);
}
}
let exceptionStrategy = flow["exception-strategy"];
assert.isTrue(
exceptionStrategy,
`${apiFileName}: Missing exception strategy`
);
if (exceptionStrategy) {
let exceptionStrategyAttributes = exceptionStrategy[0]["$"];
assert.equals(
"ChoiceExceptionStrategy",
exceptionStrategyAttributes.ref,
`${apiFileName} exception-strategy ref`
);
}
});
assert.isTrue(
!xml.mule["apikit:mapping-exception-strategy"],
`${apiFileName}: APIkit exception strategy not removed`
);
};
module.exports = validateApiFile;