-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinfo.js
72 lines (68 loc) · 1.98 KB
/
info.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
var _ = require('lodash');
module.exports = {
headerWithInfo : function(api, search) {
var infoText = mkYamlHeader(api, search);
infoText += `\n# ${api.info.title}\n\n`;
infoText += mkInfoText(api);
return infoText;
}
};
function mkYamlHeader(api, search) {
var infoObject = api.info;
var headerText =
`---
title: ${infoObject.title}
search: ${search}
toc_footers:
- ${infoObject.title}
- <em>Version ${infoObject.version}</em>
- <hr>
- <strong>${infoObject.contact.name}</strong>
- <em>${infoObject.license.name}</em>
- <a href='${infoObject.contact.url}'>${infoObject.contact.url}</a>
- <a href='mailto:${infoObject.contact.email}'>${infoObject.contact.email}</a>
---
`;
return headerText;
}
function mkInfoText(api) {
var infoObject = api.info;
var infoText = '## General Information\n';
if(infoObject.version != undefined) {
infoText += `### Version \`${infoObject.version}\`\n\n`;
}
if(api.schemes != undefined) {
infoText += '### Schemes\n';
_.forEach(api.schemes, function(v,k) {
infoText += '`' + v + '`\n\n';
});
}
if(api.host != undefined && api.basePath != undefined) {
infoText += '\n###Host & base path\n\n';
infoText += `\`${api.host}${api.basePath}/\`\n\n`;
}
if(api.consumes != undefined) {
infoText += '### Consumes\n';
_.forEach(api.consumes, function(v,k) {
infoText += '`' + v + '`\n\n';
});
}
if(api.produces != undefined) {
infoText += '### Produces\n';
_.forEach(api.produces, function(v,k) {
infoText += '`' + v + '`\n\n';
});
}
if(infoObject.termsOfService != undefined) {
infoText += '### Terms of Service\n\n';
infoText += `${infoObject.termsOfService}\n\n`;
}
if(api.externalDocs != undefined) {
infoText += '### External resources\n';
infoText += `[${api.externalDocs.description}](${api.externalDocs.url})\n\n`;
}
if(infoObject.description != undefined) {
infoText += `${infoObject.description}\n`;
}
return infoText;
}