swagger-mock-parser
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -45,3 +45,3 @@ 'use strict'; | ||
var iterations = chance.integer(options); | ||
var iterations = this.parser.options && this.parser.options.fixedArray ? 1 : chance.integer(options); | ||
var ret = []; | ||
@@ -48,0 +48,0 @@ |
@@ -43,13 +43,18 @@ 'use strict'; | ||
schema = schema.properties; | ||
this.cache.push(node); | ||
for (var k in schema) { | ||
// detect and fix circular references in schema and return null object | ||
if (this.cache.filter(function (cacheObj) { | ||
return node == cacheObj; | ||
}).length > 2) { | ||
ret[k] = {}; | ||
this.cache.pop(); | ||
return ret; | ||
} else { | ||
ret[k] = this.parser.parse(schema[k]); | ||
this.cache.push(schema); | ||
// if is not swagger object type return null object | ||
if (schema) { | ||
var hasCircular = this.cache.filter(function (cacheObj) { | ||
return schema == cacheObj; | ||
}).length > 1; | ||
for (var k in schema) { | ||
// detect and break circular references in schema and return null object | ||
if (hasCircular) { | ||
schema[k] = {}; | ||
hasCircular = false; | ||
this.cache.pop(); | ||
break; | ||
} else { | ||
ret[k] = this.parser.parse(schema[k]); | ||
} | ||
} | ||
@@ -56,0 +61,0 @@ } |
{ | ||
"name": "swagger-mock-parser", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "use chance.js to parse definition schema to mock data", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
# swagger-mock-parser | ||
A parser for swagger object properties ,mock data returned by chancejs | ||
##changeLog | ||
version 1.1.8 change: add useExample option,set this true parser will return defined example first | ||
version 1.1.7 break change: return string instead of throw error,objectParser canParse add "node.type == object" judge condition | ||
## changeLog | ||
### version 1.1.13 | ||
add fixedArray option,set this true ,array parser will return only one child array | ||
### version 1.1.12 | ||
detect and fix circular references in schema and return null object | ||
### version 1.1.8 ~ 1.1.11 | ||
add useExample option,set this true parser will return defined example first | ||
### version 1.1.7 | ||
break change: return string instead of throw error,objectParser canParse add "node.type == object" judge condition | ||
## usage | ||
@@ -10,0 +18,0 @@ |
@@ -24,3 +24,3 @@ import Chance from 'chance'; | ||
let iterations = chance.integer(options); | ||
let iterations = (this.parser.options && this.parser.options.fixedArray)? 1 : chance.integer(options) ; | ||
let ret = []; | ||
@@ -27,0 +27,0 @@ |
@@ -19,13 +19,20 @@ import Chance from 'chance'; | ||
var ret = {}; | ||
var schema = Object.assign({},node); | ||
var schema = Object.assign({}, node); | ||
schema = schema.properties; | ||
this.cache.push(node); | ||
for (var k in schema) { | ||
// detect and fix circular references in schema and return null object | ||
if (this.cache.filter(cacheObj => { return node == cacheObj}).length > 2) { | ||
ret[k] = {}; | ||
this.cache.pop(); | ||
return ret; | ||
} else { | ||
ret[k] = this.parser.parse(schema[k]); | ||
this.cache.push(schema); | ||
// if is not swagger object type return null object | ||
if (schema) { | ||
var hasCircular = this.cache.filter(function (cacheObj) { | ||
return schema == cacheObj; | ||
}).length > 1 | ||
for (var k in schema) { | ||
// detect and break circular references in schema and return null object | ||
if (hasCircular){ | ||
schema[k] = {}; | ||
hasCircular = false; | ||
this.cache.pop(); | ||
break; | ||
} else { | ||
ret[k] = this.parser.parse(schema[k]); | ||
} | ||
} | ||
@@ -32,0 +39,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35373
26
721
89