diff options
author | Julian Berman <Julian@GrayVines.com> | 2017-11-05 13:18:25 -0500 |
---|---|---|
committer | Julian Berman <Julian@GrayVines.com> | 2017-11-05 13:18:25 -0500 |
commit | 2a067e7fd455952f01924d5983d0bceacf9ee08d (patch) | |
tree | a0993b434a59349957a09069dae7a6aad5cb6ca1 | |
parent | d0381d51c1ba361e675bdf36adb6ea9d62caa06b (diff) | |
parent | be19a54e7a4716103177401fb57baf5ac61407df (diff) | |
download | jsonschema-2a067e7fd455952f01924d5983d0bceacf9ee08d.tar.gz |
Merge commit 'be19a54e7a4716103177401fb57baf5ac61407df'
* commit 'be19a54e7a4716103177401fb57baf5ac61407df':
Squashed 'json/' changes from 27f8c84..9567c58
24 files changed, 506 insertions, 36 deletions
diff --git a/json/README.md b/json/README.md index 21f7332..8044189 100644 --- a/json/README.md +++ b/json/README.md @@ -155,6 +155,7 @@ for more information. ### PostgreSQL ### * [postgres-json-schema](https://github.com/gavinwahl/postgres-json-schema) +* [is_jsonb_valid](https://github.com/furstenheim/is_jsonb_valid) If you use it as well, please fork and send a pull request adding yourself to the list :). diff --git a/json/index.js b/json/index.js index 9b8df93..2684ffe 100644 --- a/json/index.js +++ b/json/index.js @@ -15,7 +15,10 @@ runTest(4); runTest(6); function runTest(draft) { - var opts = {format: 'full'}; + var opts = { + format: 'full', + formats: {'json-pointer': /^(?:\/(?:[^~\/]|~0|~1)*)*$/} + }; if (draft == 4) opts.meta = false; var ajv = new Ajv(opts); ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json')); diff --git a/json/tests/draft3/additionalProperties.json b/json/tests/draft3/additionalProperties.json index 40831f9..90d7607 100644 --- a/json/tests/draft3/additionalProperties.json +++ b/json/tests/draft3/additionalProperties.json @@ -19,11 +19,21 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, "valid": true diff --git a/json/tests/draft3/dependencies.json b/json/tests/draft3/dependencies.json index 2f6ae48..d7e0925 100644 --- a/json/tests/draft3/dependencies.json +++ b/json/tests/draft3/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft3/patternProperties.json b/json/tests/draft3/patternProperties.json index 18586e5..2ca9aae 100644 --- a/json/tests/draft3/patternProperties.json +++ b/json/tests/draft3/patternProperties.json @@ -29,7 +29,12 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft3/properties.json b/json/tests/draft3/properties.json index cd1644d..a830c67 100644 --- a/json/tests/draft3/properties.json +++ b/json/tests/draft3/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft4/additionalProperties.json b/json/tests/draft4/additionalProperties.json index 40831f9..90d7607 100644 --- a/json/tests/draft4/additionalProperties.json +++ b/json/tests/draft4/additionalProperties.json @@ -19,11 +19,21 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, "valid": true diff --git a/json/tests/draft4/dependencies.json b/json/tests/draft4/dependencies.json index 7b9b16a..38effa1 100644 --- a/json/tests/draft4/dependencies.json +++ b/json/tests/draft4/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft4/maxProperties.json b/json/tests/draft4/maxProperties.json index d282446..513731e 100644 --- a/json/tests/draft4/maxProperties.json +++ b/json/tests/draft4/maxProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", "data": "foobar", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft4/minProperties.json b/json/tests/draft4/minProperties.json index a72c7d2..49a0726 100644 --- a/json/tests/draft4/minProperties.json +++ b/json/tests/draft4/minProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", "data": "", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft4/optional/format.json b/json/tests/draft4/optional/format.json index 80373bd..32db8de 100644 --- a/json/tests/draft4/optional/format.json +++ b/json/tests/draft4/optional/format.json @@ -25,16 +25,81 @@ "schema": {"format": "uri"}, "tests": [ { - "description": "a valid URI", + "description": "a valid URL with anchor tag", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { + "description": "a valid URL with anchor tag and parantheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { "description": "an invalid protocol-relative URI Reference", "data": "//foo.bar/?baz=qux#quux", "valid": false }, { + "description": "an invalid relative URI Reference", + "data": "/abc", + "valid": false + }, + { "description": "an invalid URI", "data": "\\\\WINDOWS\\fileshare", "valid": false @@ -43,6 +108,16 @@ "description": "an invalid URI though valid URI reference", "data": "abc", "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false } ] }, diff --git a/json/tests/draft4/patternProperties.json b/json/tests/draft4/patternProperties.json index 18586e5..5f741df 100644 --- a/json/tests/draft4/patternProperties.json +++ b/json/tests/draft4/patternProperties.json @@ -29,7 +29,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft4/properties.json b/json/tests/draft4/properties.json index cd1644d..a830c67 100644 --- a/json/tests/draft4/properties.json +++ b/json/tests/draft4/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft4/required.json b/json/tests/draft4/required.json index 576ef45..1e2a4f0 100644 --- a/json/tests/draft4/required.json +++ b/json/tests/draft4/required.json @@ -20,7 +20,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft6/additionalProperties.json b/json/tests/draft6/additionalProperties.json index 40831f9..90d7607 100644 --- a/json/tests/draft6/additionalProperties.json +++ b/json/tests/draft6/additionalProperties.json @@ -19,11 +19,21 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [1, 2, 3], "valid": true }, { + "description": "ignores strings", + "data": "foobarbaz", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true + }, + { "description": "patternProperties are not additional properties", "data": {"foo":1, "vroom": 2}, "valid": true diff --git a/json/tests/draft6/const.json b/json/tests/draft6/const.json index 0e533e0..0fe00f2 100644 --- a/json/tests/draft6/const.json +++ b/json/tests/draft6/const.json @@ -47,6 +47,27 @@ ] }, { + "description": "const with array", + "schema": {"const": [{ "foo": "bar" }]}, + "tests": [ + { + "description": "same array is valid", + "data": [{"foo": "bar"}], + "valid": true + }, + { + "description": "another array item is invalid", + "data": [2], + "valid": false + }, + { + "description": "array with additional items is invalid", + "data": [1, 2, 3], + "valid": false + } + ] + }, + { "description": "const with null", "schema": {"const": null}, "tests": [ diff --git a/json/tests/draft6/dependencies.json b/json/tests/draft6/dependencies.json index a9b3334..80e552f 100644 --- a/json/tests/draft6/dependencies.json +++ b/json/tests/draft6/dependencies.json @@ -26,8 +26,18 @@ "valid": false }, { - "description": "ignores non-objects", - "data": "foo", + "description": "ignores arrays", + "data": ["bar"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft6/maxProperties.json b/json/tests/draft6/maxProperties.json index d282446..513731e 100644 --- a/json/tests/draft6/maxProperties.json +++ b/json/tests/draft6/maxProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [1, 2, 3], + "valid": true + }, + { + "description": "ignores strings", "data": "foobar", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft6/minProperties.json b/json/tests/draft6/minProperties.json index a72c7d2..49a0726 100644 --- a/json/tests/draft6/minProperties.json +++ b/json/tests/draft6/minProperties.json @@ -19,9 +19,19 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", "data": "", "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] } diff --git a/json/tests/draft6/optional/format.json b/json/tests/draft6/optional/format.json index 677891c..67f2fe6 100644 --- a/json/tests/draft6/optional/format.json +++ b/json/tests/draft6/optional/format.json @@ -25,11 +25,71 @@ "schema": {"format": "uri"}, "tests": [ { - "description": "a valid URI", + "description": "a valid URL with anchor tag", "data": "http://foo.bar/?baz=qux#quux", "valid": true }, { + "description": "a valid URL with anchor tag and parantheses", + "data": "http://foo.com/blah_(wikipedia)_blah#cite-1", + "valid": true + }, + { + "description": "a valid URL with URL-encoded stuff", + "data": "http://foo.bar/?q=Test%20URL-encoded%20stuff", + "valid": true + }, + { + "description": "a valid puny-coded URL ", + "data": "http://xn--nw2a.xn--j6w193g/", + "valid": true + }, + { + "description": "a valid URL with many special characters", + "data": "http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + "valid": true + }, + { + "description": "a valid URL based on IPv4", + "data": "http://223.255.255.254", + "valid": true + }, + { + "description": "a valid URL with ftp scheme", + "data": "ftp://ftp.is.co.za/rfc/rfc1808.txt", + "valid": true + }, + { + "description": "a valid URL for a simple text file", + "data": "http://www.ietf.org/rfc/rfc2396.txt", + "valid": true + }, + { + "description": "a valid URL ", + "data": "ldap://[2001:db8::7]/c=GB?objectClass?one", + "valid": true + }, + { + "description": "a valid mailto URI", + "data": "mailto:John.Doe@example.com", + "valid": true + }, + { + "description": "a valid newsgroup URI", + "data": "news:comp.infosystems.www.servers.unix", + "valid": true + }, + { + "description": "a valid tel URI", + "data": "tel:+1-816-555-1212", + "valid": true + }, + { + "description": "a valid URN", + "data": "urn:oasis:names:specification:docbook:dtd:xml:4.1.2", + "valid": true + }, + { "description": "an invalid protocol-relative URI Reference", "data": "//foo.bar/?baz=qux#quux", "valid": false @@ -48,6 +108,16 @@ "description": "an invalid URI though valid URI reference", "data": "abc", "valid": false + }, + { + "description": "an invalid URI with spaces", + "data": "http:// shouldfail.com", + "valid": false + }, + { + "description": "an invalid URI with spaces and missing scheme", + "data": ":// should fail", + "valid": false } ] }, @@ -220,7 +290,7 @@ ] }, { - "description": "validation of JSON-pointers", + "description": "validation of JSON-pointers (JSON String Representation)", "schema": {"format": "json-pointer"}, "tests": [ { @@ -229,29 +299,159 @@ "valid": true }, { - "description": "empty string is valid", + "description": "not a valid JSON-pointer (~ not escaped)", + "data": "/foo/bar~", + "valid": false + }, + { + "description": "valid JSON-pointer with empty segment", + "data": "/foo//bar", + "valid": true + }, + { + "description": "valid JSON-pointer with the last empty segment", + "data": "/foo/bar/", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #1", "data": "", "valid": true }, { - "description": "/ is valid", + "description": "valid JSON-pointer as stated in RFC 6901 #2", + "data": "/foo", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #3", + "data": "/foo/0", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #4", "data": "/", "valid": true }, { - "description": "not a valid JSON-pointer (~ not escaped)", - "data": "/foo/bar~", - "valid": false + "description": "valid JSON-pointer as stated in RFC 6901 #5", + "data": "/a~1b", + "valid": true }, { - "description": "valid JSON-pointer with empty segment", - "data": "/foo//bar", + "description": "valid JSON-pointer as stated in RFC 6901 #6", + "data": "/c%d", "valid": true }, { - "description": "valid JSON-pointer with the last empty segment", - "data": "/foo/bar/", + "description": "valid JSON-pointer as stated in RFC 6901 #7", + "data": "/e^f", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #8", + "data": "/g|h", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #9", + "data": "/i\\j", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #10", + "data": "/k\"l", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #11", + "data": "/ ", + "valid": true + }, + { + "description": "valid JSON-pointer as stated in RFC 6901 #12", + "data": "/m~0n", + "valid": true + }, + { + "description": "valid JSON-pointer used adding to the last array position", + "data": "/foo/-", + "valid": true + }, + { + "description": "valid JSON-pointer (- used as object member name)", + "data": "/foo/-/bar", + "valid": true + }, + { + "description": "valid JSON-pointer (multiple escaped characters)", + "data": "/~1~0~0~1~1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #1", + "data": "/~1.1", + "valid": true + }, + { + "description": "valid JSON-pointer (escaped with fraction part) #2", + "data": "/~0.1", "valid": true + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #1", + "data": "#", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #2", + "data": "#/", + "valid": false + }, + { + "description": "not a valid JSON-pointer (URI Fragment Identifier) #3", + "data": "#a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #1", + "data": "/~0~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (some escaped, but not all) #2", + "data": "/~0/~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #1", + "data": "/~2", + "valid": false + }, + { + "description": "not a valid JSON-pointer (wrong escape character) #2", + "data": "/~-1", + "valid": false + }, + { + "description": "not a valid JSON-pointer (multiple characters not escaped)", + "data": "/~~", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #1", + "data": "a", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #2", + "data": "0", + "valid": false + }, + { + "description": "not a valid JSON-pointer (isn't empty nor starts with /) #3", + "data": "a/a", + "valid": false } ] } diff --git a/json/tests/draft6/patternProperties.json b/json/tests/draft6/patternProperties.json index b1f2d35..1d04a16 100644 --- a/json/tests/draft6/patternProperties.json +++ b/json/tests/draft6/patternProperties.json @@ -29,7 +29,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": ["foo"], + "valid": true + }, + { + "description": "ignores strings", + "data": "foo", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } diff --git a/json/tests/draft6/properties.json b/json/tests/draft6/properties.json index d56a960..c8ad719 100644 --- a/json/tests/draft6/properties.json +++ b/json/tests/draft6/properties.json @@ -29,9 +29,14 @@ "valid": true }, { - "description": "ignores non-objects", + "description": "ignores arrays", "data": [], "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, + "valid": true } ] }, diff --git a/json/tests/draft6/propertyNames.json b/json/tests/draft6/propertyNames.json index 2804b41..8423690 100644 --- a/json/tests/draft6/propertyNames.json +++ b/json/tests/draft6/propertyNames.json @@ -27,8 +27,18 @@ "valid": true }, { - "description": "non-object is valid", - "data": [], + "description": "ignores arrays", + "data": [1, 2, 3, 4], + "valid": true + }, + { + "description": "ignores strings", + "data": "foobar", + "valid": true + }, + { + "description": "ignores other non-objects", + "data": 12, "valid": true } ] diff --git a/json/tests/draft6/required.json b/json/tests/draft6/required.json index 3082157..bd96907 100644 --- a/json/tests/draft6/required.json +++ b/json/tests/draft6/required.json @@ -20,7 +20,17 @@ "valid": false }, { - "description": "ignores non-objects", + "description": "ignores arrays", + "data": [], + "valid": true + }, + { + "description": "ignores strings", + "data": "", + "valid": true + }, + { + "description": "ignores other non-objects", "data": 12, "valid": true } |