Skip to content

Commit a4c60dc

Browse files
authored
feat(ipa): enable OperationID Validation with warning severity (#871)
1 parent b55f9d0 commit a4c60dc

15 files changed

+761
-77
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
},
2020
"testPathIgnorePatterns": [
2121
"__helpers__",
22-
"metrics/data",
23-
"IPA\\d+ValidOperationID\\.test\\.js$"
22+
"metrics/data"
2423
]
2524
},
2625
"dependencies": {

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

Lines changed: 93 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import testRule from './__helpers__/testRule';
2-
3-
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
4-
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
2+
import { DiagnosticSeverity } from '@stoplight/types';
53

64
testRule('xgen-IPA-104-valid-operation-id', [
75
{
@@ -17,19 +15,33 @@ testRule('xgen-IPA-104-valid-operation-id', [
1715
},
1816
errors: [],
1917
},
20-
// This test will be enable when the xgen-IPA-104-valid-operation-id is set to warning severity - CLOUDP-329722
21-
/* {
22-
name: 'invalid methods',
18+
{
19+
name: 'invalid methods with short opIDs',
2320
document: {
2421
paths: {
25-
'/api/atlas/v2/groups/{groupId}/accessList/{entryValue}/status': {
22+
'/api/atlas/v2/groups/{groupId}/accessList/{entryValue}': {
2623
get: {
27-
operationId: 'getProjectIpAccessListStatus',
24+
operationId: 'getProjectIpList',
2825
},
2926
},
30-
'/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/limits/{limitName}': {
27+
},
28+
},
29+
errors: [
30+
{
31+
code: 'xgen-IPA-104-valid-operation-id',
32+
message: "Invalid OperationID. Found 'getProjectIpList', expected 'getGroupAccessList'. ",
33+
path: ['paths', '/api/atlas/v2/groups/{groupId}/accessList/{entryValue}', 'get', 'operationId'],
34+
severity: DiagnosticSeverity.Warning,
35+
},
36+
],
37+
},
38+
{
39+
name: 'invalid methods with long opIDs',
40+
document: {
41+
paths: {
42+
'/api/atlas/v2/groups/{groupId}/alerts/{alertId}/alertConfigs': {
3143
get: {
32-
operationId: 'returnFederatedDatabaseQueryLimit',
44+
operationId: 'listAlertConfigurationsByAlertId',
3345
},
3446
},
3547
},
@@ -38,19 +50,85 @@ testRule('xgen-IPA-104-valid-operation-id', [
3850
{
3951
code: 'xgen-IPA-104-valid-operation-id',
4052
message:
41-
'Invalid OperationID. ',
42-
path: ['paths', '/api/atlas/v2/groups/{groupId}/accessList/{entryValue}/status', 'get'],
53+
"Invalid OperationID. Found 'listAlertConfigurationsByAlertId', expected 'getGroupAlertAlertConfigs'. ",
54+
path: ['paths', '/api/atlas/v2/groups/{groupId}/alerts/{alertId}/alertConfigs', 'get', 'operationId'],
4355
severity: DiagnosticSeverity.Warning,
4456
},
4557
{
4658
code: 'xgen-IPA-104-valid-operation-id',
4759
message:
48-
'Invalid OperationID. ',
49-
path: ['paths', '/api/atlas/v2/groups/{groupId}/dataFederation/{tenantName}/limits/{limitName}', 'get'],
60+
"The Operation ID is longer than 4 words. Please add an 'x-xgen-operation-id-override' extension to the operation with a shorter operation ID. ",
61+
path: ['paths', '/api/atlas/v2/groups/{groupId}/alerts/{alertId}/alertConfigs', 'get', 'operationId'],
5062
severity: DiagnosticSeverity.Warning,
5163
},
5264
],
53-
}, */
65+
},
66+
{
67+
name: 'valid methods with valid overrides',
68+
document: {
69+
paths: {
70+
'/api/atlas/v2/federationSettings/{federationSettingsId}/connectedOrgConfigs/{orgId}/roleMappings/{id}': {
71+
get: {
72+
operationId: 'getFederationSettingConnectedOrgConfigRoleMapping',
73+
'x-xgen-operation-id-override': 'getRoleMapping',
74+
},
75+
},
76+
},
77+
},
78+
errors: [],
79+
},
80+
{
81+
name: 'valid methods with invalid overrides',
82+
document: {
83+
paths: {
84+
'/api/atlas/v2/federationSettings/{federationSettingsId}/connectedOrgConfigs/{orgId}/roleMappings/{id}': {
85+
get: {
86+
operationId: 'getFederationSettingConnectedOrgConfigRoleMapping',
87+
'x-xgen-operation-id-override': 'getGroupRoleConfig',
88+
},
89+
},
90+
},
91+
},
92+
errors: [
93+
{
94+
code: 'xgen-IPA-104-valid-operation-id',
95+
message:
96+
"The operation ID override must only contain nouns from the operation ID 'getFederationSettingConnectedOrgConfigRoleMapping'. ",
97+
path: [
98+
'paths',
99+
'/api/atlas/v2/federationSettings/{federationSettingsId}/connectedOrgConfigs/{orgId}/roleMappings/{id}',
100+
'get',
101+
'x-xgen-operation-id-override',
102+
],
103+
severity: DiagnosticSeverity.Warning,
104+
},
105+
{
106+
code: 'xgen-IPA-104-valid-operation-id',
107+
message: "The operation ID override must end with the noun 'Mapping'. ",
108+
path: [
109+
'paths',
110+
'/api/atlas/v2/federationSettings/{federationSettingsId}/connectedOrgConfigs/{orgId}/roleMappings/{id}',
111+
'get',
112+
'x-xgen-operation-id-override',
113+
],
114+
severity: DiagnosticSeverity.Warning,
115+
},
116+
],
117+
},
118+
{
119+
name: 'valid method with verb overrides',
120+
document: {
121+
paths: {
122+
'/api/atlas/v2/groups/{groupId}/streams/{tenantName}': {
123+
get: {
124+
operationId: 'getGroupStreamWorkspace',
125+
'x-xgen-method-verb-override': { verb: 'getWorkspace', customMethod: false },
126+
},
127+
},
128+
},
129+
},
130+
errors: [],
131+
},
54132
{
55133
name: 'invalid methods with exceptions',
56134
document: {

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

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import testRule from './__helpers__/testRule';
2-
3-
// TODO: add tests for xgen-custom-method extension - CLOUDP-306294
4-
// TOOD: enable tests for invalid methods (after rules are upgraded to warning) - CLOUDP-329722
2+
import { DiagnosticSeverity } from '@stoplight/types';
53

64
testRule('xgen-IPA-105-valid-operation-id', [
75
{
@@ -17,19 +15,33 @@ testRule('xgen-IPA-105-valid-operation-id', [
1715
},
1816
errors: [],
1917
},
20-
// This test will be enable when the xgen-IPA-105-valid-operation-id is set to warning severity - CLOUDP-329722
21-
/* {
22-
name: 'invalid methods',
18+
{
19+
name: 'invalid methods with short opIDs',
2320
document: {
2421
paths: {
25-
'/api/atlas/v2/orgs/{orgId}/teams/{teamId}/users': {
22+
'/api/atlas/v2/unauth/openapi/versions': {
2623
get: {
27-
operationId: 'listTeamUsers',
24+
operationId: 'getApiVersions',
2825
},
2926
},
30-
'/api/atlas/v2/orgs/{orgId}/events': {
27+
},
28+
},
29+
errors: [
30+
{
31+
code: 'xgen-IPA-105-valid-operation-id',
32+
message: "Invalid OperationID. Found 'getApiVersions', expected 'listOpenapiVersions'. ",
33+
path: ['paths', '/api/atlas/v2/unauth/openapi/versions', 'get', 'operationId'],
34+
severity: DiagnosticSeverity.Warning,
35+
},
36+
],
37+
},
38+
{
39+
name: 'invalid methods with too long opIDs',
40+
document: {
41+
paths: {
42+
'/api/atlas/v2/unauth/controlPlaneIPAddresses': {
3143
get: {
32-
operationId: 'listOrganizationEvents',
44+
operationId: 'returnAllControlPlaneIpAddresses',
3345
},
3446
},
3547
},
@@ -38,19 +50,76 @@ testRule('xgen-IPA-105-valid-operation-id', [
3850
{
3951
code: 'xgen-IPA-105-valid-operation-id',
4052
message:
41-
'Invalid OperationID. ',
42-
path: ['paths', '/api/atlas/v2/groups/{groupId}/databaseUsers/{username}/certs', 'get'],
53+
"Invalid OperationID. Found 'returnAllControlPlaneIpAddresses', expected 'listControlPlaneIPAddresses'. ",
54+
path: ['paths', '/api/atlas/v2/unauth/controlPlaneIPAddresses', 'get', 'operationId'],
4355
severity: DiagnosticSeverity.Warning,
4456
},
4557
{
4658
code: 'xgen-IPA-105-valid-operation-id',
4759
message:
48-
'Invalid OperationID. ',
49-
path: ['paths', '/api/atlas/v2/orgs/{orgId}/events', 'get'],
60+
"The Operation ID is longer than 4 words. Please add an 'x-xgen-operation-id-override' extension to the operation with a shorter operation ID. ",
61+
path: ['paths', '/api/atlas/v2/unauth/controlPlaneIPAddresses', 'get', 'operationId'],
5062
severity: DiagnosticSeverity.Warning,
5163
},
5264
],
53-
}, */
65+
},
66+
{
67+
name: 'valid methods with valid overrides',
68+
document: {
69+
paths: {
70+
'/api/atlas/v2/groups/{groupId}/backup/exportBuckets': {
71+
get: {
72+
operationId: 'listGroupBackupExportBuckets',
73+
'x-xgen-operation-id-override': 'listExportBuckets',
74+
},
75+
},
76+
},
77+
},
78+
errors: [],
79+
},
80+
{
81+
name: 'valid methods with invalid overrides',
82+
document: {
83+
paths: {
84+
'/api/atlas/v2/groups/{groupId}/backup/exportBuckets': {
85+
get: {
86+
operationId: 'listGroupBackupExportBuckets',
87+
'x-xgen-operation-id-override': 'listMyExports',
88+
},
89+
},
90+
},
91+
},
92+
errors: [
93+
{
94+
code: 'xgen-IPA-105-valid-operation-id',
95+
message:
96+
"The operation ID override must only contain nouns from the operation ID 'listGroupBackupExportBuckets'. ",
97+
path: ['paths', '/api/atlas/v2/groups/{groupId}/backup/exportBuckets', 'get', 'x-xgen-operation-id-override'],
98+
severity: DiagnosticSeverity.Warning,
99+
},
100+
{
101+
code: 'xgen-IPA-105-valid-operation-id',
102+
message: "The operation ID override must end with the noun 'Buckets'. ",
103+
path: ['paths', '/api/atlas/v2/groups/{groupId}/backup/exportBuckets', 'get', 'x-xgen-operation-id-override'],
104+
severity: DiagnosticSeverity.Warning,
105+
},
106+
],
107+
},
108+
{
109+
name: 'valid method with verb overrides',
110+
document: {
111+
paths: {
112+
'/api/atlas/v2/groups/{groupId}/serverless': {
113+
get: {
114+
operationId: 'listGroupServerlessInstances',
115+
'x-xgen-method-verb-override': { verb: 'listInstances', customMethod: false },
116+
'x-xgen-operation-id-override': 'listServerlessInstances',
117+
},
118+
},
119+
},
120+
},
121+
errors: [],
122+
},
54123
{
55124
name: 'invalid methods with exceptions',
56125
document: {

0 commit comments

Comments
 (0)