json-schema 2.1.6 → 2.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.textile +1 -1
- data/lib/json-schema.rb +1 -0
- data/lib/json-schema/attributes/enum.rb +1 -1
- data/lib/json-schema/util/array_set.rb +14 -0
- data/lib/json-schema/validator.rb +2 -6
- data/test/test_jsonschema_draft4.rb +17 -0
- data/test/test_ruby_schema.rb +0 -6
- metadata +6 -7
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDk3NjY1MWJhZWMwMDk0MGFjMWZlNzNmNzNmYzE5MWM4Y2I4MWYyNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTUyMTAyNTdiZmE3YWI0YzM0Y2ZmYmQ5YTZjMTdiYjYzZWNjMWEzNg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDNjOTI5ZWNlYmVlYWI4MTQ0ZTdhOWFlMjlmODZmZmZhMGI4NTZjNTkwMjg3
|
10
|
+
NGQ0MjQ4NWMyYjdiNzc0ZmZiZGQ1MDQzMjQzNDMwNmZiZDk2ZTQwZTY0NDdi
|
11
|
+
NGM1ODA4NTEzNjE1N2JlNWQyMTdlODA2ZjdkMGZlOGExZjA3NmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDVkY2E4MWM0NGZlYjgyNTEwOGM0ZDIzNDIzYWNmMzMzZTMxMDhhMGQ4NDk0
|
14
|
+
MzI3ZWY1NjJlNzIxNDc3N2IyZWJlMWYyYTkwODA5YjAwMmM5NGYyYTUwOGE4
|
15
|
+
ZDA0ZDhhMTZmODU1YmRmODBkNWNlZjhmYTQyYjI5YzRlM2Y1NTM=
|
data/README.textile
CHANGED
data/lib/json-schema.rb
CHANGED
@@ -18,6 +18,7 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/json-schema"
|
|
18
18
|
|
19
19
|
require 'rubygems'
|
20
20
|
require 'util/hash'
|
21
|
+
require 'util/array_set'
|
21
22
|
require 'schema'
|
22
23
|
require 'validator'
|
23
24
|
Dir[File.join(File.dirname(__FILE__), "json-schema/attributes/*.rb")].each {|file| require file }
|
@@ -4,7 +4,7 @@ module JSON
|
|
4
4
|
def self.validate(current_schema, data, fragments, processor, validator, options = {})
|
5
5
|
if !current_schema.schema['enum'].include?(data)
|
6
6
|
message = "The property '#{build_fragment(fragments)}' value #{data.inspect} did not match one of the following values:"
|
7
|
-
current_schema.schema['enum'].
|
7
|
+
current_schema.schema['enum'].each {|val|
|
8
8
|
if val.is_a?(NilClass)
|
9
9
|
message += " null,"
|
10
10
|
elsif val.is_a?(Array)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# This is a hack that I don't want to ever use anywhere else or repeat EVER, but we need enums to be
|
2
|
+
# an Array to pass schema validation. But we also want fast lookup! And we can't use sets because of
|
3
|
+
# backport support... so...
|
4
|
+
|
5
|
+
class ArraySet < Array
|
6
|
+
def include?(obj)
|
7
|
+
# On first invocation create a HASH (yeah, yeah) to act as our set given the array values
|
8
|
+
if !defined? @array_values
|
9
|
+
@array_values = {}
|
10
|
+
self.each {|x| @array_values[x] = 1}
|
11
|
+
end
|
12
|
+
@array_values.has_key? obj
|
13
|
+
end
|
14
|
+
end
|
@@ -337,13 +337,9 @@ module JSON
|
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
340
|
-
# Convert enum to a
|
340
|
+
# Convert enum to a ArraySet
|
341
341
|
if parent_schema.schema["enum"] && parent_schema.schema["enum"].is_a?(Array)
|
342
|
-
|
343
|
-
parent_schema.schema["enum"].each do |item|
|
344
|
-
enum_hash[item] = true
|
345
|
-
end
|
346
|
-
parent_schema.schema["enum"] = enum_hash
|
342
|
+
parent_schema.schema["enum"] = ArraySet.new(parent_schema.schema["enum"])
|
347
343
|
end
|
348
344
|
|
349
345
|
# Each of these might be schemas
|
@@ -602,6 +602,23 @@ class JSONSchemaDraft4Test < Test::Unit::TestCase
|
|
602
602
|
assert(JSON::Validator.validate(schema,data))
|
603
603
|
end
|
604
604
|
|
605
|
+
def test_enum_with_schema_validation
|
606
|
+
schema = {
|
607
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
608
|
+
"properties" => {
|
609
|
+
"a" => {"enum" => [1,'boo',[1,2,3],{"a" => "b"}]}
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
613
|
+
data = {
|
614
|
+
"a" => nil
|
615
|
+
}
|
616
|
+
|
617
|
+
# Make sure all of the above are valid...
|
618
|
+
data["a"] = 1
|
619
|
+
assert(JSON::Validator.validate(schema,data,:validate_schema => true))
|
620
|
+
end
|
621
|
+
|
605
622
|
|
606
623
|
def test_multiple_of
|
607
624
|
# Set up the default datatype
|
data/test/test_ruby_schema.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kenny Hoxworth
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-03 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description:
|
15
14
|
email: hoxworth@gmail.com
|
@@ -58,6 +57,7 @@ files:
|
|
58
57
|
- lib/json-schema/schema.rb
|
59
58
|
- lib/json-schema/uri/file.rb
|
60
59
|
- lib/json-schema/uri/uuid.rb
|
60
|
+
- lib/json-schema/util/array_set.rb
|
61
61
|
- lib/json-schema/util/hash.rb
|
62
62
|
- lib/json-schema/validator.rb
|
63
63
|
- lib/json-schema/validators/draft1.rb
|
@@ -112,27 +112,26 @@ files:
|
|
112
112
|
homepage: http://github.com/hoxworth/json-schema/tree/master
|
113
113
|
licenses:
|
114
114
|
- MIT
|
115
|
+
metadata: {}
|
115
116
|
post_install_message:
|
116
117
|
rdoc_options: []
|
117
118
|
require_paths:
|
118
119
|
- lib
|
119
120
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
-
none: false
|
121
121
|
requirements:
|
122
122
|
- - ! '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
-
none: false
|
127
126
|
requirements:
|
128
127
|
- - ! '>='
|
129
128
|
- !ruby/object:Gem::Version
|
130
129
|
version: '0'
|
131
130
|
requirements: []
|
132
131
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
132
|
+
rubygems_version: 2.0.7
|
134
133
|
signing_key:
|
135
|
-
specification_version:
|
134
|
+
specification_version: 4
|
136
135
|
summary: Ruby JSON Schema Validator
|
137
136
|
test_files:
|
138
137
|
- test/test_all_of_ref_schema.rb
|