Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cbaf505
CLOUDP-328955: Switched from ember-inflector to inflection
Jul 3, 2025
eba0010
CLOUDP-328959: Added helper method for stripping custom method names
Jul 4, 2025
06d1ca1
CLOUDP-328959: Implemented basic Operation ID Validation for create o…
Jul 4, 2025
f6ff5dd
CLOUDP-328959: Implemented basic Operation ID Validation for delete o…
Jul 4, 2025
53692d8
CLOUDP-328959: Implemented basic Operation ID Validation for update o…
Jul 4, 2025
98cc8a1
Update tools/spectral/ipa/rulesets/functions/IPA108ValidOperationID.js
sphterry Jul 7, 2025
6360e10
CLOUDP-328959: Fixed error handling pattern
Jul 7, 2025
f47ef0a
CLOUDP-328959: Added more verbose error messages
Jul 7, 2025
5e7a26e
CLOUDP-328959: Added exception handling and removed used variables
Jul 7, 2025
1b8e593
Merge branch 'main' into CLOUDP-328959
Jul 7, 2025
ff9eb08
CLOUDP-328959: 'prettier' new line
Jul 7, 2025
d17c7b6
CLOUDP-328959: Fixed exceptions and imports
Jul 7, 2025
60197ca
CLOUDP-328959: Added opID validation yaml for IPA106 and fixed lint e…
Jul 7, 2025
769a4a0
CLOUDP-328959: Added opID validation yaml for IPA107 and fixed lint e…
Jul 7, 2025
11f4aab
CLOUDP-328959: Added opID validation yaml for IPA108 and fixed lint e…
Jul 7, 2025
ae54d57
CLOUDP-328959: Updated docs
Jul 7, 2025
ff7df80
CLOUDP-328959: Added tests for validating IPA106 valid operationIds
Jul 8, 2025
277cb19
CLOUDP-328959: Added tests for validating IPA108 valid operationIds
Jul 8, 2025
bb78336
CLOUDP-328959: comment out unlaunched test
Jul 8, 2025
fcef3e4
CLOUDP-328959: Added tests for validating IPA107 valid operationIds
Jul 8, 2025
50fa6db
CLOUDP-328959: Added early returns and removed reference to custom me…
Jul 8, 2025
5262142
CLOUDP-328959: Edits
Jul 9, 2025
1eee9f3
Merge branch 'main' into CLOUDP-328959
Jul 9, 2025
ecb2e28
CLOUDP-328959: prettier
Jul 9, 2025
3f4fc95
CLOUDP-328959: doc update
Jul 9, 2025
29c55c4
CLOUDP-328959: Added methodName to functionOptions
Jul 9, 2025
6a9a67d
CLOUDP-328959: Update docs, remove unused schema, add customMethod check
Jul 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"precommit": "husky install"
},
"jest": {
"transformIgnorePatterns": [
"/node_modules/(?!ember-inflector/)"
],
"transform": {
"^.+\\.[t|j]sx?$": "babel-jest"
},
Expand All @@ -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"
Expand All @@ -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.4",
"lint-staged": "^16.1.2",
"prettier": "3.6.2",
"brace-expansion": "4.0.1"
"prettier": "3.6.2"
},
"engineStrict": false,
"engines": {
Expand Down
82 changes: 82 additions & 0 deletions tools/spectral/ipa/__tests__/IPA106ValidOperationID.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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

const componentSchemas = {
schemas: {
Schema: {
type: 'object',
},
},
operationId: 'string',
};

testRule('xgen-IPA-106-valid-operation-id', [
{
name: 'valid methods',
document: {
components: componentSchemas,
paths: {
'/groups/{groupId}/clusters': {
post: {
operationId: 'createGroupCluster',
},
},
},
},
errors: [],
},
// This test will be enable when the xgen-IPA-106-valid-operation-id is set to warning severity - CLOUDP-329722
/* {
name: 'invalid methods',
document: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/access': {
post: {
operationId: 'addUserToProject',
},
},
'/api/atlas/v2/groups/{groupId}/invites': {
post: {
operationId: 'createProjectInvitation',
},
},
},
},
errors: [
{
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. ',
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. ',
path: ['paths', '/api/atlas/v2/groups/{groupId}/invites', 'post'],
severity: DiagnosticSeverity.Warning,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just asking to learn:
I’m not fully sure how severity: off behaves. Does it completely disable the rule, or does it still run but return errors with DiagnosticSeverity.Off?
If it’s the first case, can we assume the rule isn't being tested at all?

Copy link
Contributor Author

@sphterry sphterry Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity off still runs the rule but hides the errors, which is what i want here until the package and extension are supported (ie: closer to the time of correction). The rule isn't being tested because it's not active yet, but I have run the tests on error and warning severity and they pass.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Thanks ❤️

},
],
}, */
{
name: 'invalid methods with exceptions',
document: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
post: {
operationId: 'createRollingIndex',
'x-xgen-IPA-exception': {
'xgen-IPA-106-valid-operation-id': 'Reason',
},
},
},
},
},
errors: [],
},
]);
88 changes: 88 additions & 0 deletions tools/spectral/ipa/__tests__/IPA107ValidOperationID.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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

const componentSchemas = {
schemas: {
Schema: {
type: 'object',
},
},
operationId: 'string',
};

testRule('xgen-IPA-107-valid-operation-id', [
{
name: 'valid methods',
document: {
components: componentSchemas,
paths: {
'groups/{groupId}/clusters/{clusterName}': {
put: {
operationId: 'updateGroupCluster',
},
},
'/groups/{groupId}/settings': {
put: {
operationId: 'updateGroupSettings',
},
},
},
},
errors: [],
},
// This test will be enable when the xgen-IPA-107-valid-operation-id is set to warning severity - CLOUDP-329722
/* {
name: 'invalid methods',
document: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/limits/{limitName}': {
patch: {
operationId: 'setProjectLimit',
},
},
'/api/atlas/v2/groups/{groupId}/settings': {
put: {
operationId: 'updateProjectSettings',
},
},
},
},
errors: [
{
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.',
path: ['paths', '/api/atlas/v2/groups/{groupId}/limits/{limitName}', 'patch'],
severity: DiagnosticSeverity.Warning,
},
{
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.',
path: ['paths', '/api/atlas/v2/groups/{groupId}/settings', 'put'],
severity: DiagnosticSeverity.Warning,
},
],
}, */
{
name: 'invalid methods with exceptions',
document: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
post: {
operationId: 'updateRollingIndex',
'x-xgen-IPA-exception': {
'xgen-IPA-107-valid-operation-id': 'Reason',
},
},
},
},
},
errors: [],
},
]);
82 changes: 82 additions & 0 deletions tools/spectral/ipa/__tests__/IPA108ValidOperationID.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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

const componentSchemas = {
schemas: {
Schema: {
type: 'object',
},
},
operationId: 'string',
};

testRule('xgen-IPA-108-valid-operation-id', [
{
name: 'valid methods',
document: {
components: componentSchemas,
paths: {
'/groups/{groupId}/clusters/{clusterName}': {
delete: {
operationId: 'deleteGroupCluster',
},
},
},
},
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: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/apiKeys/{apiUserId}': {
delete: {
operationId: 'removeProjectApiKey',
},
},
'/api/atlas/v2/groups/{groupId}': {
delete: {
operationId: 'deleteProject',
},
},
},
},
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. ',
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. ',
path: ['paths', '/api/atlas/v2/groups/{groupId}', 'delete'],
severity: DiagnosticSeverity.Warning,
},
],
}, */
{
name: 'invalid methods with exceptions',
document: {
components: componentSchemas,
paths: {
'/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/index ': {
post: {
operationId: 'deleteRollingIndex',
'x-xgen-IPA-exception': {
'xgen-IPA-108-valid-operation-id': 'Reason',
},
},
},
},
},
errors: [],
},
]);
17 changes: 17 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-106.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ functions:
- IPA106CreateMethodRequestHasNoReadonlyFields
- IPA106CreateMethodResponseCodeIs201Created
- IPA106CreateMethodResponseIsGetMethodResponse
- IPA106ValidOperationID

aliases:
CreateOperationObject:
Expand Down Expand Up @@ -112,3 +113,19 @@ rules:
then:
field: '@key'
function: 'IPA106CreateMethodResponseIsGetMethodResponse'
xgen-IPA-106-valid-operation-id:
description: |
Confirms that the existing operationId is compliant with generated IPA Compliant OperationId.

##### Implementation details
Rule checks for the following conditions:
- Applies only to POST methods on resource collection paths
- Generates the expected OperationId given the resource identifier
- Compares the generated IPA Compliant OperationId with the existing OperationId
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-106-valid-operation-id'
severity: off
given: '#CreateOperationObject'
then:
function: 'IPA106ValidOperationID'
functionOptions:
methodName: 'create'
17 changes: 17 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-107.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ functions:
- IPA107UpdateMethodRequestHasNoReadonlyFields
- IPA107UpdateMethodRequestBodyIsGetResponse
- IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject
- IPA107ValidOperationID

aliases:
UpdateOperationObject:
Expand Down Expand Up @@ -112,3 +113,19 @@ rules:
then:
field: '@key'
function: 'IPA107UpdateMethodRequestBodyIsUpdateRequestSuffixedObject'
xgen-IPA-107-valid-operation-id:
description: |
Confirms that the existing operationId is compliant with generated IPA Compliant OperationId.

##### Implementation details
Rule checks for the following conditions:
- Validation checks the PATCH/PUT methods for single resource paths and [singleton resources](https://go/ipa/113).
- Generates the expected OperationId given the resource identifier
- Compares the generated IPA Compliant OperationId with the existing OperationId
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-valid-operation-id'
severity: off
given: '#UpdateOperationObject'
then:
function: 'IPA107ValidOperationID'
functionOptions:
methodName: 'update'
17 changes: 17 additions & 0 deletions tools/spectral/ipa/rulesets/IPA-108.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,25 @@ rules:
given: '#DeleteOperationObject'
then:
function: IPA108DeleteMethodNoRequestBody
xgen-IPA-108-valid-operation-id:
description: |
Confirms that the existing operationId is compliant with generated IPA Compliant OperationId.

##### Implementation details
Rule checks for the following conditions:
- Applies to all DELETE methods for single resource endpoints (with path parameters)
- Generates the expected OperationId given the resource identifier
- Compares the generated IPA Compliant OperationId with the existing OperationId
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-108-valid-operation-id'
severity: off
given: '#DeleteOperationObject'
then:
function: 'IPA108ValidOperationID'
functionOptions:
methodName: 'delete'

functions:
- IPA108DeleteMethodResponseShouldNotHaveSchema
- IPA108DeleteMethod204Response
- IPA108DeleteMethodNoRequestBody
- IPA108ValidOperationID
Loading
Loading