Skip to content

Commit 88b6c13

Browse files
fix(ipa): Fix IPA005 rule to allow camel case and numbers in rule name (#940)
1 parent d9648f4 commit 88b6c13

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@ testRule('xgen-IPA-005-exception-extension-format', [
1616
'xgen-IPA-100': 'Exception.',
1717
},
1818
},
19+
'/path-camelCase': {
20+
'x-xgen-IPA-exception': {
21+
'xgen-IPA-125-rule-name-camelCase': 'Exception.',
22+
},
23+
},
24+
'/path-numbers': {
25+
'x-xgen-IPA-exception': {
26+
'xgen-IPA-117-rule-name-1': 'Exception.',
27+
},
28+
},
1929
'/nested': {
2030
post: {
2131
'x-xgen-IPA-exception': {
2232
'xgen-IPA-100-rule-name': 'Exception.',
2333
'xgen-IPA-005': 'Short format exception.',
34+
'xgen-IPA-112-camelCase': 'CamelCase exception.',
2435
},
2536
},
2637
},

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ rules:
1111
1212
##### Implementation details
1313
Rule checks for the following conditions:
14-
- Exception rule names must start with 'xgen-IPA-' prefix
14+
- Exception rule names must start with 'xgen-IPA-' prefix followed by exactly 3 digits
1515
- Exception rule names can be either short format (xgen-IPA-XXX) or full format (xgen-IPA-XXX-rule-name)
16+
- Rule names in full format can use letters (upper/lowercase), numbers, and hyphens
1617
- Each exception must include a non-empty reason as a string that starts with uppercase and ends with a full stop
1718
- This rule itself does not allow exceptions
1819
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-005-exception-extension-format'

tools/spectral/ipa/rulesets/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ IPA exception extensions must follow the correct format.
1919

2020
##### Implementation details
2121
Rule checks for the following conditions:
22-
- Exception rule names must start with 'xgen-IPA-' prefix
22+
- Exception rule names must start with 'xgen-IPA-' prefix followed by exactly 3 digits
2323
- Exception rule names can be either short format (xgen-IPA-XXX) or full format (xgen-IPA-XXX-rule-name)
24+
- Rule names in full format can use letters (upper/lowercase), numbers, and hyphens
2425
- Each exception must include a non-empty reason as a string that starts with uppercase and ends with a full stop
2526
- This rule itself does not allow exceptions
2627

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const ERROR_MESSAGE_RULENAME_FORMAT =
44
'IPA exceptions must have a valid key following xgen-IPA-XXX or xgen-IPA-XXX-{rule-name} format.';
55
const ERROR_MESSAGE_REASON_FORMAT =
66
'IPA exceptions must have a non-empty reason that starts with uppercase and ends with a full stop.';
7-
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}(?:-[a-z-]+)?$/;
7+
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}(?:-[a-zA-Z0-9-]+)?$/;
88

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

0 commit comments

Comments
 (0)