-
Notifications
You must be signed in to change notification settings - Fork 0
/
parseUrlDocs.js
executable file
·54 lines (48 loc) · 1.88 KB
/
parseUrlDocs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var comments = require('parse-comments');
module.exports = function parseUrlDocs({chain, halObj, name}) {
// check each of the functions in the url chain for HAL documentation
for (var z = 0; z < chain.length; z++) {
// process the comments in the function code
var code = comments(chain[z] + "");
// go over each comment block
for (var j = 0; j < code.length; j++) {
var piece = code[j];
// we only process it if the description starts with `HAL: `
if (piece.description && piece.description.substring(0,5) == "HAL: ") {
piece.description = piece.description.substring(5);
// override the name if set
if (piece.name && name != "self") {
halObj.rel = piece.name;
}
// set the type
halObj.type = piece.type;
// set the deprecation flag
halObj.deprecation = piece.deprecated;
// profile refers to a validation document
// value must be a URL
if (piece.returns && piece.returns[0]) {
halObj.profile = piece.returns[0].description;
}
// title, used by client UI's to know what to put in a button or something
halObj.title = piece.alias;
// description is not in the JSON-HAL spec, but it's useful
halObj.description = piece.description;
// JSON-HAL doesn't specify a way to document parameters
// URI Templates do though
if (piece.params && halObj.href && halObj.href.indexOf("?") == -1) {
halObj.templated = true;
halObj.href += "{?";
for (var a = 0; a < piece.params.length; a++) {
var param = piece.params[a];
halObj.href += param.name || param.description;
if (a != piece.params.length-1) {
halObj.href += ",";
}
}
halObj.href += "}";
}
}
}
halObj.rel = halObj.rel || name;
}
}