Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.