json_schemer 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +1 -1
- data/.travis.yml +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +6 -4
- data/json_schemer.gemspec +1 -1
- data/lib/json_schemer.rb +18 -512
- data/lib/json_schemer/format.rb +158 -58
- data/lib/json_schemer/schema/base.rb +437 -0
- data/lib/json_schemer/schema/draft4.rb +44 -0
- data/lib/json_schemer/schema/draft6.rb +25 -0
- data/lib/json_schemer/schema/draft7.rb +33 -0
- data/lib/json_schemer/version.rb +3 -1
- metadata +7 -3
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSchemer
|
4
|
+
module Schema
|
5
|
+
class Draft4 < Base
|
6
|
+
ID_KEYWORD = 'id'
|
7
|
+
SUPPORTED_FORMATS = Set[
|
8
|
+
'date-time',
|
9
|
+
'email',
|
10
|
+
'hostname',
|
11
|
+
'ipv4',
|
12
|
+
'ipv6',
|
13
|
+
'uri'
|
14
|
+
].freeze
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def id_keyword
|
19
|
+
ID_KEYWORD
|
20
|
+
end
|
21
|
+
|
22
|
+
def supported_format?(format)
|
23
|
+
SUPPORTED_FORMATS.include?(format)
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate_exclusive_maximum(data, schema, pointer, exclusive_maximum, maximum)
|
27
|
+
yield error(data, schema, pointer, 'exclusiveMaximum') if exclusive_maximum && data >= maximum
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_exclusive_minimum(data, schema, pointer, exclusive_minimum, minimum)
|
31
|
+
yield error(data, schema, pointer, 'exclusiveMinimum') if exclusive_minimum && data <= minimum
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_integer(data, schema, pointer)
|
35
|
+
if !data.is_a?(Integer)
|
36
|
+
yield error(data, schema, pointer, 'integer')
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
validate_numeric(data, schema, pointer, &Proc.new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSchemer
|
4
|
+
module Schema
|
5
|
+
class Draft6 < Base
|
6
|
+
SUPPORTED_FORMATS = Set[
|
7
|
+
'date-time',
|
8
|
+
'email',
|
9
|
+
'hostname',
|
10
|
+
'ipv4',
|
11
|
+
'ipv6',
|
12
|
+
'uri',
|
13
|
+
'uri-reference',
|
14
|
+
'uri-template',
|
15
|
+
'json-pointer'
|
16
|
+
].freeze
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def supported_format?(format)
|
21
|
+
SUPPORTED_FORMATS.include?(format)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JSONSchemer
|
4
|
+
module Schema
|
5
|
+
class Draft7 < Base
|
6
|
+
SUPPORTED_FORMATS = Set[
|
7
|
+
'date-time',
|
8
|
+
'date',
|
9
|
+
'time',
|
10
|
+
'email',
|
11
|
+
'idn-email',
|
12
|
+
'hostname',
|
13
|
+
'idn-hostname',
|
14
|
+
'ipv4',
|
15
|
+
'ipv6',
|
16
|
+
'uri',
|
17
|
+
'uri-reference',
|
18
|
+
'iri',
|
19
|
+
'iri-reference',
|
20
|
+
'uri-template',
|
21
|
+
'json-pointer',
|
22
|
+
'relative-json-pointer',
|
23
|
+
'regex'
|
24
|
+
].freeze
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def supported_format?(format)
|
29
|
+
SUPPORTED_FORMATS.include?(format)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/json_schemer/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_schemer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Harsha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,10 @@ files:
|
|
114
114
|
- json_schemer.gemspec
|
115
115
|
- lib/json_schemer.rb
|
116
116
|
- lib/json_schemer/format.rb
|
117
|
+
- lib/json_schemer/schema/base.rb
|
118
|
+
- lib/json_schemer/schema/draft4.rb
|
119
|
+
- lib/json_schemer/schema/draft6.rb
|
120
|
+
- lib/json_schemer/schema/draft7.rb
|
117
121
|
- lib/json_schemer/version.rb
|
118
122
|
homepage: https://github.com/davishmcclurg/json_schemer
|
119
123
|
licenses:
|
@@ -138,5 +142,5 @@ rubyforge_project:
|
|
138
142
|
rubygems_version: 2.7.3
|
139
143
|
signing_key:
|
140
144
|
specification_version: 4
|
141
|
-
summary: JSON Schema
|
145
|
+
summary: JSON Schema validator. Supports drafts 4, 6, and 7.
|
142
146
|
test_files: []
|