-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathoperationIdFormatInflector.js
92 lines (86 loc) · 2.78 KB
/
operationIdFormatInflector.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
getResourcePathItems,
isSingleResourceIdentifier,
isCustomMethodIdentifier,
isSingletonResource,
isResourceCollectionIdentifier,
} from './utils/resourceEvaluation.js';
import {
generateOperationIdForCustomMethod_inflector,
generateOperationIdForStandardMethod_inflector,
} from './utils/generateOperationId.js';
const BASE_PATH = '/api/atlas/v2';
export default (input, _, { path, documentInventory }) => {
const operationId = input;
const oas = documentInventory.resolved;
const operationPath = path[1];
const method = path[2];
const resourcePathItems = getResourcePathItems(operationPath, oas.paths);
if (operationPath === BASE_PATH) {
const expectedOperationId = 'getSystemStatus';
if (operationId !== expectedOperationId) {
return [
{
message: `Invalid operation ID ${operationId}, please change to ${expectedOperationId}`,
},
];
}
return;
}
if (isCustomMethodIdentifier(operationPath)) {
const expectedOperationId = generateOperationIdForCustomMethod_inflector(operationPath);
if (operationId !== expectedOperationId) {
return [
{
message: `Invalid operation ID ${operationId}, please change to ${expectedOperationId}`,
},
];
}
return;
}
let expectedOperationId = '';
switch (method) {
case 'get':
if (isResourceCollectionIdentifier(operationPath)) {
if (isSingletonResource(resourcePathItems)) {
expectedOperationId = generateOperationIdForStandardMethod_inflector(operationPath, 'get', false);
} else {
expectedOperationId = generateOperationIdForStandardMethod_inflector(operationPath, 'list', false);
}
} else {
expectedOperationId = generateOperationIdForStandardMethod_inflector(
operationPath,
'get',
isSingleResourceIdentifier(operationPath)
);
}
break;
case 'post':
expectedOperationId = generateOperationIdForStandardMethod_inflector(operationPath, 'create', true);
break;
case 'patch':
expectedOperationId = generateOperationIdForStandardMethod_inflector(
operationPath,
'update',
!isSingletonResource(resourcePathItems)
);
break;
case 'put':
expectedOperationId = generateOperationIdForStandardMethod_inflector(operationPath, 'update', true);
break;
case 'delete':
expectedOperationId = generateOperationIdForStandardMethod_inflector(operationPath, 'delete', true);
break;
}
if (!expectedOperationId) {
console.error('Unsupported http method');
return;
}
if (operationId !== expectedOperationId) {
return [
{
message: `Invalid operation ID ${operationId}, please change to ${expectedOperationId}`,
},
];
}
};