-
Notifications
You must be signed in to change notification settings - Fork 0
/
definitions.js
27 lines (24 loc) · 1.08 KB
/
definitions.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
var fs = require('fs');
const { getType } = require('./utils');
var writeFile = fs.writeFile;
exports.genDefinitions = function(definitions, savePath) {
var definintionKeys = Object.keys(definitions);
var output = '// This is generated code do not edit.\n\n';
definintionKeys.forEach(key => {
if (definitions[key].properties) {
output += 'export interface ' + key + ' {\n';
var propertyKeys = Object.keys(definitions[key].properties)
propertyKeys.forEach(property => {
output += ' ' + property + `${definitions[key].required && definitions[key].required.find(x => x == property) ? '' : '?'}: ` + getType(definitions[key].properties[property]) + ';\n';
});
} else if (definitions[key].enum) {
output += 'export enum ' + key + ' {\n';
var propertyKeys = Object.keys(definitions[key].enum)
propertyKeys.forEach(property => {
output += `'e${property}' = ${property},\n`;
});
}
output += '}\n\n';
});
writeFile(savePath + '\\api-definitions.d.ts', output, () => { });
}