forked from fnogatz/xsd2json
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
36 lines (31 loc) · 1.26 KB
/
index.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
/**
* Main for the node-xsd2json project.
*
* The function used by the command line interface is the xsd2json function.
* Other functions are internals exposed for a potential API usage.
*/
var xml2js = require('xml2js');
var xsdInclusions = require('./lib/xsd-inclusions');
var xsdExtensions = require('./lib/xsd-extensions');
var prologWrapper = require('./lib/prolog-wrapper');
var jsonProcessing = require('./lib/json-processing');
/**
* @param [string] filePath - the path to the XSD schema file that needs to be translated into JSON schema
*/
exports.xsd2json = function(filePath, callback) {
xsdInclusions.mergeInclusions('./', filePath, function(err, schema) {
if (err) return callback(err);
var mergedSchema = xsdExtensions.mergeExtensions(schema);
var builder = new xml2js.Builder();
var xml = builder.buildObject(mergedSchema);
prologWrapper.xsd2jsonWrapper(xml, function(err, schema) {
if (err) return callback(err);
callback(null, jsonProcessing.postProcessing(schema));
});
});
};
// Internals exposed for API usage
exports.mergeInclusions = xsdInclusions.mergeInclusions;
exports.mergeExtensions = xsdExtensions.mergeExtensions;
exports.xsd2jsonWrapper = prologWrapper.xsd2jsonWrapper;
exports.postProcessing = jsonProcessing.postProcessing;