-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathparameters.js
102 lines (89 loc) · 2.69 KB
/
parameters.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var _ = require('lodash');
var Markdown = require('markdown-it')();
module.exports = {
parameterSection: function(parameters, hNum, includeInternal) {
var text = _.repeat('#', hNum) + ' Parameters\n';
text += parametersListAsTable(parameters, includeInternal);
return text;
}
}
function parametersListAsTable(parameters, includeInternal) {
var htmlText = '<table class="table-left-col-25">\n';
htmlText += '<tr> <th>Parameter</th> <th>Description</th> <th>Type</th> <th>In</th> </tr>\n';
_.forEach(parameters, function(p) {
if(p['x-internalOnly'] && !includeInternal) {
// Skip interalOnly when not including internal only details
}
else {
if(p.name != undefined) {
htmlText += parameterObjectAsRow(p);
}
else {
htmlText += referenceObjectAsRow(p);
}
}
});
htmlText += '</table>\n';
return htmlText;
};
function referenceObjectAsRow(ref) {
// TODO render REFs properly
return `<tr> <td>[REF](${ref['$ref']})</td> <td></td> <td></td> <td></td> </tr>\n`;
};
/* Renders a ParameterObject inside a <tr>
* http://swagger.io/specification/#parameterObject
*
* name (required) :: string
* in (required) :: string, enum ["query", "header", "path", "formData", "body]
* description :: string
* required :: boolean (default = false)
*
* if (in == "body")
* schema :: SchemaObject
* else
* type (required) :: string
* format :: string
* ... more things, see link above
*/
function parameterObjectAsRow(parameter) {
var rowText = '<tr>';
var required = 'optional';
if(parameter.required) {
required = 'required';
}
rowText += '<td>';
rowText += `<p><code>${parameter.name}</code><br/>`;
rowText += `<em>${required}</em></p>`;
if(parameter.default != undefined) {
rowText += `<p><em>default:</em> <code>${parameter.default}</code></p>`;
}
rowText += '</td>';
var description = '';
if(parameter.description != undefined) {
description = `<div class="description">${Markdown.render(parameter.description)}</div>`;
}
var enumeration = '';
if(parameter.enum) {
enumeration += '<div class="enumeration"><strong>Enum:</strong> ';
enumeration += parameter.enum.map(function(enumItem) {
return `<code>${enumItem}</code>`;
}).join(', ');
enumeration += '</div>';
}
rowText += '<td>';
rowText += description;
rowText += enumeration;
rowText += '</td>';
var type = '';
if(parameter.type != undefined) {
type += `<p>${parameter.type}`;
if(parameter.format != undefined) {
type += `<br><em>${parameter.format}</em>`;
}
type += '</p>';
}
rowText += `<td>${type}</td>`;
rowText += `<td>${parameter.in}</td>`;
rowText += '</tr>\n';
return rowText;
};