source: node_modules/swagger-client/es/helpers/each-operation.js

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.1 KB
Line 
1// iterate over each operation, and fire a callback with details
2// `find=true` will stop iterating, when the cb returns truthy
3export default function eachOperation(spec, cb, find) {
4 if (!spec || typeof spec !== 'object' || !spec.paths || typeof spec.paths !== 'object') {
5 return null;
6 }
7 const {
8 paths
9 } = spec;
10
11 // Iterate over the spec, collecting operations
12 // eslint-disable-next-line no-restricted-syntax, guard-for-in
13 for (const pathName in paths) {
14 // eslint-disable-next-line no-restricted-syntax, guard-for-in
15 for (const method in paths[pathName]) {
16 if (method.toUpperCase() === 'PARAMETERS') {
17 continue; // eslint-disable-line no-continue
18 }
19 const operation = paths[pathName][method];
20 if (!operation || typeof operation !== 'object') {
21 continue; // eslint-disable-line no-continue
22 }
23 const operationObj = {
24 spec,
25 pathName,
26 method: method.toUpperCase(),
27 operation
28 };
29 const cbValue = cb(operationObj);
30 if (find && cbValue) {
31 return operationObj;
32 }
33 }
34 }
35 return undefined;
36}
Note: See TracBrowser for help on using the repository browser.