forked from kaltura/developer-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLucyBot.js
68 lines (58 loc) · 1.88 KB
/
LucyBot.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
const YAML = require('js-yaml');
const fs = require('fs');
const TARGET_API = process.env.TARGET_API || 'ovp';
const getYAML = function(name) {
return YAML.load(fs.readFileSync(__dirname + '/' + name + '.yml', 'utf8'));
}
const openapi = require('./' + TARGET_API + '.openapi.json');
const config = module.exports = getYAML('base.LucyBot');
const apiConfig = getYAML(TARGET_API + '.LucyBot');
Object.assign(config, apiConfig);
var definitions = openapi.definitions;
var enums = openapi['x-enums'];
function makeItem(def) {
return {definition: def};
}
function makeEnumItem(name) {
var enm = enums[name];
var table = '| Name | Value |\n'
+ '|------|-------|\n';
return {
title: name,
contents: table + enm.oneOf.map(function(s) {
return "| " + s.title + " | " + JSON.stringify(s.enum[0]) + " |";
}).join('\n'),
}
}
if (TARGET_API === 'ott') {
let tagItems = openapi.tags.map(t => ({tag: t.name}));
config.operationNavigation.push({children: tagItems, title: 'Services'});
}
let objectsItem = {title: 'General Objects', children: [], prerender: false};
config.operationNavigation.push(objectsItem);
objectsItem.children.push({
title: "Objects",
children: Object.keys(definitions).filter(function(d) {
return d.indexOf("Filter") === -1;
}).map(makeItem),
});
objectsItem.children.push({
title: "Enums",
children: Object.keys(enums).map(makeEnumItem),
})
objectsItem.children.push({
title: "Filters",
children: Object.keys(definitions).filter(function(d) {
return d.indexOf("Filter") !== -1;
}).map(makeItem),
});
config.operationNavigation.push({
title: "Error Codes",
markdown: "# Error Codes\n\n" + openapi['x-errors'].map(e => {
let str = '* `' + e.name + '`';
if (e.code && e.code !== e.name) str += ' (code: ' + e.code + ')';
let desc = e.message
if (e.message) str += ' - ' + e.message;
return str;
}).join('\n'),
});