diff --git a/tools/spectral/ipa/__tests__/IPA112AvoidProjectFieldNames.test.js b/tools/spectral/ipa/__tests__/IPA112AvoidProjectFieldNames.test.js index 1bc90d7c09..21642bfc1e 100644 --- a/tools/spectral/ipa/__tests__/IPA112AvoidProjectFieldNames.test.js +++ b/tools/spectral/ipa/__tests__/IPA112AvoidProjectFieldNames.test.js @@ -12,6 +12,8 @@ testRule('xgen-IPA-112-avoid-project-field-names', [ group: { type: 'string' }, groupId: { type: 'string' }, projection: { type: 'number' }, + gcpProjectId: { type: 'string' }, + somethingWithGcpProjectId: { type: 'string' }, }, }, }, diff --git a/tools/spectral/ipa/rulesets/IPA-112.yaml b/tools/spectral/ipa/rulesets/IPA-112.yaml index 45de97d64b..c10298f3b7 100644 --- a/tools/spectral/ipa/rulesets/IPA-112.yaml +++ b/tools/spectral/ipa/rulesets/IPA-112.yaml @@ -13,6 +13,7 @@ rules: Rule checks for the following conditions: - Searches through all schemas in the API definition - Identifies property names that match "project" (case-insensitive) + - Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId") - Reports any instances where these field names are used - Suggests using "group", "groups", or "groupId" as alternatives message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-avoid-project-field-names' @@ -26,3 +27,5 @@ rules: alternative: ['group'] - name: 'projects' alternative: ['groups'] + ignore: + - 'gcp' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 7eab45f343..184732fd1f 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -460,6 +460,7 @@ Schema field names should avoid using "project", "projects", or "projectId". Rule checks for the following conditions: - Searches through all schemas in the API definition - Identifies property names that match "project" (case-insensitive) + - Ignores fields where prohibited words appear with specified words (e.g., "gcpProjectId") - Reports any instances where these field names are used - Suggests using "group", "groups", or "groupId" as alternatives diff --git a/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js b/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js index c24f531b02..c3e0606739 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js +++ b/tools/spectral/ipa/rulesets/functions/IPA112AvoidProjectFieldNames.js @@ -14,6 +14,11 @@ export default (input, options, { path, documentInventory }) => { const oas = documentInventory.resolved; const property = resolveObject(oas, path); + const ignoreList = options?.ignore || []; + if (ignoreList.some((ignoreTerm) => input.toLowerCase().includes(ignoreTerm))) { + return; + } + if (hasException(property, RULE_NAME)) { collectException(property, RULE_NAME, path); return;