diff options
| author | Marak <[email protected]> | 2016-02-08 16:32:10 +0530 |
|---|---|---|
| committer | Marak <[email protected]> | 2016-02-08 16:50:52 +0530 |
| commit | 3ccabb88aeeba77700ef289ccb05b81c5040c69f (patch) | |
| tree | 61d05a757dcd8ce4698643b25e08a58141fe3ac3 | |
| parent | 652f2c2c89291dca0d3b03ee686269614a9db622 (diff) | |
| download | faker-3ccabb88aeeba77700ef289ccb05b81c5040c69f.tar.xz faker-3ccabb88aeeba77700ef289ccb05b81c5040c69f.zip | |
[dist] First pass at schema generator #170
* Generates a mschema from faker api
* Useful for auto-documentation
* Starts to provide API contract to all methods
| -rw-r--r-- | build/generateMschema.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/build/generateMschema.js b/build/generateMschema.js new file mode 100644 index 00000000..af795891 --- /dev/null +++ b/build/generateMschema.js @@ -0,0 +1,67 @@ +var faker = require('../'); + +var items = Object.keys(faker); + +items = items.filter(function(i){ + if(['locales', 'definitions', 'locale', 'localeFallback'].indexOf(i) === -1) { + return i; + } +}); + +var schema = { + "methods": { + "type": "string", + "enum": [] + } +}; + +schema.modules = { + "type": "string", + "enum": [] +}; + +schema.methodSchemas = { +}; + +items.forEach(function(item){ + // schema[item] = {}; + + schema.modules.enum.push(item); + for (var q in faker[item]) { + + //console.log(item + '.' + q); + var fnLine = faker[item][q].toString().split('\n').slice(0,1)[0]; + var prop; + + // find first ( + var start = fnLine.search(/\(/); + + // find first ) + var end = fnLine.search(/\)/); + + // substr on those positions + fnLine = fnLine.substr(start + 1, end - start - 1) + + if (fnLine === "") { + //console.log(item + '.' + q, 'no arguments') + prop = { + }; + } else { + // split on , + fnLine = fnLine.split(','); + //console.log(item + '.' + q, fnLine); + prop = {}; + fnLine.forEach(function(arg){ + prop[arg] = { + type: "any" + }; + }); + } + schema.methods.enum.push(item + '.' + q); + schema.methodSchemas[item + '.' + q] = prop; + } + +}); + +var util = require('util'); +console.log(util.inspect(schema, false, null));
\ No newline at end of file |
