forked from finos/architecture-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules-architecture.ts
More file actions
179 lines (163 loc) · 6.55 KB
/
rules-architecture.ts
File metadata and controls
179 lines (163 loc) · 6.55 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import { RulesetDefinition } from '@stoplight/spectral-core';
import { pattern, truthy } from '@stoplight/spectral-functions';
import { numericalPlaceHolder } from './functions/helper-functions';
import { idsAreUnique } from './functions/architecture/ids-are-unique';
import { nodeIdExists } from './functions/architecture/node-id-exists';
import { interfaceIdExists } from './functions/architecture/interface-id-exists';
import { nodeHasRelationship } from './functions/architecture/node-has-relationship';
import { interfaceIdExistsOnNode } from './functions/architecture/interface-id-exists-on-node';
import { relationshipIdExists } from './functions/architecture/relationship-id-exists';
import { sequenceNumbersAreUnique } from './functions/architecture/sequence-numbers-are-unique';
const architectureRules: RulesetDefinition = {
rules: {
'architecture-has-nodes-relationships': {
description: 'Has top level nodes and relationships',
message: 'Should have nodes and relationships as top level properties on the CALM document',
severity: 'error',
given: '$',
then: [
{
field: 'nodes',
function: truthy,
},
{
field: 'relationships',
function: truthy,
},
],
},
'architecture-has-no-empty-string-properties': {
description: 'Must not contain string properties set to the empty string',
message: 'All properties must be set to a nonempty value.',
severity: 'error',
given: '$..*@string()',
then: {
function: truthy,
},
},
'architecture-has-no-placeholder-properties-numerical': {
description: 'Should not contain numerical placeholder properties set to -1',
message: 'Numerical placeholder (-1) detected in architecture.',
severity: 'warn',
given: '$..*',
then: {
function: numericalPlaceHolder,
},
},
'architecture-has-no-placeholder-properties-string': {
description: 'Should not contain placeholder values with pattern [[ PLACEHOLDER_NAME ]]',
message: 'String placeholder detected in architecture.',
severity: 'warn',
given: '$..*',
then: {
function: pattern,
functionOptions: {
notMatch: '^\\[\\[\\s*[A-Z_]+\\s*\\]\\]$',
},
},
},
'architecture-has-no-placeholder-properties-boolean': {
description: 'Should not contain placeholder values with pattern [[ BOOLEAN_[property name] ]]',
message: 'Boolean placeholder detected in architecture.',
severity: 'warn',
given: '$..*',
then: {
function: pattern,
functionOptions: {
notMatch: '^\\[\\[\\s*BOOLEAN_[A-Z_]+\\s*\\]\\]$',
},
},
},
'relationship-references-existing-nodes-in-architecture': {
description: 'Relationships must reference existing nodes',
severity: 'error',
message: '{{error}}',
given: '$.relationships[*].relationship-type.*',
then: [
{
field: 'actor',
function: nodeIdExists,
},
{
field: 'container',
function: nodeIdExists,
},
],
},
'connects-relationship-references-existing-nodes-in-architecture': {
description: 'Connects relationships must reference existing nodes',
severity: 'error',
message: '{{error}}',
given: '$.relationships[*].relationship-type.connects.*',
then: {
field: 'node',
function: nodeIdExists
},
},
'referenced-interfaces-defined-in-architecture': {
description: 'Referenced interfaces must be defined',
severity: 'error',
message: '{{error}}',
given: '$.relationships[*].relationship-type.connects.*.interfaces[*]',
then: {
function: interfaceIdExists
},
},
'referenced-interfaces-defined-on-correct-node-in-architecture': {
description: 'Connects relationships must reference interfaces that exist on the correct nodes',
severity: 'error',
message: '{{error}}',
given: '$.relationships[*].relationship-type.connects.*',
then: {
function: interfaceIdExistsOnNode
},
},
'composition-relationships-reference-existing-nodes-in-architecture': {
description: 'All nodes in a composition relationship must reference existing nodes',
severity: 'error',
message: '{{error}}',
given: '$.relationships[*].relationship-type.*.nodes[*]',
then: {
function: nodeIdExists
},
},
'architecture-nodes-must-be-referenced': {
description: 'Nodes must be referenced by at least one relationship.',
severity: 'warn',
message: '{{error}}',
given: '$.nodes[*].unique-id',
then: {
function: nodeHasRelationship
},
},
'unique-ids-must-be-unique-in-architecture': {
description: 'Unique IDs cannot be reused.',
severity: 'error',
message: '{{error}}',
given: '$',
then: {
function: idsAreUnique
},
},
'flow-transitions-references-existing-relationship-in-architecture': {
description: 'Flow transitions must reference existing relationships',
severity: 'error',
message: '{{error}}',
given: '$.flows[*].transitions[*]',
then: {
field: 'relationship-unique-id',
function: relationshipIdExists
}
},
'flow-transitions-have-unique-sequence-numbers': {
description: 'Flows must have unique sequence numbers',
severity: 'error',
message: '{{error}}',
given: '$.flows[*].transitions',
then: {
function: sequenceNumbersAreUnique
}
}
}
};
export default architectureRules;