Created
April 22, 2019 23:28
-
-
Save niradler/d44ad66b0e3338dfa270a69c534efc8c to your computer and use it in GitHub Desktop.
export docs from apigateway
This file contains 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
//https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getExport-property | |
const fs = require("fs"); | |
const AWS = require("aws-sdk"); | |
const path = require("path"); | |
const apigateway = new AWS.APIGateway({ | |
apiVersion: "2015-07-09", | |
region: "us-east-1" | |
}); | |
const getExport = params => { | |
return new Promise((resolve, reject) => { | |
apigateway.getExport(params, (err, data) => { | |
if (err) { | |
reject(err, err.stack); | |
} else { | |
resolve(data); | |
} | |
}); | |
}); | |
}; | |
(async function() { | |
try { | |
const params = { | |
exportType: "swagger", | |
restApiId: "123", | |
stageName: "prod", | |
parameters: { | |
extensions: "postman" | |
} | |
}; | |
const res = await getExport(params); | |
const file = JSON.parse(res.body); | |
fs.writeFileSync( | |
path.join(process.cwd(), `${file.info.title}.json`), | |
res.body | |
); | |
} catch (error) { | |
console.log(error.message); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment