@@ -17,18 +17,24 @@ export function interfaceIdExistsOnNode(input, _, context) {
17
17
}
18
18
19
19
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 ) {
22
28
// other rule will report undefined node
23
29
return [ ] ;
24
30
}
25
31
26
32
// all of these must be present on the referenced node
27
33
const desiredInterfaces = input . interfaces ;
28
34
29
- const node = nodeMatch [ 0 ] ;
30
-
31
35
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 } ) ) ;
32
38
if ( ! nodeInterfaces || nodeInterfaces . length === 0 ) {
33
39
return [
34
40
{ message : `Node with unique-id ${ nodeId } has no interfaces defined, expected interfaces [${ desiredInterfaces } ]` }
@@ -37,7 +43,7 @@ export function interfaceIdExistsOnNode(input, _, context) {
37
43
38
44
const missingInterfaces = difference ( desiredInterfaces , nodeInterfaces ) ;
39
45
40
- // difference always returns an array
46
+ //difference always returns an array
41
47
if ( missingInterfaces . length === 0 ) {
42
48
return [ ] ;
43
49
}
0 commit comments