This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_to_markdown.js
More file actions
64 lines (45 loc) · 2.03 KB
/
data_to_markdown.js
File metadata and controls
64 lines (45 loc) · 2.03 KB
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
"use-strict"
const fs = require("fs");
const data = JSON.parse(fs.readFileSync("./API.json", "utf8"));
let output = "";
// Start
output += "<!-- markdownlint-disable MD012 -->" + "\n" + "# API documentation" + "\n\n";
// Table of content
output += "- [API documentation](#api-documentation)\n";
for (const entity in data) {
let chapterName = entity;
let link = chapterName.toLowerCase().replace(' ', '-').replace('/', '');
output += ` - [${chapterName}](#${link})\n`;
for (const request in data[entity]) {
let chapterName = data[entity][request].name;
let link = chapterName.toLowerCase().replace(' ', '-').replace('/', '');
output += ` - [${chapterName}](#${link})\n`;
}
}
output += "\n\n <!-- break line -->\n\n"
// Content
for (const entity in data) {
output += `## ${entity}\n`;
output += "\n";
for (const request in data[entity]) {
output += `### ${data[entity][request].name}\n`;
output += "\n";
output += data[entity][request].description != "" ?
`> ${data[entity][request].description}\n` :
"> Description\n";
output += "\n";
output += `**URL** : \`${data[entity][request].url}\`\n`;
output += `**Authentication required** : \`${data[entity][request].authenticationRequired}\`\n`;
output += `**Method** : \`${data[entity][request].method}\`\n`;
output += "\n";
output += "| Key | Required | Default | Type | Description |\n"
output += "| --- | --- | --- | --- | --- |\n"
if (typeof(data[entity][request].body) != "string")
for (const property in data[entity][request].body) {
output += `| ${data[entity][request].body[property].key} | unspecified | unspecified | ${data[entity][request].body[property].type} | ${data[entity][request].body[property].description} |\n`
}
output += "\n---\n\n"; // Request separator
}
output += "\n\n <!-- break line -->\n\n"; // Entity separator
}
console.log(output);