main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports.default = eachOperation;
|
---|
5 | // iterate over each operation, and fire a callback with details
|
---|
6 | // `find=true` will stop iterating, when the cb returns truthy
|
---|
7 | function eachOperation(spec, cb, find) {
|
---|
8 | if (!spec || typeof spec !== 'object' || !spec.paths || typeof spec.paths !== 'object') {
|
---|
9 | return null;
|
---|
10 | }
|
---|
11 | const {
|
---|
12 | paths
|
---|
13 | } = spec;
|
---|
14 |
|
---|
15 | // Iterate over the spec, collecting operations
|
---|
16 | // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
---|
17 | for (const pathName in paths) {
|
---|
18 | // eslint-disable-next-line no-restricted-syntax, guard-for-in
|
---|
19 | for (const method in paths[pathName]) {
|
---|
20 | if (method.toUpperCase() === 'PARAMETERS') {
|
---|
21 | continue; // eslint-disable-line no-continue
|
---|
22 | }
|
---|
23 | const operation = paths[pathName][method];
|
---|
24 | if (!operation || typeof operation !== 'object') {
|
---|
25 | continue; // eslint-disable-line no-continue
|
---|
26 | }
|
---|
27 | const operationObj = {
|
---|
28 | spec,
|
---|
29 | pathName,
|
---|
30 | method: method.toUpperCase(),
|
---|
31 | operation
|
---|
32 | };
|
---|
33 | const cbValue = cb(operationObj);
|
---|
34 | if (find && cbValue) {
|
---|
35 | return operationObj;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 | return undefined;
|
---|
40 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.