diff --git a/.gitignore b/.gitignore index c4f9beeafa48e9b353a4d5e41800804d43994dd6..c71f8d041e449b94ef60aced9f97710dc34737a9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .DS_Store /package /reports +/generated /node_modules diff --git a/.npmignore b/.npmignore index 724959c34720fe9487f1d97d2d5f3cd9b36ac984..c047e0a30b8388328bfc205dd1f7c924782cc81e 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,5 @@ Gruntfile.js /spec /package /reports +/generated /node_modules diff --git a/lib/types/integer.js b/lib/types/integer.js index 850f344a25f038e6e2cb88066008c969556828e1..8a169e10377d3eac467ab08506337d6d5f58812e 100644 Binary files a/lib/types/integer.js and b/lib/types/integer.js differ diff --git a/lib/types/number.js b/lib/types/number.js index dd8c26885ab76de2fac91f46e5c75e5d0a865f85..df0e9bc1c84787482926d6870c40d763edc514c5 100644 Binary files a/lib/types/number.js and b/lib/types/number.js differ diff --git a/lib/util/random.js b/lib/util/random.js index 6b11d885ef8ce6aae94aca753ecc775a57f5a948..d9fd0cd60437af6ebe3e94a23cef5cfe4dc416b4 100644 Binary files a/lib/util/random.js and b/lib/util/random.js differ diff --git a/package.json b/package.json index 32af00a855be6b523d5dbd56679b8ad9a6064c4e..727f37ba15d785dd3c26447a2145cf2f940e7e46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-schema-faker", - "version": "0.1.5", + "version": "0.1.6", "description": "JSON-Schema + Faker", "main": "lib/index.js", "author": { @@ -16,15 +16,15 @@ "clone": "^0.1.19", "glob": "^4.3.5", "grunt": "^0.4.5", - "grunt-parts": "^0.3.0", + "grunt-parts": "^0.3.1", "jayschema": "^0.3.1", "semver": "^4.2.0", - "tv4": "^1.1.5", + "tv4": "^1.1.9", "z-schema": "^3.3.1" }, "dependencies": { - "chance": "^0.6.4", - "deref": "^0.2.6", + "chance": "^0.7.4", + "deref": "^0.2.8", "faker": "^2.1.2", "randexp": "^0.4.0" } diff --git a/spec/core/issues/allOf.json b/spec/core/issues/allOf.json index 1d01ad7f55456cb06c5b3c76d08ed16807424f2d..0281a3913e9a8d8a2aac5d89747d86a20d83af17 100644 --- a/spec/core/issues/allOf.json +++ b/spec/core/issues/allOf.json @@ -3,6 +3,7 @@ "description": "sub-schema mixins", "schemas": [ { + "id": "#", "type": "object", "definitions": { "inner": { diff --git a/spec/core/issues/chance.json b/spec/core/issues/chance.json new file mode 100644 index 0000000000000000000000000000000000000000..d2556b4d64e0aa71f0e4ab996508c8fe05835e3a --- /dev/null +++ b/spec/core/issues/chance.json @@ -0,0 +1,15 @@ +[ + { + "description": "chance issues", + "tests": [ + { + "description": "should allow url-format (0.7.1+)", + "schema": { + "type": "string", + "chance": "url" + }, + "valid": true + } + ] + } +] diff --git a/spec/core/issues/format.json b/spec/core/issues/format.json index 8be3921690985d5d6ff7505aae26235d25583e60..d5f6b747140adfea33ef401d05f1c0d2ca5d6f5e 100644 --- a/spec/core/issues/format.json +++ b/spec/core/issues/format.json @@ -17,6 +17,23 @@ "format": "semver" }, "valid": true + }, + { + "description": "should support faker/chance on numeric types", + "schema": { + "type": "object", + "properties": { + "chanceNumber": { + "type": "integer", + "chance": "natural" + }, + "fakerNumber": { + "type": "integer", + "faker": "random.number" + } + } + }, + "valid": true } ] } diff --git a/spec/core/keywords.json b/spec/core/keywords.json index 207638151c7bdf1ee6409e59d32159258434956d..971c2050e201a9a614b7d7990a8e56b90dd02d3b 100644 --- a/spec/core/keywords.json +++ b/spec/core/keywords.json @@ -5,7 +5,7 @@ { "description": "should handle array of types", "schema": { - "type": ["string", "number"] + "type": ["string", "integer"] }, "valid": true }, @@ -35,7 +35,7 @@ "schema": { "anyOf": [ { - "type": "number" + "type": "integer" }, { "type": "array" diff --git a/spec/core/references.json b/spec/core/references.json index 0a5357c7393297fc8984bd8edbc519a29a3fc088..fe66e83c12b4ffa04a70d475dd891ddb61a21952 100644 --- a/spec/core/references.json +++ b/spec/core/references.json @@ -4,10 +4,11 @@ "tests": [ { "description": "should handle internal $refs", - "schema": { + "schema": { + "id": "#", "definitions": { - "number": { - "type": "number" + "integer": { + "type": "integer" }, "positive": { "minimum": 0, @@ -17,7 +18,7 @@ "type": "object", "properties": { "weakNumber": { - "$ref": "#/definitions/number" + "$ref": "#/definitions/integer" }, "multipleOf5": { "allOf": [ @@ -25,7 +26,7 @@ "$ref": "#/definitions/positive" }, { - "$ref": "#/definitions/number" + "$ref": "#/definitions/integer" }, { "multipleOf": 5 diff --git a/spec/core/types/numbers.json b/spec/core/types/integers.json similarity index 78% rename from spec/core/types/numbers.json rename to spec/core/types/integers.json index 2cfbced62891173425e4914e12e85194e4d714e7..740f528e36e2d60e90969dd1c450aa001b2e505d 100644 --- a/spec/core/types/numbers.json +++ b/spec/core/types/integers.json @@ -1,55 +1,65 @@ [ { - "description": "generated number values", + "description": "generated integer values", "tests": [ { "description": "should handle minimum", "schema": { - "type": "number", + "type": "integer", "minimum": 10 }, + "hasNot": ".", + "type": "number", "valid": true }, { "description": "should handle maximum", "schema": { - "type": "number", + "type": "integer", "minimum": 20, "maximum": 30 }, + "hasNot": ".", + "type": "number", "valid": true }, { "description": "should handle multipleOf", "schema": { - "type": "number", + "type": "integer", "minimum": 40, "maximum": 50, "multipleOf": 6 }, + "hasNot": ".", + "type": "number", "valid": true }, { "description": "should handle exclusiveMinimum", "schema": { - "type": "number", + "type": "integer", "minimum": 60, "maximum": 70, "multipleOf": 7, "exclusiveMinimum": true }, + "hasNot": ".", + "type": "number", "valid": true }, { "description": "should handle exclusiveMaximum", "schema": { - "type": "number", + "type": "integer", "minimum": 80, "maximum": 90, "multipleOf": 8, "exclusiveMinimum": true, "exclusiveMaximum": true }, + "hasNot": ".", + "type": "number", "valid": true }, { @@ -58,7 +68,7 @@ "type": "object", "properties": { "test": { - "type": "number", + "type": "integer", "minimum": [] } } @@ -71,7 +81,7 @@ "type": "object", "properties": { "test": { - "type": "number", + "type": "integer", "maximum": [] } } @@ -84,7 +94,7 @@ "type": "object", "properties": { "test": { - "type": "number", + "type": "integer", "minimum": 100, "maximum": 50 } diff --git a/spec/helpers.coffee b/spec/helpers.coffee index 647f615d7281f994a2980f32dd1252371ee7add2..bb009d69420a27627b94c9ee802fc87cd81fc868 100644 --- a/spec/helpers.coffee +++ b/spec/helpers.coffee @@ -47,7 +47,7 @@ jasmine.Matchers::toHaveSchema = (expected, refs) -> formatValidators jay - jay.register(clone(schema), schema.id) for schema in refs if refs + jay.register(clone(schema)) for schema in refs if refs result = jay.validate @actual, clone(expected) diff --git a/spec/main-spec.coffee b/spec/main-spec.coffee index 74cda0f3d5e416a9cd0bf780ef38a632b8380711..7ee94e442f5d9c647dd950d9f890e87817ab8e5b 100644 --- a/spec/main-spec.coffee +++ b/spec/main-spec.coffee @@ -1,5 +1,6 @@ fs = require('fs') glob = require('glob') +deref = require('deref') jsfaker = require('../lib') require('./formats').register(jsfaker) @@ -43,6 +44,9 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> error = e.message throw e unless test.throws + if test.hasNot + expect(sample.toString()).not.toContain test.hasNot + if test.type expect(sample).toHaveType test.type @@ -50,7 +54,10 @@ glob.sync("#{__dirname}/**/*.json").forEach (file) -> expect(error).toMatch new RegExp('^' + test.throws + '$', 'i') if test.valid + schema = deref.util.normalizeSchema(schema) + try + refs = [schema] if schema.id expect(sample).toHaveSchema schema, refs catch e console.log JSON.stringify(schema, null, 2)