diff --git a/package.json b/package.json index 5a7088a..7458a1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "openapi2postman", - "version": "2.2.6", + "version": "2.2.7", "description": "openapi2postman", "bin": { "o2p": "index.js" diff --git a/src/generator/authorization.js b/src/generator/authorization.js index 9ca5123..ab0f72f 100644 --- a/src/generator/authorization.js +++ b/src/generator/authorization.js @@ -5,7 +5,7 @@ const _ = require('lodash'); module.exports = function() { - + return function get(postmanRequest, status){ if (!postmanRequest.aux.authorization){ return postmanRequest; diff --git a/src/parser/openapiAuthorizationDefinition.js b/src/parser/openapiAuthorizationDefinition.js index 73287fc..a8d2be6 100644 --- a/src/parser/openapiAuthorizationDefinition.js +++ b/src/parser/openapiAuthorizationDefinition.js @@ -6,12 +6,11 @@ const _ = require('lodash'); module.exports = function() { - + return function get(oAuthDefinition){ let definition for (const i in oAuthDefinition) { definition = oAuthDefinition[i]; - } const data = parseUrl(definition.flows) const authKey = _.keys(global.definition.security[0])[0] @@ -27,20 +26,20 @@ module.exports = function() { }, item: [ { - name: "Get OAuth2 Token", + name: `Get OAuth2 Token - ${auth}`, event: [ { listen: "test", script: { id: "7e78bc50-5882-47e1-9920-754befbbbfc5", exec: [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.have.status(200);", - "});", - "", - "var json = pm.response.json();", - "", - `pm.environment.set(\"${auth}\", \"Bearer \"+json.data.access_token);` + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.have.status(200);", + "});", + "", + "var json = pm.response.json();", + "var token = json.access_token || (json.data && json.data.access_token);", + `pm.environment.set("${auth}", "Bearer "+token);` ], type: "text/javascript" } diff --git a/test/generator-authorization.js b/test/generator-authorization.js index 7aed250..70ef8a3 100644 --- a/test/generator-authorization.js +++ b/test/generator-authorization.js @@ -3,7 +3,7 @@ const assert = require('assert'); describe('generator-authorization', () => { - + it('good', () => { let endpoint = require('../seeds/generatorEndpointInitial.json');