forked from Ygilany/paw-apidoc-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ApiDocGenerator.js
executable file
·54 lines (42 loc) · 1.47 KB
/
ApiDocGenerator.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
var handlebars = require('./handlebars');
var utils = require('./utils');
var APIDocGenerator = function () {
this.generate = function (context, requests, options) {
var request = context.getCurrentRequest();
var headers = [];
var params = [];
var response = [];
var responseBody = JSON.parse(request.getLastExchange().responseBody);
if (responseBody.status === `SUCCESS` && responseBody.data) {
extractKeyNamesAndTypes(responseBody.data, response);
}
extractKeyNamesAndTypes(request.headers, headers);
extractKeyNamesAndTypes(request.urlParameters, params);
extractKeyNamesAndTypes(request.jsonBody, params);
var view = {
headers: headers,
params: params,
response: response,
method: request.method,
request_name: request.name,
request_description: request.description,
request_group: request.parent ? request.parent.name : `...`,
url: request.urlBase
};
var template = handlebars.compile(readFile('./ApiDocTemplate.hbs'));
return template(view);
};
};
var extractKeyNamesAndTypes = function (theObj, resultsVariable) {
for (var key in theObj) {
resultsVariable.push({
name: key,
type: utils.getType(theObj[key])
});
}
};
APIDocGenerator.identifier = 'com.ygilany.PawExtensions.apiDocGenerator';
APIDocGenerator.title = 'ApiDoc Paw Generator';
APIDocGenerator.languageHighlighter = 'javascript'; // The Javascript highlighter doesn't highlight :(
APIDocGenerator.fileExtension = 'js';
registerCodeGenerator(APIDocGenerator);