Comparing version 0.0.4 to 0.0.5
@@ -0,1 +1,6 @@ | ||
# v0.0.5 | ||
- exclusive limit issue #27 and multipleOf max value enhancement #26 | ||
- mock gen issue for type number with minimum =0 #28 | ||
# v0.0.4 | ||
@@ -2,0 +7,0 @@ ## Features |
@@ -103,6 +103,6 @@ 'use strict'; | ||
if (Util.isInteger(schema.minimum)) { | ||
opts.min = (schema.exclusiveMinimum) ? schema.minimum : schema.minimum + 1; | ||
opts.min = (schema.exclusiveMinimum) ? schema.minimum + 1 : schema.minimum; | ||
} | ||
if (Util.isInteger(schema.maximum)) { | ||
opts.max = (schema.exclusiveMaximum) ? schema.maximum : schema.maximum - 1; | ||
opts.max = (schema.exclusiveMaximum) ? schema.maximum - 1 : schema.maximum; | ||
} | ||
@@ -112,5 +112,7 @@ //Generate a number that is multiple of schema.multipleOf | ||
//Use the muplilier as the min number | ||
opts.min = schema.multipleOf; | ||
//Use the max/muplilier as the new max value | ||
opts.max = (Util.isInteger(opts.max)) ? (Math.floor(opts.max/schema.multipleOf)) : opts.max; | ||
//Use default min as 1 if min is not properly set. | ||
opts.min = (Number.isInteger(opts.min)) ? (Math.ceil(opts.min / schema.multipleOf)) : 1; | ||
//Use the max/muplilier as the new max value. | ||
//Use a default - min + 10 - if max value is not properly set. | ||
opts.max = (Number.isInteger(opts.max)) ? (Math.floor(opts.max / schema.multipleOf)) : (opts.min + 10); | ||
intmock = Chance.integer(opts); | ||
@@ -140,15 +142,18 @@ intmock = intmock * schema.multipleOf; | ||
if (schema.minimum) { | ||
opts.min = (schema.exclusiveMinimum) ? schema.minimum : schema.minimum + 0.1; | ||
if (Util.isFinite(schema.minimum)) { | ||
opts.min = (schema.exclusiveMinimum) ? schema.minimum + 0.1 : schema.minimum; | ||
} | ||
if (schema.maximum) { | ||
opts.max = (schema.exclusiveMaximum) ? schema.maximum : schema.maximum - 0.1; | ||
if (Util.isFinite(schema.maximum)) { | ||
opts.max = (schema.exclusiveMaximum) ? schema.maximum - 0.1 : schema.maximum; | ||
} | ||
//Generate a number that is multiple of schema.multipleOf | ||
if (schema.multipleOf > 0) { | ||
//Use the muplilier as the min number | ||
opts.min = schema.multipleOf; | ||
if (Util.isFinite(schema.multipleOf) && schema.multipleOf > 0) { | ||
//Use the min/muplilier as the min number | ||
//Use default min as 1 if min is not properly set | ||
opts.min = (Number.isFinite(opts.min)) ? (Math.ceil(opts.min / schema.multipleOf)) : 1; | ||
//Use the max/muplilier as the new max value | ||
opts.max = (opts.max) ? opts.max/schema.multipleOf : opts.max; | ||
nummock = Chance.floating(opts); | ||
//Use a default - min + 10 - if max value is not properly set. | ||
opts.max = (Number.isFinite(opts.max)) ? (Math.floor(opts.max / schema.multipleOf)) : (opts.min + 10); | ||
nummock = Chance.integer(opts); | ||
nummock = nummock * schema.multipleOf; | ||
@@ -155,0 +160,0 @@ } else { |
@@ -13,1 +13,5 @@ 'use strict'; | ||
}; | ||
module.exports.isFinite = function(value) { | ||
return typeof value === 'number' && isFinite(value); | ||
}; |
{ | ||
"name": "swagmock", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Mock data generator for swagger api", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -187,2 +187,4 @@ { | ||
"type": "integer", | ||
"minimum": 1000, | ||
"maximum": 2000, | ||
"format": "int64" | ||
@@ -197,2 +199,21 @@ }, | ||
"pattern": "awesome+ (pet|cat|bird)" | ||
}, | ||
{ | ||
"name": "petWeight", | ||
"in": "query", | ||
"description": "Weight of pet to return", | ||
"required": false, | ||
"type": "number", | ||
"minimum": 10, | ||
"maximum": 500 | ||
}, | ||
{ | ||
"name": "bmi", | ||
"in": "query", | ||
"description": "bmi of the pet", | ||
"required": false, | ||
"type": "number", | ||
"minimum": 0, | ||
"maximum": 1, | ||
"multipleOf": 0.2 | ||
}], | ||
@@ -299,2 +320,6 @@ "responses": { | ||
"type": "integer", | ||
"exclusiveMinimum": true, | ||
"exclusiveMaximum": true, | ||
"minimum": 1000, | ||
"maximum": 1010, | ||
"format": "int64" | ||
@@ -764,2 +789,5 @@ }, { | ||
"type": "integer", | ||
"multipleOf": 100, | ||
"minimum": 1000, | ||
"exclusiveMinimum": true, | ||
"format": "int32", | ||
@@ -766,0 +794,0 @@ "description": "User Status" |
var Assert = require('assert'); | ||
var Swagmock = require('../lib'); | ||
var Path = require('path') | ||
var Path = require('path'); | ||
var Util = require('../lib/util'); | ||
//isInteger pollyfil for pre es6 | ||
@@ -25,3 +26,3 @@ Number.isInteger = Number.isInteger || function(value) { | ||
Assert.ok(params.path[0].name === 'orderId', 'generated mock parameter for orderId'); | ||
Assert.ok(params.path[0].value > 0 && params.path[0].value < 10, 'OK value for orderId'); | ||
Assert.ok(params.path[0].value >= 1 && params.path[0].value <= 10, 'OK value for orderId'); | ||
done(); | ||
@@ -60,6 +61,17 @@ }); | ||
Assert.ok(Number.isInteger(params.path[0].value), 'OK value for petId'); | ||
Assert.ok(params.path[0].value >= 1000 && params.path[0].value <= 2000, 'OK value for petId'); | ||
Assert.ok(params.query, 'Generated query parameter'); | ||
Assert.ok(params.query[0].name === 'petName', 'generated mock parameter for petName'); | ||
Assert.ok(/awesome+ (pet|cat|bird)/.test(params.query[0].value), 'OK value for petName'); | ||
params.query.forEach(function (param) { | ||
if (param.name === 'petName') { | ||
Assert.ok(/awesome+ (pet|cat|bird)/.test(param.value), 'OK value for petName'); | ||
} | ||
if (param.name === 'petWeight') { | ||
Assert.ok(Util.isFinite(param.value), 'OK value for petWeight'); | ||
Assert.ok(param.value <= 500 && param.value >= 10, 'OK value for petWeight'); | ||
} | ||
if (param.name === 'bmi') { | ||
Assert.ok(Util.isFinite(param.value), 'OK value for bmi'); | ||
Assert.ok(param.value <= 1 && param.value >= 0, 'OK value for bmi'); | ||
} | ||
}); | ||
done(); | ||
@@ -81,3 +93,3 @@ }); | ||
Assert.ok(Number.isInteger(params.path[0].value), 'OK value for petId'); | ||
Assert.ok(params.path[0].value > 1000 && params.path[0].value < 1010, 'OK value for petId'); | ||
Assert.ok(params.formData, 'Generated formData parameter'); | ||
@@ -144,2 +156,4 @@ Assert.ok(params.formData[0].name === 'additionalMetadata', 'generated mock parameter for additionalMetadata'); | ||
Assert.ok(Number.isInteger(user.userStatus), 'user.userStatus is integer'); | ||
Assert.ok(user.userStatus > 1000, 'user.userStatus is greater than 1000'); | ||
Assert.ok(user.userStatus % 100 === 0, 'user.userStatus is multipleOf 100'); | ||
Assert.ok(typeof user.username === 'string', 'user.username is string'); | ||
@@ -146,0 +160,0 @@ |
@@ -26,3 +26,3 @@ var Assert = require('assert'); | ||
Assert.ok(params.path[0].name === 'orderId', 'generated mock parameter for orderId'); | ||
Assert.ok(params.path[0].value > 0 && params.path[0].value < 10, 'OK value for orderId'); | ||
Assert.ok(params.path[0].value >= 1 && params.path[0].value <= 10, 'OK value for orderId'); | ||
done(); | ||
@@ -29,0 +29,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
90702
1993