Skip to content

Instantly share code, notes, and snippets.

@turadg
Created January 3, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turadg/98cd98eb893f96c6dcbf7399772144da to your computer and use it in GitHub Desktop.
Save turadg/98cd98eb893f96c6dcbf7399772144da to your computer and use it in GitHub Desktop.
Generate a tab delimited table of endpoints on a Swagger-described API
#!/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