Skip to content

Commit e594161

Browse files
IPA-112: Disallow usages of project in the api (Fix: Ignore "gcp") (#587)
1 parent 431ae20 commit e594161

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ testRule('xgen-IPA-112-avoid-project-field-names', [
1212
group: { type: 'string' },
1313
groupId: { type: 'string' },
1414
projection: { type: 'number' },
15+
gcpProjectId: { type: 'string' },
16+
somethingWithGcpProjectId: { type: 'string' },
1517
},
1618
},
1719
},

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rules:
1313
Rule checks for the following conditions:
1414
- Searches through all schemas in the API definition
1515
- Identifies property names that match "project" (case-insensitive)
16+
- Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId")
1617
- Reports any instances where these field names are used
1718
- Suggests using "group", "groups", or "groupId" as alternatives
1819
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-avoid-project-field-names'
@@ -26,3 +27,5 @@ rules:
2627
alternative: ['group']
2728
- name: 'projects'
2829
alternative: ['groups']
30+
ignore:
31+
- 'gcp'

tools/spectral/ipa/rulesets/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ Schema field names should avoid using "project", "projects", or "projectId".
460460
Rule checks for the following conditions:
461461
- Searches through all schemas in the API definition
462462
- Identifies property names that match "project" (case-insensitive)
463+
- Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId")
463464
- Reports any instances where these field names are used
464465
- Suggests using "group", "groups", or "groupId" as alternatives
465466

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ export default (input, options, { path, documentInventory }) => {
1414
const oas = documentInventory.resolved;
1515
const property = resolveObject(oas, path);
1616

17+
const ignoreList = options?.ignore || [];
18+
if (ignoreList.some((ignoreTerm) => input.toLowerCase().includes(ignoreTerm))) {
19+
return;
20+
}
21+
1722
if (hasException(property, RULE_NAME)) {
1823
collectException(property, RULE_NAME, path);
1924
return;

0 commit comments

Comments
 (0)