Skip to content

Commit 8e6fe2f

Browse files
committed
fix: IPA-102
1 parent c31bd58 commit 8e6fe2f

9 files changed

+48
-8
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,50 @@ rules:
2222
given: $.paths
2323
then:
2424
field: '@key'
25-
function: collectionIdentifierCamelCase
25+
function: IPA102CollectionIdentifierCamelCase
2626
functionOptions:
2727
# Contains list of ignored path params
2828
ignoredValues: ['v2', 'v1']
2929

3030
xgen-IPA-102-path-alternate-resource-name-path-param:
31-
description: 'Paths should alternate between resource names and path params.'
31+
description: |
32+
Paths should alternate between resource names and path params.
33+
34+
##### Implementation details
35+
Rule checks for the following conditions:
36+
37+
- Paths must follow a pattern where resource names and path parameters strictly alternate
38+
- Even-indexed path segments should be resource names (not path parameters)
39+
- Odd-indexed path segments should be path parameters
40+
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
3241
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-102-path-alternate-resource-name-path-param'
3342
severity: error
3443
given: '$.paths'
3544
then:
3645
field: '@key'
37-
function: 'eachPathAlternatesBetweenResourceNameAndPathParam'
46+
function: IPA102EachPathAlternatesBetweenResourceNameAndPathParam
3847

3948
xgen-IPA-102-collection-identifier-pattern:
40-
description: Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers.
49+
description: |
50+
Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers.
51+
52+
##### Implementation details
53+
Rule checks for the following conditions:
54+
55+
- All path segments that are not path parameters must match pattern `/^[a-z][a-zA-Z0-9]*$/`
56+
- Path parameters (inside curly braces) are excluded from validation
57+
- Custom methods (segments containing colons) are excluded from validation
58+
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
59+
- Each non-parameter path segment must start with a lowercase letter followed by any combination of ASCII letters and numbers
60+
4161
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-102-collection-identifier-pattern'
4262
severity: warn
4363
given: $.paths
4464
then:
4565
field: '@key'
46-
function: collectionIdentifierPattern
66+
function: IPA102CollectionIdentifierPattern
4767

4868
functions:
49-
- collectionIdentifierPattern
50-
- eachPathAlternatesBetweenResourceNameAndPathParam
51-
- collectionIdentifierCamelCase
69+
- IPA102CollectionIdentifierPattern
70+
- IPA102EachPathAlternatesBetweenResourceNameAndPathParam
71+
- IPA102CollectionIdentifierCamelCase

tools/spectral/ipa/rulesets/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ Rule is based on [http://go/ipa/IPA-102](http://go/ipa/IPA-102).
3333

3434
![error](https://img.shields.io/badge/error-red)
3535
Paths should alternate between resource names and path params.
36+
37+
##### Implementation details
38+
Rule checks for the following conditions:
39+
40+
- Paths must follow a pattern where resource names and path parameters strictly alternate
41+
- Even-indexed path segments should be resource names (not path parameters)
42+
- Odd-indexed path segments should be path parameters
43+
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
44+
3645
#### xgen-IPA-102-collection-identifier-camelCase
3746

3847
![warn](https://img.shields.io/badge/warning-yellow)
@@ -54,6 +63,16 @@ Collection identifiers must be in camelCase.
5463
![warn](https://img.shields.io/badge/warning-yellow)
5564
Collection identifiers must begin with a lowercase letter and contain only ASCII letters and numbers.
5665

66+
##### Implementation details
67+
Rule checks for the following conditions:
68+
69+
- All path segments that are not path parameters must match pattern `/^[a-z][a-zA-Z0-9]*$/`
70+
- Path parameters (inside curly braces) are excluded from validation
71+
- Custom methods (segments containing colons) are excluded from validation
72+
- Paths with `x-xgen-IPA-exception` for this rule are excluded from validation
73+
- Each non-parameter path segment must start with a lowercase letter followed by any combination of ASCII letters and numbers
74+
75+
5776

5877
### IPA-104
5978

tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function resourceBelongsToSingleParent(resourcePath) {
159159
return isPathParam(parentResourceSection);
160160
}
161161

162+
// TODO move prefixes to be rule arguments
162163
function removePrefix(path) {
163164
if (path.startsWith(AUTH_PREFIX)) {
164165
return path.slice(AUTH_PREFIX.length);

0 commit comments

Comments
 (0)