Skip to content

Commit d0aba4a

Browse files
feat(ipa): error on unneeded exceptions IPA 105-107 (#878)
1 parent 85953df commit d0aba4a

22 files changed

+45
-272
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ testRule('xgen-IPA-106-create-method-request-body-is-get-method-response', [
563563
content: {
564564
'application/vnd.atlas.2023-01-01+json': {
565565
schema: {
566-
$ref: '#/components/schemas/SchemaTwoResponse',
566+
$ref: '#/components/schemas/SchemaThree',
567567
},
568568
},
569569
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,15 +681,15 @@ testRule('xgen-IPA-107-update-method-request-body-is-get-method-response', [
681681
content: {
682682
'application/vnd.atlas.2023-01-01+json': {
683683
schema: {
684-
$ref: '#/components/schemas/SchemaTwoRequest',
684+
$ref: '#/components/schemas/SchemaThree',
685685
},
686686
'x-xgen-IPA-exception': {
687687
'xgen-IPA-107-update-method-request-body-is-get-method-response': 'reason',
688688
},
689689
},
690690
'application/vnd.atlas.2024-01-01+json': {
691691
schema: {
692-
$ref: '#/components/schemas/SchemaTwoRequest',
692+
$ref: '#/components/schemas/SchemaThree',
693693
},
694694
'x-xgen-IPA-exception': {
695695
'xgen-IPA-107-update-method-request-body-is-get-method-response': 'reason',

tools/spectral/ipa/ipa-spectral.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ overrides:
129129
- '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D'
130130
rules:
131131
xgen-IPA-104-get-method-response-has-no-input-fields: 'off'
132+
- files: # To be removed in CLOUDP-337392
133+
- '**#/paths/~1api~1atlas~1v2~1groups~1%7BgroupId%7D~1pushBasedLogExport'
134+
rules:
135+
xgen-IPA-106-create-method-request-has-no-readonly-fields: 'off'

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import {
44
getResourcePathItems,
55
isResourceCollectionIdentifier,
66
} from './utils/resourceEvaluation.js';
7-
import { hasException } from './utils/exceptions.js';
8-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
7+
import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js';
98

109
const RULE_NAME = 'xgen-IPA-105-resource-has-list';
1110
const ERROR_MESSAGE = 'APIs must provide a List method for resources.';
@@ -17,16 +16,8 @@ export default (input, _, { path, documentInventory }) => {
1716
return;
1817
}
1918

20-
if (hasException(oas.paths[input], RULE_NAME)) {
21-
collectException(oas.paths[input], RULE_NAME, path);
22-
return;
23-
}
24-
2519
const errors = checkViolationsAndReturnErrors(oas.paths[input], input, path);
26-
if (errors.length !== 0) {
27-
return collectAndReturnViolation(path, RULE_NAME, errors);
28-
}
29-
collectAdoption(path, RULE_NAME);
20+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, oas.paths[input], path);
3021
};
3122

3223
function checkViolationsAndReturnErrors(pathItem, input, path) {

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { hasException } from './utils/exceptions.js';
2-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
1+
import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js';
32
import {
43
getResourcePathItems,
54
isResourceCollectionIdentifier,
@@ -20,17 +19,9 @@ export default (input, _, { path, documentInventory }) => {
2019
return;
2120
}
2221

23-
if (hasException(input, RULE_NAME)) {
24-
collectException(input, RULE_NAME, path);
25-
return;
26-
}
27-
2822
const errors = checkViolationsAndReturnErrors(input, path);
2923

30-
if (errors.length !== 0) {
31-
return collectAndReturnViolation(path, RULE_NAME, errors);
32-
}
33-
collectAdoption(path, RULE_NAME);
24+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path);
3425
};
3526

3627
function checkViolationsAndReturnErrors(getOperationObject, path) {

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ import {
44
isSingletonResource,
55
} from './utils/resourceEvaluation.js';
66
import { resolveObject } from './utils/componentUtils.js';
7-
import { hasException } from './utils/exceptions.js';
8-
import {
9-
collectAdoption,
10-
collectAndReturnViolation,
11-
collectException,
12-
handleInternalError,
13-
} from './utils/collectionUtils.js';
7+
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
148
import { getSchemaRef, getSchemaNameFromRef, getResponseOfGetMethodByMediaType } from './utils/methodUtils.js';
159
import { schemaIsPaginated } from './utils/schemaUtils.js';
1610

@@ -38,11 +32,6 @@ export default (input, _, { path, documentInventory }) => {
3832
return;
3933
}
4034

41-
if (hasException(listMethodResponse, RULE_NAME)) {
42-
collectException(listMethodResponse, RULE_NAME, path);
43-
return;
44-
}
45-
4635
// Get list response schema from ref or inline schema
4736
let resolvedListSchema;
4837
const listSchemaRef = getSchemaRef(listMethodResponse.schema);
@@ -70,11 +59,7 @@ export default (input, _, { path, documentInventory }) => {
7059
getMethodResponseContentPerMediaType
7160
);
7261

73-
if (errors.length !== 0) {
74-
return collectAndReturnViolation(path, RULE_NAME, errors);
75-
}
76-
77-
collectAdoption(path, RULE_NAME);
62+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, listMethodResponse, path);
7863
};
7964

8065
function checkViolationsAndReturnErrors(path, listMethodResultItems, getMethodResponseContent) {

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { hasException } from './utils/exceptions.js';
2-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
1+
import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js';
32
import {
43
getResourcePathItems,
54
isResourceCollectionIdentifier,
@@ -21,15 +20,7 @@ export default (input, _, { path, documentInventory }) => {
2120
) {
2221
return;
2322
}
24-
if (hasException(input, RULE_NAME)) {
25-
collectException(input, RULE_NAME, path);
26-
return;
27-
}
2823

2924
const errors = checkResponseCodeAndReturnErrors(input, '200', path, RULE_NAME, ERROR_MESSAGE);
30-
31-
if (errors.length !== 0) {
32-
return collectAndReturnViolation(path, RULE_NAME, errors);
33-
}
34-
return collectAdoption(path, RULE_NAME);
25+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path);
3526
};

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import { hasException } from './utils/exceptions.js';
2-
import {
3-
collectAdoption,
4-
collectAndReturnViolation,
5-
collectException,
6-
handleInternalError,
7-
} from './utils/collectionUtils.js';
1+
import { evaluateAndCollectAdoptionStatus, handleInternalError } from './utils/collectionUtils.js';
82
import { getResourcePathItems } from './utils/resourceEvaluation.js';
93
import { isInvalidListMethod } from './utils/methodLogic.js';
104
import { hasCustomMethodOverride, hasMethodVerbOverride, VERB_OVERRIDE_EXTENSION } from './utils/extensions.js';
@@ -25,23 +19,13 @@ export default (input, { methodName }, { path, documentInventory }) => {
2519
return;
2620
}
2721

28-
if (hasException(input, RULE_NAME)) {
29-
collectException(input, RULE_NAME, path);
30-
return;
31-
}
32-
3322
if (hasMethodVerbOverride(input, methodName)) {
3423
methodName = input[VERB_OVERRIDE_EXTENSION].verb;
3524
}
3625

3726
try {
3827
const errors = validateOperationIdAndReturnErrors(methodName, resourcePath, input, path);
39-
40-
if (errors.length > 0) {
41-
return collectAndReturnViolation(path, RULE_NAME, errors);
42-
}
43-
44-
return collectAdoption(path, RULE_NAME);
28+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, input, path);
4529
} catch (e) {
4630
return handleInternalError(RULE_NAME, path, e);
4731
}

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
isSingletonResource,
66
} from './utils/resourceEvaluation.js';
77
import { resolveObject } from './utils/componentUtils.js';
8-
import { hasException } from './utils/exceptions.js';
9-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
8+
import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js';
109
import { getResponseOfGetMethodByMediaType } from './utils/methodUtils.js';
1110
import { checkRequestResponseResourceEqualityAndReturnErrors } from './utils/validations/checkRequestResponseResourceEqualityAndReturnErrors.js';
1211

@@ -43,11 +42,6 @@ export default (input, _, { path, documentInventory }) => {
4342
return;
4443
}
4544

46-
if (hasException(postRequestContentPerMediaType, RULE_NAME)) {
47-
collectException(postRequestContentPerMediaType, RULE_NAME, path);
48-
return;
49-
}
50-
5145
const postRequestContentPerMediaTypeUnresolved = resolveObject(unresolvedOas, path);
5246
const getResponseContentPerMediaTypeUnresolved = getResponseOfGetMethodByMediaType(
5347
mediaType,
@@ -65,10 +59,5 @@ export default (input, _, { path, documentInventory }) => {
6559
'Get',
6660
ERROR_MESSAGE
6761
);
68-
69-
if (errors.length !== 0) {
70-
return collectAndReturnViolation(path, RULE_NAME, errors);
71-
}
72-
73-
collectAdoption(path, RULE_NAME);
62+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, postRequestContentPerMediaType, path);
7463
};

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { hasException } from './utils/exceptions.js';
2-
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
1+
import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js';
32
import {
43
getResourcePathItems,
54
isCustomMethodIdentifier,
@@ -27,15 +26,6 @@ export default (input, _, { path, documentInventory }) => {
2726
return;
2827
}
2928

30-
if (hasException(contentPerMediaType, RULE_NAME)) {
31-
collectException(contentPerMediaType, RULE_NAME, path);
32-
return;
33-
}
34-
3529
const errors = checkSchemaRefSuffixAndReturnErrors(path, contentPerMediaType, 'Request', RULE_NAME);
36-
37-
if (errors.length !== 0) {
38-
return collectAndReturnViolation(path, RULE_NAME, errors);
39-
}
40-
collectAdoption(path, RULE_NAME);
30+
return evaluateAndCollectAdoptionStatus(errors, RULE_NAME, contentPerMediaType, path);
4131
};

0 commit comments

Comments
 (0)