Skip to content

Commit ba2ccb2

Browse files
Merge pull request #73 from apiaddicts/develop
Develop
2 parents 852c580 + 0abef65 commit ba2ccb2

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ _.forEach(endpointsParsed, function (endpointParsed, i) {
8686
endpointsParsed[i].bodyResponse = require('./src/parser/'+version+'/body.js')(endpointParsed.verb, endpointParsed.path, true)
8787
endpointsParsed[i].authorization = require('./src/parser/authorization.js')(endpointParsed.verb, endpointParsed.path, authorizationTokens)
8888
endpointsParsed[i].queryParams = require('./src/parser/'+version+'/queryParams.js')(endpointParsed.verb, endpointParsed.path)
89+
endpointsParsed[i].headers = require('./src/parser/'+version+'/headers.js')(endpointParsed.verb, endpointParsed.path)
8990
endpointsParsed[i].summary = require('./src/parser/summary.js')(endpointParsed.verb, endpointParsed.path)
9091
endpointsParsed[i].microcks = require('./src/parser/openapi3/microcks.js')(endpointParsed.verb, endpointParsed.path)
9192
});
9293

9394
//GENERATOR-------------------------------- */
9495
let endpointsPostman = [];
9596
const endpoints = require('./src/generator/endpoints.js')(endpointsParsed);
96-
// console.log(endpoints);
9797

9898
_.forEach(endpoints, function (endpoint, i) {
9999
for (let index = 0; index < endpoint.count; index++) {

src/generator/endpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function() {
3636
microcks: endpoint.microcks || false,
3737
request: {
3838
method: endpoint.verb,
39-
header: [],
39+
header: endpoint.headers ? endpoint.headers : [],
4040
body: {
4141
mode: "raw",
4242
raw: ""

src/generator/environmentVariablesNames.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = function() {
4242
if(request.header){
4343
for (let i in request.header){
4444
request.header[i].key = extractVariablesFromString(numerateItem,request.header[i].key,items,itemKeys,id);
45-
request.header[i].value = extractVariablesFromString(numerateItem, request.header[i].value, items, itemKeys, id, request.header[i].key === 'Authorization');
45+
request.header[i].value = typeof request.header[i].value == 'number' || typeof request.header[i].value == 'object' ? request.header[i].value : extractVariablesFromString(numerateItem, request.header[i].value, items, itemKeys, id, request.header[i].key === 'Authorization');
4646
}
4747
}
4848
if (request.body && request.body.raw) {

src/parser/openapi3/headers.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** Part of APIAddicts. See LICENSE fileor full copyright and licensing details. Supported by Madrid Digital and CloudAPPi **/
2+
3+
'use strict'
4+
5+
const _ = require('lodash');
6+
7+
module.exports = function() {
8+
9+
return function get(verb,path){
10+
if (!_.isObject(global.definition.paths)) {
11+
require('../../utils/error.js')('paths is required')
12+
}
13+
14+
let parameters = global.definition.paths[path][_.toLower(verb)]['parameters'];
15+
// parameters = replaceRefs(parameters);
16+
let headers = _.filter(parameters, ['in', 'header'])
17+
const result = []
18+
_.forEach(headers, function(header) {
19+
result.push({
20+
key: header.name,
21+
type: header.schema.type,
22+
required : header.required,
23+
value: getExamples(header)
24+
});
25+
});
26+
return result
27+
};
28+
29+
function getExamples(header) {
30+
if (header.example) {
31+
return header.example
32+
}
33+
else {
34+
if (header.hasOwnProperty('examples')) {
35+
const value = header.examples[Object.keys(header.examples)[0]];
36+
return value[Object.keys(value)[0]];
37+
}
38+
return header.example;
39+
}
40+
}
41+
42+
}()

src/parser/swagger2/headers.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/** Part of APIAddicts. See LICENSE fileor full copyright and licensing details. Supported by Madrid Digital and CloudAPPi **/
2+
3+
'use strict'
4+
5+
const _ = require('lodash');
6+
7+
module.exports = function() {
8+
9+
return function get(verb,path){
10+
if (!_.isObject(global.definition.paths)) {
11+
require('../../utils/error.js')('paths is required')
12+
}
13+
14+
let parameters = global.definition.paths[path][_.toLower(verb)]['parameters'];
15+
// parameters = replaceRefs(parameters);
16+
let headers = _.filter(parameters, ['in', 'header'])
17+
const result = []
18+
_.forEach(headers, function(header) {
19+
result.push({
20+
key: header.name,
21+
type: header.schema.type,
22+
required : header.required,
23+
value: getExamples(header)
24+
});
25+
});
26+
return result
27+
};
28+
29+
function getExamples(header) {
30+
if (header.example) {
31+
return header.example
32+
}
33+
else {
34+
if (header.hasOwnProperty('examples')) {
35+
const value = header.examples[Object.keys(header.examples)[0]];
36+
return value[Object.keys(value)[0]];
37+
}
38+
return header.example;
39+
}
40+
}
41+
42+
}()

0 commit comments

Comments
 (0)