Last active
October 4, 2018 07:52
-
-
Save djfdyuruiry/e52c2dd710ac2d419a5c258436907761 to your computer and use it in GitHub Desktop.
NodeJS Script to Generate Postman Collections/Environments for the Alfresco v1 REST API (uses https://www.npmjs.com/package/swagger2-postman-generator)
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
// see: https://www.npmjs.com/package/swagger2-postman-generator | |
const Swagger2Postman = require("swagger2-postman-generator"); | |
function alfrescoRequestPostProcessor(postmanRequest, swaggerSpec) { | |
if (postmanRequest.url.includes("/authentication/versions/1/tickets")) { | |
// add a test post login event to save the ticket to an environment variable | |
postmanRequest.events = [ | |
{ | |
"listen": "test", | |
"script": { | |
"id": "57da8de9-78e9-4796-a310-358c73e74667", | |
"type": "text/javascript", | |
"exec": [ | |
"var CryptoJS = require('crypto-js')", | |
"", | |
"pm.environment.set('ticket', CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(pm.response.json().entry.id)))", | |
"" | |
] | |
} | |
} | |
] | |
} | |
} | |
let apis = ["alfresco-auth", "alfresco-core", "alfresco-search"] | |
apis.forEach(api => { | |
let alfrescoApi = Swagger2Postman.convertSwagger().fromUrl(`https://api-explorer.alfresco.com/api-explorer/definitions/${api}.json`) | |
alfrescoApi.toPostmanCollectionFile(`${api}_postman_collection.json`, { | |
globalHeaders: [ | |
"Authorization: Basic {{ticket}}" | |
], | |
requestPostProcessor: alfrescoRequestPostProcessor | |
}) | |
alfrescoApi.toPostmanEnvironmentFile(`${api}_postman_environment.json`, { | |
environment: { | |
name: `${api} Environment`, | |
customVariables: [{ | |
name: "ticket" | |
}] | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment