Skip to content

Commit e43e965

Browse files
committed
(fixes finos#1210) fixed validate crash
1 parent 8772e31 commit e43e965

File tree

3 files changed

+191
-185
lines changed

3 files changed

+191
-185
lines changed

cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@finos/calm-cli",
3-
"version": "0.7.2",
3+
"version": "0.7.3",
44
"description": "A set of tools for interacting with the Common Architecture Language Model (CALM)",
55
"main": "dist/index.js",
66
"files": [

shared/src/spectral/functions/pattern/interface-id-exists-on-node.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ export function interfaceIdExistsOnNode(input, _, context) {
1717
}
1818

1919
const nodeId = input.node;
20-
const nodeMatch: object[] = JSONPath({ path: `$.properties.nodes.prefixItems[?(@.properties['unique-id'].const == '${nodeId}')]`, json: context.document.data });
21-
if (!nodeMatch || nodeMatch.length === 0) {
20+
const nodes: object[] = JSONPath({ path: '$.properties.nodes.prefixItems[*]', json: context.document.data });
21+
const node = nodes.find((node) => {
22+
const uniqueId: string[] = JSONPath({ path: '$.properties.unique-id.const', json: node });
23+
uniqueId.push(...JSONPath({ path: '$.oneOf[*].properties.unique-id.const', json: node }));
24+
uniqueId.push(...JSONPath({ path: '$.anyOf[*].properties.unique-id.const', json: node }));
25+
return uniqueId && uniqueId[0] === nodeId;
26+
});
27+
if (!node) {
2228
// other rule will report undefined node
2329
return [];
2430
}
2531

2632
// all of these must be present on the referenced node
2733
const desiredInterfaces = input.interfaces;
2834

29-
const node = nodeMatch[0];
30-
3135
const nodeInterfaces = JSONPath({ path: '$.properties.interfaces.prefixItems[*].properties.unique-id.const', json: node });
36+
nodeInterfaces.push(...JSONPath({ path: '$.oneOf[*].properties.interfaces.prefixItems[*].properties.unique-id.const', json: node }));
37+
nodeInterfaces.push(...JSONPath({ path: '$.anyOf[*].properties.interfaces.prefixItems[*].properties.unique-id.const', json: node }));
3238
if (!nodeInterfaces || nodeInterfaces.length === 0) {
3339
return [
3440
{ message: `Node with unique-id ${nodeId} has no interfaces defined, expected interfaces [${desiredInterfaces}]` }
@@ -37,7 +43,7 @@ export function interfaceIdExistsOnNode(input, _, context) {
3743

3844
const missingInterfaces = difference(desiredInterfaces, nodeInterfaces);
3945

40-
// difference always returns an array
46+
//difference always returns an array
4147
if (missingInterfaces.length === 0) {
4248
return [];
4349
}

0 commit comments

Comments
 (0)