diff options
| author | Marak <[email protected]> | 2016-02-08 16:50:19 +0530 |
|---|---|---|
| committer | Marak <[email protected]> | 2016-02-08 16:50:52 +0530 |
| commit | ab9a3efe1d524c3f3fa5d5784d2cdeb68ae5a2ae (patch) | |
| tree | 709ce115437e46e6df59cfe51584c33af4343890 | |
| parent | 0dc76d3cec4adaa981f110654a48a8a8c5630331 (diff) | |
| download | faker-ab9a3efe1d524c3f3fa5d5784d2cdeb68ae5a2ae.tar.xz faker-ab9a3efe1d524c3f3fa5d5784d2cdeb68ae5a2ae.zip | |
[dist] Integrate in-line schemas #170
* Attempts to load any available in-line schemas
* Falls back to using method signature
* Defaults to any type
| -rw-r--r-- | build/generateMschema.js | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/build/generateMschema.js b/build/generateMschema.js index af795891..8718fdb8 100644 --- a/build/generateMschema.js +++ b/build/generateMschema.js @@ -24,39 +24,48 @@ schema.methodSchemas = { }; items.forEach(function(item){ - // schema[item] = {}; schema.modules.enum.push(item); for (var q in faker[item]) { //console.log(item + '.' + q); + + // check to see if an existing schema existing on the function var fnLine = faker[item][q].toString().split('\n').slice(0,1)[0]; var prop; - // find first ( - var start = fnLine.search(/\(/); + if (typeof faker[item][q].schema === "object") { + // if so, we'll want to merge that onto the exported schemas here + prop = faker[item][q].schema; + } else { + // if not, fall back to the ones we can parse from the method itself - // find first ) - var end = fnLine.search(/\)/); + // find first ( + var start = fnLine.search(/\(/); - // substr on those positions - fnLine = fnLine.substr(start + 1, end - start - 1) + // find first ) + var end = fnLine.search(/\)/); - 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" + // 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 = {}; + prop.properties = {}; + fnLine.forEach(function(arg){ + prop.properties[arg] = { + type: "any" + }; + }); + } } + schema.methods.enum.push(item + '.' + q); schema.methodSchemas[item + '.' + q] = prop; } |
