Skip to content

Commit 792d407

Browse files
Merge pull request #54 from apiaddicts/develop
Up version to 2.2.0
2 parents 1bfb143 + 527ac80 commit 792d407

6 files changed

+31
-18
lines changed

index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,13 @@ _.forEach(environments, function (element) {
227227
}
228228
}
229229
}
230-
if(global.definition.components.securitySchemes){
231-
console.log('securitySchemes');
230+
if ( element.custom_authorizations_file ) {
231+
require('./src/parser/authorizationRequests.js')(endpointsStage,element.custom_authorizations_file)
232+
} else if(global.definition.components.securitySchemes){
232233
let securityDefinition = require('./src/parser/openapiAuthorizationDefinition.js')(global.definition.components.securitySchemes)
233234
if(securityDefinition){
234-
require('./src/parser/authorizationRequests.js')(endpointsStage,securityDefinition)
235-
} else {
236-
exclude.auth = true
237-
}
235+
require('./src/parser/authorizationRequests.js')(endpointsStage,null,securityDefinition)
236+
}
238237
} else {
239238
// Elimina la cabecera Authorization de las peticiones en Postman
240239
exclude.auth = true

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openapi2postman",
3-
"version": "2.1.0",
3+
"version": "2.2.1",
44
"description": "openapi2postman",
55
"bin": {
66
"o2p": "index.js"

src/generator/testBody.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = function() {
3434
" // Guardar variables en environment",
3535
" // pm.environment.set('nombreVariable', json.data.variable);",
3636
"} catch (e) {",
37-
" pm.test(\"Se esperaba una respuesta JSON\", function() {",
37+
" pm.test(\"A JSON response was expected\", function() {",
3838
" pm.expect(json, \"responseBody no es un JSON\").not.to.be.null;",
3939
" });",
4040
"}",

src/parser/authorizationRequests.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ const path = require('path')
1010

1111
module.exports = function() {
1212

13-
return function get(endpoints,definition){
13+
return function get(endpoints,file, definition){
14+
if(!definition){
15+
16+
try {
17+
definition = JSON.parse(fs.readFileSync(file, 'utf8'));
18+
} catch (e) {
19+
require('../utils/error.js')('error reading auth file ');
20+
}
21+
}
1422
for (let i in definition.item){
1523
definition.item[i].authType = true
1624
// Comprobar que viene un status dentro del objeto aux para cada endpoint de autorización

src/parser/openapiAuthorizationDefinition.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ const _ = require('lodash');
88
module.exports = function() {
99

1010
return function get(oAuthDefinition){
11-
// console.log('oAuthDefinition');
12-
// console.log(oAuthDefinition.oAuth2ClientCredentials.flows);
13-
14-
const data = parseUrl(oAuthDefinition.oAuth2ClientCredentials.flows.clientCredentials.tokenUrl)
11+
let definition
12+
for (const i in oAuthDefinition) {
13+
definition = oAuthDefinition[i];
14+
15+
}
16+
const data = parseUrl(definition.flows)
1517
return generateDefinition(data)
1618
}
1719

@@ -85,13 +87,17 @@ module.exports = function() {
8587
return postmanCollection;
8688
}
8789

88-
function parseUrl(url) {
89-
const urlObject = new URL(url);
90+
function parseUrl(flows) {
91+
let getTokenUrl
92+
for (const i in flows) {
93+
getTokenUrl = flows[i];
94+
}
95+
const urlObject = new URL(getTokenUrl.tokenUrl);
9096
const host = `${urlObject.protocol}//${urlObject.host}`;
9197
const path = urlObject.pathname.split('/').filter(segment => segment);
9298

9399
return {
94-
raw: url,
100+
raw: getTokenUrl.tokenUrl,
95101
host: host,
96102
path: path
97103
};

0 commit comments

Comments
 (0)