Created
January 3, 2017 22:50
-
-
Save turadg/98cd98eb893f96c6dcbf7399772144da to your computer and use it in GitHub Desktop.
Generate a tab delimited table of endpoints on a Swagger-described API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* | |
For Swagger 1.2 docs format. | |
Hardcode the base path in the urlFor() function. | |
Assumes Node 6+. | |
*/ | |
const rp = require('request-promise'); | |
const urlFor = path => `https://api.remind.com${path}`; | |
function logGroup(groupDoc) { | |
for (const api of groupDoc.apis) { | |
for (const operation of api.operations) { | |
console.log(api.path, '\t', operation.httpMethod, '\t', operation.summary); | |
} | |
} | |
} | |
function fetchAndLogGroup(groupDocPath) { | |
rp(urlFor(groupDocPath)) | |
.then(str => JSON.parse(str)) | |
.then(logGroup); | |
} | |
function walkRoot(rootDoc) { | |
const groupPromises = rootDoc.apis.map(api => fetchAndLogGroup(api.path)); | |
return Promise.all(groupPromises); | |
} | |
function fetchAndLogRoot() { | |
rp(urlFor('/v2/docs.json')) | |
.then(str => JSON.parse(str)) | |
.then(walkRoot); | |
} | |
fetchAndLogRoot(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment