Skip to content

Commit d3deaae

Browse files
author
Sophia Marie Terry
committed
Edit to logic to handle outliers
1 parent 794456c commit d3deaae

File tree

4 files changed

+22
-44
lines changed

4 files changed

+22
-44
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
import { hasException } from './utils/exceptions.js';
22
import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js';
3-
import {
4-
isCustomMethodIdentifier,
5-
isResourceCollectionIdentifier,
6-
isSingletonResource,
7-
getResourcePathItems,
8-
} from './utils/resourceEvaluation.js';
3+
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
94
import { generateOperationID } from './utils/operationIdGeneration.js';
105
import { isLegacyCustomMethod } from './utils/extensions.js';
116

127
const RULE_NAME = 'xgen-IPA-106-valid-operation-id';
138
const ERROR_MESSAGE = 'Invalid OperationID.';
149

15-
export default (input, { methodName }, { path, documentInventory }) => {
10+
export default (input, { methodName }, { path }) => {
1611
const resourcePath = path[1];
17-
const oas = documentInventory.resolved;
18-
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
1912

20-
const isResourceCollection = isResourceCollectionIdentifier(resourcePath) && !isSingletonResource(resourcePaths);
21-
if (isLegacyCustomMethod(input) || isCustomMethodIdentifier(resourcePath) || !isResourceCollection) {
13+
if (isLegacyCustomMethod(input) || isCustomMethodIdentifier(resourcePath)) {
2214
return;
2315
}
2416

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
import { hasException } from './utils/exceptions.js';
22
import { collectAdoption, collectException, collectAndReturnViolation } from './utils/collectionUtils.js';
3-
import {
4-
isSingleResourceIdentifier,
5-
isResourceCollectionIdentifier,
6-
isSingletonResource,
7-
getResourcePathItems,
8-
isCustomMethodIdentifier,
9-
} from './utils/resourceEvaluation.js';
3+
import { isCustomMethodIdentifier } from './utils/resourceEvaluation.js';
104
import { generateOperationID } from './utils/operationIdGeneration.js';
115
import { isLegacyCustomMethod } from './utils/extensions.js';
126

137
const RULE_NAME = 'xgen-IPA-107-valid-operation-id';
148
const ERROR_MESSAGE = 'Invalid OperationID.';
159

16-
export default (input, { methodName }, { path, documentInventory }) => {
10+
export default (input, { methodName }, { path }) => {
1711
const resourcePath = path[1];
18-
const oas = documentInventory.resolved;
19-
const resourcePaths = getResourcePathItems(resourcePath, oas.paths);
2012

21-
if (
22-
isCustomMethodIdentifier(resourcePath) ||
23-
isLegacyCustomMethod(input) ||
24-
(!isSingleResourceIdentifier(resourcePath) &&
25-
!(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(resourcePaths)))
26-
) {
13+
if (isCustomMethodIdentifier(resourcePath) || isLegacyCustomMethod(input)) {
2714
return;
2815
}
2916

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ const ERROR_MESSAGE = 'Invalid OperationID.';
1010
export default (input, { methodName }, { path }) => {
1111
const resourcePath = path[1];
1212

13-
if (
14-
isCustomMethodIdentifier(resourcePath) ||
15-
!isSingleResourceIdentifier(resourcePath) ||
16-
isLegacyCustomMethod(input)
17-
) {
13+
if (isCustomMethodIdentifier(resourcePath) || isLegacyCustomMethod(input)) {
1814
return;
1915
}
2016

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,28 @@ export default (input, _, { path }) => {
3434
}
3535

3636
const operationId = obj.operationId;
37-
errors.push(checkViolationAndReturnError(operationId, expectedOperationID, path));
37+
if (operationId !== expectedOperationID) {
38+
const errors = [
39+
{
40+
path,
41+
message: `${ERROR_MESSAGE} Found ${operationId}, expected ${expectedOperationID}.`,
42+
},
43+
];
44+
return collectAndReturnViolation(path, RULE_NAME, errors);
45+
}
3846
} else if (hasMethodWithVerbOverride(input)) {
3947
const methods = Object.keys(input);
4048
for (let i = 0; i < methods.length; i++) {
4149
let obj = input[methods[i]];
4250
const operationId = obj.operationId;
4351
if (isLegacyCustomMethod(obj)) {
4452
expectedOperationID = generateOperationID(obj['x-xgen-method-verb-override'].verb, resourcePath);
45-
errors.push(checkViolationAndReturnError(operationId, expectedOperationID, path));
53+
if (operationId !== expectedOperationID) {
54+
errors.push({
55+
path,
56+
message: `${ERROR_MESSAGE} Found ${operationId}, expected ${expectedOperationID}.`,
57+
});
58+
}
4659
}
4760
}
4861
} else {
@@ -55,13 +68,3 @@ export default (input, _, { path }) => {
5568

5669
collectAdoption(path, RULE_NAME);
5770
};
58-
59-
function checkViolationAndReturnError(oldOperationID, newOperationID, path) {
60-
if (oldOperationID !== newOperationID) {
61-
return {
62-
path,
63-
message: `${ERROR_MESSAGE} Found ${oldOperationID}, expected ${newOperationID}.`,
64-
};
65-
}
66-
return;
67-
}

0 commit comments

Comments
 (0)