Skip to content
This repository was archived by the owner on Aug 5, 2021. It is now read-only.

Commit 11973b9

Browse files
committed
Add tables with model info
1 parent 6188567 commit 11973b9

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ doc/
2626

2727
# Node
2828
node_modules
29+
source/includes/_models.md

Jenkinsfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ node('node') {
99
stage('build') {
1010
sh 'npm install'
1111
sh 'npm run compile-docs-wrapper'
12+
sh 'npm run generate-model-tables'
1213
sh 'sudo bundle install'
1314
sh 'bundle exec middleman build --clean'
1415
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"name": "api-docs",
33
"version": "1.0.0",
44
"scripts": {
5-
"compile-docs-wrapper": "npx esdoc"
5+
"compile-docs-wrapper": "npx esdoc",
6+
"generate-model-tables": "node scripts/generateTables.js"
67
},
78
"dependencies": {
89
"@mapcreator/maps4news": "^1.4.22",

scripts/generateTables.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const https = require('https');
2+
const fs = require('fs');
3+
4+
function downloadDocs () {
5+
return new Promise((resolve) => {
6+
const docsUrl = "https://api.bleeding.maps4news.com/docs";
7+
8+
https.get(docsUrl, function (res) {
9+
let body = '';
10+
11+
res.on('data', function (chunk) {
12+
body += chunk;
13+
});
14+
15+
res.on('end', function () {
16+
resolve(JSON.parse(body));
17+
});
18+
}).on('error', function (e) {
19+
reject(e);
20+
});
21+
});
22+
}
23+
24+
function getModels (json) {
25+
const models = [];
26+
27+
for (const name in json.components.schemas) {
28+
const model = json.components.schemas[name];
29+
30+
if (model.hasOwnProperty('xml') && model.xml.hasOwnProperty('name')) {
31+
models.push(model);
32+
}
33+
}
34+
35+
return models;
36+
}
37+
38+
function generateTables (models) {
39+
let string = '# Models\n\n';
40+
41+
for (const name in models) {
42+
if (!models.hasOwnProperty(name)) continue;
43+
44+
const model = models[name];
45+
46+
// Add title
47+
string += `## ${model.xml.name}\n\n`;
48+
49+
// Add columns
50+
string += '| Attribute | Type | Description | Searchable | Sortable |\n';
51+
string += '|---|---|---|---|---|\n';
52+
53+
// Add properties
54+
for (const propertyName in model.properties) {
55+
if (!model.properties.hasOwnProperty(propertyName)) continue;
56+
57+
const property = model.properties[propertyName];
58+
59+
string += `| ${propertyName} | ${property.type} | ${property.description} | ${property['x-searchable'] ? 'Yes' : 'No'} | ${property['x-sortable'] ? 'Yes' : 'No'} |\n`
60+
}
61+
62+
string += '\n\n';
63+
}
64+
65+
return string.trimRight();
66+
}
67+
68+
function writeFile(content) {
69+
fs.writeFileSync(`${__dirname}/../source/includes/_models.md`, content);
70+
}
71+
72+
downloadDocs()
73+
.then(getModels)
74+
.then(generateTables)
75+
.then(writeFile);

source/v1/index.html.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ toc_footers:
99
- <a href='https://api.maps4news.com/register'>Sign up for Maps4News</a>
1010
- <a href='https://github.com/lord/slate'>Documentation Powered by Slate</a>
1111

12+
includes:
13+
- models
14+
1215
search: true
1316
---
1417

@@ -266,7 +269,7 @@ So, for example: if the list has 600 items and the `offset` is set to 100, the `
266269

267270
The API supports sorting ascending or descending sorting on multiple columns (separated by a comma) on the resources.
268271

269-
**Sortable columns are whitelisted inside the API, there is currently no documentation on what columns are whitelisted**
272+
**Sortable columns are whitelisted inside the API, look in the model list below for supported columns**
270273

271274
### Searching
272275

0 commit comments

Comments
 (0)