-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathopenapi2slate.js
executable file
·31 lines (29 loc) · 1.2 KB
/
openapi2slate.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
var _ = require('lodash');
var RefParser = require('json-schema-ref-parser');
var info = require('./info.js');
var responses = require('./responses.js');
var definitions = require('./definitions.js');
var paths = require('./paths.js');
module.exports = {
printSlateMarkdown: function(api, includeInternal, searchFilter) {
RefParser.dereference(api)
.then(function(deRefApi) {
// Info Section
console.log(info.headerWithInfo(api, searchFilter));
// Paths from dereferenced API
var epPaths = paths.addEndpointToPaths(deRefApi.basePath, deRefApi.paths);
if(!includeInternal) {
epPaths = paths.filterInternalTag(epPaths);
}
var groupedEpPaths = paths.groupPathsByTag(epPaths);
console.log(paths.sectionIndexOfGroupedEndpointPaths(groupedEpPaths, includeInternal));
console.log(paths.sectionForGroupedEndpointPaths(groupedEpPaths, includeInternal));
// Responses + Definitions
console.log(responses.responsesSection(api.responses, 1));
console.log(definitions.definitionsObject(api.definitions));
})
.catch(function(err) {
console.error('API dereference failed: ' + err);
});
}
};