Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit e8d55c8

Browse files
committed
Don't append the url to sampleUrl if it's absolute
See apidoc/apidoc#201
1 parent 3b82b5e commit e8d55c8

File tree

2 files changed

+76
-68
lines changed

2 files changed

+76
-68
lines changed

lib/parsers/api_sample_request.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
var trim = require('../utils/trim');
2-
3-
function parse(content) {
4-
var url = trim(content);
5-
6-
if(url.length === 0)
7-
return null;
8-
9-
return {
10-
url: url
11-
};
12-
}
13-
14-
/**
15-
* Exports
16-
*/
17-
module.exports = {
18-
parse : parse,
19-
path : 'local.sampleRequest',
20-
method: 'push'
21-
};
1+
var trim = require('../utils/trim');
2+
3+
function parse(content) {
4+
var url = trim(content);
5+
6+
if(url.length === 0)
7+
return null;
8+
9+
return {
10+
url: url
11+
};
12+
}
13+
14+
/**
15+
* Exports
16+
*/
17+
module.exports = {
18+
parse : parse,
19+
path : 'local.sampleRequest',
20+
method: 'push'
21+
};

lib/workers/api_sample_request.js

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
1-
/**
2-
* PostProcess
3-
*
4-
* @param {Object[]} parsedFiles
5-
* @param {String[]} filenames
6-
* @param {Object[]} preProcess
7-
* @param {Object} packageInfos
8-
*/
9-
function postProcess(parsedFiles, filenames, preProcess, packageInfos) {
10-
var targetName = 'sampleRequest';
11-
12-
parsedFiles.forEach(function(parsedFile) {
13-
parsedFile.forEach(function(block) {
14-
if (block.local[targetName]) {
15-
var newBlock = [];
16-
block.local[targetName].forEach(function(entry) {
17-
if (entry.url !== 'off') {
18-
// Check if is an internal url
19-
if (packageInfos.sampleUrl && entry.url.length >= 4 && entry.url.substr(0, 4).toLowerCase() !== 'http') {
20-
// Prepend sampleUrl
21-
entry.url = packageInfos.sampleUrl + entry.url;
22-
}
23-
newBlock.push(entry);
24-
}
25-
}); // forEach
26-
27-
if (newBlock.length === 0)
28-
delete block.local[targetName];
29-
else
30-
block.local[targetName] = newBlock;
31-
} else {
32-
if (packageInfos.sampleUrl && block.local && block.local.url) {
33-
block.local[targetName] = [{
34-
'url': packageInfos.sampleUrl + block.local.url
35-
}];
36-
}
37-
}
38-
});
39-
});
40-
}
41-
42-
/**
43-
* Exports
44-
*/
45-
module.exports = {
46-
postProcess: postProcess
47-
};
1+
/**
2+
* PostProcess
3+
*
4+
* @param {Object[]} parsedFiles
5+
* @param {String[]} filenames
6+
* @param {Object[]} preProcess
7+
* @param {Object} packageInfos
8+
*/
9+
function postProcess(parsedFiles, filenames, preProcess, packageInfos) {
10+
var targetName = 'sampleRequest';
11+
12+
parsedFiles.forEach(function(parsedFile) {
13+
parsedFile.forEach(function(block) {
14+
if (block.local[targetName]) {
15+
var newBlock = [];
16+
block.local[targetName].forEach(function(entry) {
17+
if (entry.url !== 'off') {
18+
// Check if is an internal url
19+
if (packageInfos.sampleUrl && entry.url.length >= 4 && entry.url.substr(0, 4).toLowerCase() !== 'http') {
20+
// Prepend sampleUrl
21+
entry.url = packageInfos.sampleUrl + entry.url;
22+
}
23+
newBlock.push(entry);
24+
}
25+
}); // forEach
26+
27+
if (newBlock.length === 0)
28+
delete block.local[targetName];
29+
else
30+
block.local[targetName] = newBlock;
31+
} else {
32+
var url;
33+
if (packageInfos.sampleUrl && block.local && block.local.url) {
34+
// if the block local url is absolute, just use this don't append to the sampleUrl
35+
if (block.local.url.length >= 4 && block.local.url.substr(0, 4).toLowerCase() !== 'http') {
36+
url = packageInfos.sampleUrl + block.local.url;
37+
} else {
38+
url = block.local.url
39+
}
40+
41+
block.local[targetName] = [{
42+
'url': url
43+
}];
44+
}
45+
}
46+
});
47+
});
48+
}
49+
50+
/**
51+
* Exports
52+
*/
53+
module.exports = {
54+
postProcess: postProcess
55+
};

0 commit comments

Comments
 (0)