Skip to content

Commit 2eb7fd3

Browse files
logic fix
1 parent 79d1b1f commit 2eb7fd3

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

tools/spectral/ipa/__tests__/IPA005ExceptionExtensionFormat.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ testRule('xgen-IPA-005-exception-extension-format', [
1111
'xgen-IPA-100-rule-name': 'Exception.',
1212
},
1313
},
14+
'/path-short': {
15+
'x-xgen-IPA-exception': {
16+
'xgen-IPA-100': 'Exception.',
17+
},
18+
},
1419
'/nested': {
1520
post: {
1621
'x-xgen-IPA-exception': {
1722
'xgen-IPA-100-rule-name': 'Exception.',
23+
'xgen-IPA-005': 'Short format exception.',
1824
},
1925
},
2026
},
@@ -61,6 +67,26 @@ testRule('xgen-IPA-005-exception-extension-format', [
6167
'xgen-IPA_100_rule-name': {},
6268
},
6369
},
70+
'/path8': {
71+
'x-xgen-IPA-exception': {
72+
'xgen-IPA-100-': 'Exception.',
73+
},
74+
},
75+
'/path9': {
76+
'x-xgen-IPA-exception': {
77+
'xgen-IPA-5': 'Exception.',
78+
},
79+
},
80+
'/path10': {
81+
'x-xgen-IPA-exception': {
82+
'xgen-IPA-100': 'exception without uppercase.',
83+
},
84+
},
85+
'/path11': {
86+
'x-xgen-IPA-exception': {
87+
'xgen-IPA-100': 'Exception without period',
88+
},
89+
},
6490
},
6591
},
6692
errors: [
@@ -106,6 +132,30 @@ testRule('xgen-IPA-005-exception-extension-format', [
106132
path: ['paths', '/path7', 'x-xgen-IPA-exception'],
107133
severity: DiagnosticSeverity.Error,
108134
},
135+
{
136+
code: 'xgen-IPA-005-exception-extension-format',
137+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
138+
path: ['paths', '/path8', 'x-xgen-IPA-exception'],
139+
severity: DiagnosticSeverity.Error,
140+
},
141+
{
142+
code: 'xgen-IPA-005-exception-extension-format',
143+
message: 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.',
144+
path: ['paths', '/path9', 'x-xgen-IPA-exception'],
145+
severity: DiagnosticSeverity.Error,
146+
},
147+
{
148+
code: 'xgen-IPA-005-exception-extension-format',
149+
message: 'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.',
150+
path: ['paths', '/path10', 'x-xgen-IPA-exception'],
151+
severity: DiagnosticSeverity.Error,
152+
},
153+
{
154+
code: 'xgen-IPA-005-exception-extension-format',
155+
message: 'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.',
156+
path: ['paths', '/path11', 'x-xgen-IPA-exception'],
157+
severity: DiagnosticSeverity.Error,
158+
},
109159
],
110160
},
111161
]);

tools/spectral/ipa/rulesets/IPA-005.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rules:
1111
1212
##### Implementation details
1313
Rule checks for the following conditions:
14-
- Exception rule names must follow 'xgen-IPA-XXX-{rule-name}' format.
14+
- Exception rule names must start with 'xgen-IPA-' prefix
1515
- Each exception must include a non-empty reason as a string that starts with uppercase and ends with a full stop
1616
- This rule itself does not allow exceptions
1717
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-005-exception-extension-format'

tools/spectral/ipa/rulesets/functions/IPA005ExceptionExtensionFormat.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { evaluateAndCollectAdoptionStatusWithoutExceptions, handleInternalError } from './utils/collectionUtils.js';
1+
import {
2+
evaluateAndCollectAdoptionStatusWithoutExceptions,
3+
handleInternalError,
4+
} from './utils/collectionUtils.js';
25

36
const ERROR_MESSAGE_RULENAME_FORMAT = 'IPA exceptions must have a valid key following xgen-IPA-XXX-{rule-name} format.';
47
const ERROR_MESSAGE_REASON_FORMAT =
58
'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.';
6-
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}-[a-z-]+$/;
9+
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}(?:-[a-z-]+)?$/;
710

811
// Note: This rule does not allow exceptions
912
export default (input, _, { path, rule }) => {

0 commit comments

Comments
 (0)