This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
sidebar.js
78 lines (78 loc) · 2.19 KB
/
sidebar.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
const globby = require("globby");
const yaml = require("js-yaml");
const fs = require("fs");
// Use the following to frontload docs
var docs = [
"cloud/cspm/cspm-api",
"cloud/basic-request",
"cloud/api-urls",
"cloud/api-headers",
"cloud/cspm/rate-limits",
"cloud/api-time-range-model",
"cloud/api-integration-config",
"cloud/api-errors",
];
// Change these variables to match your doc path
const relativePath = "cloud/cspm";
const absolutePath = "/api/cloud/cspm";
function genEndpoints() {
const endpoints = [];
var endEndpoints = [];
var pushToEnd = [
"IAM",
"IAMIdp",
"DataSecurityDashboard",
"DataSecurityInventory",
"DataSecuritySettings",
];
// Absolute path from project root
specs = globby.sync(["./static/oas/cspm/*.yaml"], {
absolute: false,
objectMode: true,
deep: 1,
onlyDirectories: false,
});
specs.map((spec) => {
const specContents = fs.readFileSync(spec.path, "utf8");
const data = yaml.load(specContents);
const specSplit = spec.path.split("/");
const categoryLabel = specSplit[specSplit.length - 1].replace(".yaml", "");
const docId = categoryLabel
.replace(/([a-z])([A-Z])/g, "$1-$2")
.replace(/[\s_]+/g, "-")
.toLowerCase();
const paths = data.paths;
var category = {
type: "category",
label: categoryLabel,
};
var items = [`${relativePath}/${docId}`];
for ([path, methods] of Object.entries(paths)) {
for ([method, attributes] of Object.entries(methods)) {
const operationId = attributes.operationId;
const linkLabel = attributes.summary;
const item = {
type: "link",
label: linkLabel,
href: `${absolutePath}/${docId}#operation/${operationId}`,
customProps: {
method: method,
},
};
items.push(item);
}
}
category.items = items;
if (pushToEnd.includes(category.label)) {
endEndpoints.push(category);
} else {
endpoints.push(category);
}
});
return [endpoints, endEndpoints];
}
const [endpoints, endEndpoints] = genEndpoints();
const sidebar = docs.concat(endpoints).concat(endEndpoints);
module.exports = {
sidebar: sidebar,
};