Skip to content

Commit 1ddd6f6

Browse files
fix(ipa): Fix IPA005 rule to allow camel case and numbers in rule name
1 parent 917753b commit 1ddd6f6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-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/functions/IPA005ExceptionExtensionFormat.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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 =
47
'IPA exceptions must have a valid key following xgen-IPA-XXX or xgen-IPA-XXX-{rule-name} format.';
58
const ERROR_MESSAGE_REASON_FORMAT =
69
'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-]+)?$/;
10+
const RULE_NAME_PATTERN = /^xgen-IPA-\d{3}(?:-[a-zA-Z0-9-]+)?$/;
811

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

0 commit comments

Comments
 (0)