From 1fa55ed78c52833600d41e4ef741fd4d42814c0a Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 3 Jul 2025 18:21:26 +0100 Subject: [PATCH 1/9] CLOUDP-328955: Switched from ember-inflector to inflection --- package-lock.json | 10 ++++++++++ package.json | 8 +++----- .../rulesets/functions/utils/operationIdGeneration.js | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 79c92439b4..bf55ad55b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "dotenv": "^17.0.1", "ember-inflector": "^6.0.0", "eslint-plugin-jest": "^29.0.1", + "inflection": "^3.0.2", "markdown-table": "^3.0.4", "openapi-to-postmanv2": "5.0.0", "parquet-wasm": "^0.6.1" @@ -8373,6 +8374,15 @@ "node": ">=0.8.19" } }, + "node_modules/inflection": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-3.0.2.tgz", + "integrity": "sha512-+Bg3+kg+J6JUWn8J6bzFmOWkTQ6L/NHfDRSYU+EVvuKHDxUDHAXgqixHfVlzuBQaPOTac8hn43aPhMNk6rMe3g==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", diff --git a/package.json b/package.json index 4a1c3a3d81..42232f00f3 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,6 @@ "precommit": "husky install" }, "jest": { - "transformIgnorePatterns": [ - "/node_modules/(?!ember-inflector/)" - ], "transform": { "^.+\\.[t|j]sx?$": "babel-jest" }, @@ -36,6 +33,7 @@ "dotenv": "^17.0.1", "ember-inflector": "^6.0.0", "eslint-plugin-jest": "^29.0.1", + "inflection": "^3.0.2", "markdown-table": "^3.0.4", "openapi-to-postmanv2": "5.0.0", "parquet-wasm": "^0.6.1" @@ -49,14 +47,14 @@ "aws-sdk-client-mock": "^4.1.0", "babel-jest": "^30.0.2", "babel-plugin-transform-import-meta": "^2.3.3", + "brace-expansion": "4.0.1", "eslint": "^9.30.1", "eslint-plugin-require-extensions": "^0.1.3", "globals": "^16.3.0", "husky": "^9.1.7", "jest": "^30.0.3", "lint-staged": "^16.1.2", - "prettier": "3.6.2", - "brace-expansion": "4.0.1" + "prettier": "3.6.2" }, "engineStrict": false, "engines": { diff --git a/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js b/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js index b2ded2a7bc..12ee3cfe98 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js +++ b/tools/spectral/ipa/rulesets/functions/utils/operationIdGeneration.js @@ -1,4 +1,4 @@ -import { singularize } from 'ember-inflector'; +const inflection = require('inflection'); import { isPathParam, removePrefix, isSingleResourceIdentifier } from './resourceEvaluation.js'; const CAMEL_CASE = /[A-Z]?[a-z]+/g; @@ -29,12 +29,12 @@ export function generateOperationID(method, path) { let opID = verb; for (let i = 0; i < nouns.length - 1; i++) { - opID += singularize(nouns[i]); + opID += inflection.singularize(nouns[i]); } // singularize final noun, dependent on resource identifier if (isSingleResourceIdentifier(resourceIdentifier) || verb === 'create') { - nouns[nouns.length - 1] = singularize(nouns[nouns.length - 1]); + nouns[nouns.length - 1] = inflection.singularize(nouns[nouns.length - 1]); } opID += nouns.pop(); From 5a895391baa4505d70249b83e1b1a11f3779a22f Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Fri, 4 Jul 2025 14:49:57 +0100 Subject: [PATCH 2/9] CLOUDP-328959: Added helper method for stripping custom method names --- .../ipa/rulesets/functions/utils/resourceEvaluation.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js b/tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js index e872646ee1..ede0257308 100644 --- a/tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js +++ b/tools/spectral/ipa/rulesets/functions/utils/resourceEvaluation.js @@ -57,6 +57,10 @@ export function getCustomMethodName(path) { return path.split(':')[1]; } +export function stripCustomMethodName(path){ + return path.substring(0, path.indexOf(':')); +} + export function isPathParam(string) { return string.startsWith('{') && string.endsWith('}'); } From b47587b9c7892210dd85399ed1936ba30c05963e Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Wed, 9 Jul 2025 09:14:42 +0100 Subject: [PATCH 3/9] CLOUDP-328960: testing custom method filtering --- tools/spectral/ipa/rulesets/IPA-109.yaml | 9 ++++ .../functions/IPA109ValidOperationID.js | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js diff --git a/tools/spectral/ipa/rulesets/IPA-109.yaml b/tools/spectral/ipa/rulesets/IPA-109.yaml index 7433a0da69..aac73eb309 100644 --- a/tools/spectral/ipa/rulesets/IPA-109.yaml +++ b/tools/spectral/ipa/rulesets/IPA-109.yaml @@ -5,6 +5,7 @@ functions: - IPA109EachCustomMethodMustBeGetOrPost - IPA109EachCustomMethodMustUseCamelCase - IPA109CustomMethodIdentifierFormat + - IPA109ValidOperationID rules: xgen-IPA-109-custom-method-must-be-GET-or-POST: @@ -56,3 +57,11 @@ rules: given: '$.paths[*]' then: function: 'IPA109CustomMethodIdentifierFormat' + xgen-IPA-109-valid-operation-id: + description: | + Test + message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-custom-method-identifier-format' + severity: warn + given: '$.paths[*]' + then: + function: 'IPA109ValidOperationID' diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js new file mode 100644 index 0000000000..3d01b42e13 --- /dev/null +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -0,0 +1,41 @@ +import { hasException } from './utils/exceptions.js'; +import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js'; +import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } from './utils/resourceEvaluation.js'; +import { generateOperationID } from './utils/operationIdGeneration.js'; + +const RULE_NAME = 'xgen-IPA-109-valid-operation-id'; +const ERROR_MESSAGE = 'Invalid Operation ID'; + +export default (input, _, { path }) => { + let resourcePath = path[1]; + + if (!isCustomMethodIdentifier(resourcePath)) { + return; + } + //console.log(resourcePath); + + if (hasException(input, RULE_NAME)) { + collectException(input, RULE_NAME, path); + return; + } + + //console.log(input['post'].operationId) + // TODO detect custom method extension - CLOUDP-306294 + let methodName = getCustomMethodName(resourcePath); + resourcePath = stripCustomMethodName(resourcePath); + const operationId = input.post.operationId; + + const expectedOperationID = generateOperationID(methodName, resourcePath); + if (expectedOperationID !== operationId) { + console.log(operationId, expectedOperationID) + const errors = [ + { + path, + message: `${ERROR_MESSAGE} Found ${operationId}, expected ${expectedOperationID}.`, + }, + ]; + return collectAndReturnViolation(path, RULE_NAME, errors); + } + + collectAdoption(path, RULE_NAME); +}; From 7701e0b66d423e82dea36a7a7b42588d15d66954 Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 09:43:54 +0100 Subject: [PATCH 4/9] CLOUDP-328960: custom method opID validation for :action notation --- .../functions/IPA109ValidOperationID.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js index 3d01b42e13..a39cdeaee3 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -8,26 +8,29 @@ const ERROR_MESSAGE = 'Invalid Operation ID'; export default (input, _, { path }) => { let resourcePath = path[1]; + const methodName = getCustomMethodName(resourcePath); if (!isCustomMethodIdentifier(resourcePath)) { return; } - //console.log(resourcePath); if (hasException(input, RULE_NAME)) { collectException(input, RULE_NAME, path); return; } - //console.log(input['post'].operationId) // TODO detect custom method extension - CLOUDP-306294 - let methodName = getCustomMethodName(resourcePath); - resourcePath = stripCustomMethodName(resourcePath); - const operationId = input.post.operationId; - const expectedOperationID = generateOperationID(methodName, resourcePath); + let obj; + if (input.post) { + obj = input.post; + } else if (input.get) { + obj = input.get; + } + + const operationId = obj.operationId; + const expectedOperationID = generateOperationID(methodName, stripCustomMethodName(resourcePath)); if (expectedOperationID !== operationId) { - console.log(operationId, expectedOperationID) const errors = [ { path, From 1f5e7598fbb164c8a6219480c733dc69b828d5f1 Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 09:47:44 +0100 Subject: [PATCH 5/9] CLOUDP-328960: Updated docs & error format --- tools/spectral/ipa/rulesets/IPA-109.yaml | 17 ++++++++++++++--- tools/spectral/ipa/rulesets/README.md | 16 ++++++++++++++++ .../functions/IPA109ValidOperationID.js | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/tools/spectral/ipa/rulesets/IPA-109.yaml b/tools/spectral/ipa/rulesets/IPA-109.yaml index aac73eb309..57ef4a97c2 100644 --- a/tools/spectral/ipa/rulesets/IPA-109.yaml +++ b/tools/spectral/ipa/rulesets/IPA-109.yaml @@ -59,9 +59,20 @@ rules: function: 'IPA109CustomMethodIdentifierFormat' xgen-IPA-109-valid-operation-id: description: | - Test - message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-custom-method-identifier-format' - severity: warn + The Operation ID must start with the custom method verb (the custom method path section delimited by the colon (:) character) and should be followed by a noun or compound noun. + If the custom Operation ID has a verb + noun, the Operation ID should end with the noun. + The noun(s) in the Operation ID should be the collection identifiers from the resource identifier. + The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun: + - Is in plural form if the method applies to a collection of resources + - Is in singular form if the method applies to a single resource + + ##### Implementation details + Rule checks for the following conditions: + - Applies only to paths containing custom method identifiers (with colon format) + - Generates the expected OperationId given the resource identifier and the method name portion following the colon + - Confirms that the existing operationId is compliant with generated IPA Compliant OperationId + message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-109-valid-operation-id' + severity: off given: '$.paths[*]' then: function: 'IPA109ValidOperationID' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 3c613bf5b3..877c58ae12 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -496,6 +496,22 @@ Rule checks for the following conditions: - Fails if multiple colons appear in the path - Fails if other than an alphabetical character or a closing curly brace appears before a colon +#### xgen-IPA-109-valid-operation-id + + `off` +The Operation ID must start with the custom method verb (the custom method path section delimited by the colon (:) character) and should be followed by a noun or compound noun. +If the custom Operation ID has a verb + noun, the Operation ID should end with the noun. +The noun(s) in the Operation ID should be the collection identifiers from the resource identifier. +The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun: + - Is in plural form if the method applies to a collection of resources + - Is in singular form if the method applies to a single resource + +##### Implementation details +Rule checks for the following conditions: + - Applies only to paths containing custom method identifiers (with colon format) + - Generates the expected OperationId given the resource identifier and the method name portion following the colon + - Confirms that the existing operationId is compliant with generated IPA Compliant OperationId + ### IPA-110 diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js index a39cdeaee3..02fd3f06e4 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -4,7 +4,7 @@ import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } import { generateOperationID } from './utils/operationIdGeneration.js'; const RULE_NAME = 'xgen-IPA-109-valid-operation-id'; -const ERROR_MESSAGE = 'Invalid Operation ID'; +const ERROR_MESSAGE = 'Invalid Operation ID.'; export default (input, _, { path }) => { let resourcePath = path[1]; From e4a662a80ad6b064299d2f12643e983a88ac15fb Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 11:12:56 +0100 Subject: [PATCH 6/9] CLOUDP-328960: Added tests for custom method rule --- .../__tests__/IPA108ValidOperationID.test.js | 11 ++- .../__tests__/IPA109ValidOperationID.test.js | 75 +++++++++++++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tools/spectral/ipa/__tests__/IPA109ValidOperationID.test.js diff --git a/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js index 7a311e0f65..2774e7bc2e 100644 --- a/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js @@ -1,4 +1,5 @@ import testRule from './__helpers__/testRule'; +import { DiagnosticSeverity } from '@stoplight/types'; // TODO: add tests for xgen-custom-method extension - CLOUDP-306294 // TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722 @@ -18,7 +19,7 @@ testRule('xgen-IPA-108-valid-operation-id', [ errors: [], }, // This test will be enable when the xgen-IPA-108-valid-operation-id is set to warning severity - CLOUDP-329722 - /* { + { name: 'invalid methods', document: { paths: { @@ -37,20 +38,18 @@ testRule('xgen-IPA-108-valid-operation-id', [ errors: [ { code: 'xgen-IPA-108-valid-operation-id', - message: - 'Invalid OperationID. The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ', + message: 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}', 'delete'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-108-valid-operation-id', - message: - 'Invalid OperationID. The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ', + message: 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}', 'delete'], severity: DiagnosticSeverity.Warning, }, ], - }, */ + }, { name: 'invalid methods with exceptions', document: { diff --git a/tools/spectral/ipa/__tests__/IPA109ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA109ValidOperationID.test.js new file mode 100644 index 0000000000..378d29fa5b --- /dev/null +++ b/tools/spectral/ipa/__tests__/IPA109ValidOperationID.test.js @@ -0,0 +1,75 @@ +import testRule from './__helpers__/testRule'; + +// TODO: add tests for xgen-custom-method extension - CLOUDP-306294 +// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722 + +testRule('xgen-IPA-109-valid-operation-id', [ + { + name: 'valid methods', + document: { + paths: { + '/groups/{groupId}/clusters/{clusterName}:pause': { + post: { + operationId: 'pauseGroupCluster', + }, + }, + '/groups/{groupId}/clusters/{clusterName}:addNode': { + post: { + operationId: 'addGroupClusterNode', + }, + }, + }, + }, + errors: [], + }, + // This test will be enable when the xgen-IPA-109-valid-operation-id is set to warning severity - CLOUDP-329722 + /* { + name: 'invalid methods', + document: { + paths: { + '/api/atlas/v2/groups/{groupId}/clusters:search': { + post: { + operationId: 'searchClusters', + }, + }, + '/api/atlas/v2/groups/{groupId}:migrate': { + post: { + operationId: 'migrateProjectToAnotherOrg', + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-109-valid-operation-id', + message: + 'Invalid OperationID. ', + path: ['paths', '/api/atlas/v2/groups/{groupId}/clusters:search'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-109-valid-operation-id', + message: + 'Invalid OperationID. ', + path: ['paths', '/api/atlas/v2/groups/{groupId}:migrate'], + severity: DiagnosticSeverity.Warning, + }, + ], + }, */ + { + name: 'invalid methods with exceptions', + document: { + paths: { + '/api/atlas/v2/orgs/{orgId}/users/{userId}:addRole': { + post: { + operationId: 'addOrgRole', + 'x-xgen-IPA-exception': { + 'xgen-IPA-109-valid-operation-id': 'Reason', + }, + }, + }, + }, + }, + errors: [], + }, +]); From df2c41b3a8063a3ccc06a5450a871d0a565b7318 Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 11:15:22 +0100 Subject: [PATCH 7/9] CLOUDP-328960: Fixed tests to match error messages --- .../ipa/__tests__/IPA104ValidOperationID.test.js | 4 ++-- .../ipa/__tests__/IPA105ValidOperationID.test.js | 4 ++-- .../ipa/__tests__/IPA106ValidOperationID.test.js | 4 ++-- .../ipa/__tests__/IPA107ValidOperationID.test.js | 2 +- .../ipa/__tests__/IPA108ValidOperationID.test.js | 5 ++--- .../ipa/rulesets/functions/IPA109ValidOperationID.js | 12 ++++++------ 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js index cff141067a..5794894f5c 100644 --- a/tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA104ValidOperationID.test.js @@ -38,14 +38,14 @@ testRule('xgen-IPA-104-valid-operation-id', [ { code: 'xgen-IPA-104-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/accessList/{entryValue}/status', 'get'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-104-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/limits/{limitName}', 'get'], severity: DiagnosticSeverity.Warning, }, diff --git a/tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js index eda4656182..4b057da052 100644 --- a/tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA105ValidOperationID.test.js @@ -38,14 +38,14 @@ testRule('xgen-IPA-105-valid-operation-id', [ { code: 'xgen-IPA-105-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/databaseUsers/{username}/certs', 'get'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-105-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/orgs/{orgId}/events', 'get'], severity: DiagnosticSeverity.Warning, }, diff --git a/tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js index 4d03acc02b..717622120c 100644 --- a/tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js @@ -38,14 +38,14 @@ testRule('xgen-IPA-106-valid-operation-id', [ { code: 'xgen-IPA-106-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “create” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/access', 'post'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-106-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “create” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. ', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/invites', 'post'], severity: DiagnosticSeverity.Warning, }, diff --git a/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js index a157366ba2..ef0d9780b7 100644 --- a/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js @@ -43,7 +43,7 @@ testRule('xgen-IPA-107-valid-operation-id', [ { code: 'xgen-IPA-107-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “update” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. For singleton resources - the last noun may be in plural form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/limits/{limitName}', 'patch'], severity: DiagnosticSeverity.Warning, }, diff --git a/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js index 2774e7bc2e..442da86325 100644 --- a/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js @@ -1,5 +1,4 @@ import testRule from './__helpers__/testRule'; -import { DiagnosticSeverity } from '@stoplight/types'; // TODO: add tests for xgen-custom-method extension - CLOUDP-306294 // TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722 @@ -19,7 +18,7 @@ testRule('xgen-IPA-108-valid-operation-id', [ errors: [], }, // This test will be enable when the xgen-IPA-108-valid-operation-id is set to warning severity - CLOUDP-329722 - { + /* { name: 'invalid methods', document: { paths: { @@ -49,7 +48,7 @@ testRule('xgen-IPA-108-valid-operation-id', [ severity: DiagnosticSeverity.Warning, }, ], - }, + }, */ { name: 'invalid methods with exceptions', document: { diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js index 02fd3f06e4..7b302560d9 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -4,7 +4,7 @@ import { isCustomMethodIdentifier, getCustomMethodName, stripCustomMethodName } import { generateOperationID } from './utils/operationIdGeneration.js'; const RULE_NAME = 'xgen-IPA-109-valid-operation-id'; -const ERROR_MESSAGE = 'Invalid Operation ID.'; +const ERROR_MESSAGE = 'Invalid OperationID.'; export default (input, _, { path }) => { let resourcePath = path[1]; @@ -14,11 +14,6 @@ export default (input, _, { path }) => { return; } - if (hasException(input, RULE_NAME)) { - collectException(input, RULE_NAME, path); - return; - } - // TODO detect custom method extension - CLOUDP-306294 let obj; @@ -28,6 +23,11 @@ export default (input, _, { path }) => { obj = input.get; } + if (hasException(obj, RULE_NAME)) { + collectException(obj, RULE_NAME, path); + return; + } + const operationId = obj.operationId; const expectedOperationID = generateOperationID(methodName, stripCustomMethodName(resourcePath)); if (expectedOperationID !== operationId) { From 1a556b8f5d2747b69c1e194672d7cac3373167f7 Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 11:49:32 +0100 Subject: [PATCH 8/9] CLOUDP-328960: Missing test error correction --- tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js b/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js index ef0d9780b7..abc58e5fce 100644 --- a/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js +++ b/tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js @@ -50,7 +50,7 @@ testRule('xgen-IPA-107-valid-operation-id', [ { code: 'xgen-IPA-107-valid-operation-id', message: - 'Invalid OperationID. The Operation ID must start with the verb “update” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. For singleton resources - the last noun may be in plural form.', + 'Invalid OperationID. ', path: ['paths', '/api/atlas/v2/groups/{groupId}/settings', 'put'], severity: DiagnosticSeverity.Warning, }, From 1190090ea71f18752c7f92777a65ec6851bcec26 Mon Sep 17 00:00:00 2001 From: Sophia Marie Terry Date: Thu, 10 Jul 2025 12:03:38 +0100 Subject: [PATCH 9/9] CLOUDP-328960: Graceful return for custom method edge case --- tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js index 7b302560d9..ec3a15f47d 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js +++ b/tools/spectral/ipa/rulesets/functions/IPA109ValidOperationID.js @@ -21,6 +21,8 @@ export default (input, _, { path }) => { obj = input.post; } else if (input.get) { obj = input.get; + } else { + return; } if (hasException(obj, RULE_NAME)) {