openc-json_schema 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/lib/openc/json_schema/validator.rb +31 -12
- data/lib/openc/json_schema/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTgxODJmMjgzZjgwNjhhMDQ4MmVkNTQzMTk4MTU4ZTUxMzM2NTlkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2FhMDFhYTg5OTYzOWNhYzZhYzY5MWJkYTQwYTVhZTJhZWMyM2VmNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODg5OTdmN2EzMDg1NzExNDdkMGRiMGYzNTJkNzhhYzg3OTA4ODllYjcyODUw
|
10
|
+
N2QwNGE0YzE2NGZmYjlmOGQwMWQ0MDk5NTMzMmQwNjBjM2QyNDIzYzc0MDRi
|
11
|
+
Yjk0NDcxMmMyYWVjMmJiZmVlYzFkNzEyNTQ1YjAyNDFhYmMwMmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDQ5YTYxZTI5N2JjOWVlMjAzMzNiMmRiZDkyN2EzOGM5MzQ1MDFiZjE1YWFi
|
14
|
+
NWY5Njk2NTk5MGQ5ZmYxY2FlMDE2MTBiYzcxZDA1OGQ5NTExOGI0NGY2OTVk
|
15
|
+
Y2Y5NzA0ZTRhZDEzYzg5M2JiNDcyOTI4ZWU5ZGRkYTJlNWM5NjE=
|
data/Gemfile.lock
CHANGED
@@ -77,53 +77,72 @@ module Openc
|
|
77
77
|
|
78
78
|
def convert_error(error)
|
79
79
|
path = fragment_to_path(error[:fragment])
|
80
|
+
extra_params = {}
|
80
81
|
|
81
82
|
case error[:failed_attribute]
|
82
83
|
when 'Required'
|
83
84
|
match = error[:message].match(/required property of '(.*)'/)
|
84
85
|
missing_property = match[1]
|
85
86
|
path = fragment_to_path("#{error[:fragment]}/#{missing_property}")
|
86
|
-
|
87
|
+
type = :missing
|
88
|
+
message = "Missing required property: #{path}"
|
87
89
|
when 'AdditionalProperties'
|
88
90
|
match = error[:message].match(/contains additional properties \["(.*)"\] outside of the schema/)
|
89
91
|
additional_property = match[1].split('", "')[0]
|
90
92
|
path = fragment_to_path("#{error[:fragment]}/#{additional_property}")
|
91
|
-
|
93
|
+
type = :additional
|
94
|
+
message = "Disallowed additional property: #{path}"
|
92
95
|
when 'OneOf'
|
93
96
|
if error[:message].match(/did not match any/)
|
94
|
-
|
97
|
+
type = :one_of_no_matches
|
98
|
+
message = "No match for property: #{path}"
|
95
99
|
else
|
96
|
-
|
100
|
+
type = :one_of_many_matches
|
101
|
+
message = "Multiple possible matches for property: #{path}"
|
97
102
|
end
|
98
103
|
when 'AnyOf'
|
99
|
-
|
104
|
+
type = :any_of_no_matches
|
105
|
+
message = "No match for property: #{path}"
|
100
106
|
when 'MinLength'
|
101
107
|
match = error[:message].match(/minimum string length of (\d+) in/)
|
102
108
|
min_length = match[1].to_i
|
103
|
-
|
109
|
+
type = :too_short
|
110
|
+
message = "Property too short: #{path} (must be at least #{min_length} characters)"
|
111
|
+
extra_params = {:length => min_length}
|
104
112
|
when 'MaxLength'
|
105
113
|
match = error[:message].match(/maximum string length of (\d+) in/)
|
106
114
|
max_length = match[1].to_i
|
107
|
-
|
115
|
+
type = :too_long
|
116
|
+
message = "Property too long: #{path} (must be at most #{max_length} characters)"
|
117
|
+
extra_params = {:length => max_length}
|
108
118
|
when 'TypeV4'
|
109
119
|
match = error[:message].match(/the following types?: ([\w\s,]+) in schema/)
|
110
120
|
allowed_types = match[1].split(',').map(&:strip)
|
111
|
-
|
121
|
+
type = :type_mismatch
|
122
|
+
message = "Property of wrong type: #{path} (must be of type #{allowed_types.join(', ')})"
|
123
|
+
extra_params = {:allowed_types => allowed_types}
|
112
124
|
when 'Enum'
|
113
125
|
match = error[:message].match(/the following values: ([\w\s,]+) in schema/)
|
114
126
|
allowed_values = match[1].split(',').map(&:strip)
|
127
|
+
type = :enum_mismatch
|
115
128
|
if allowed_values.size == 1
|
116
|
-
"Property must have value #{allowed_values[0]}: #{path}"
|
129
|
+
message = "Property must have value #{allowed_values[0]}: #{path}"
|
117
130
|
else
|
118
|
-
"Property not an allowed value: #{path} (must be one of #{allowed_values.join(', ')})"
|
131
|
+
message = "Property not an allowed value: #{path} (must be one of #{allowed_values.join(', ')})"
|
119
132
|
end
|
133
|
+
extra_params = {:allowed_values => allowed_values}
|
120
134
|
else
|
121
135
|
if error[:message].match(/must be of format yyyy-mm-dd/)
|
122
|
-
|
136
|
+
type = :format_mismatch
|
137
|
+
message = "Property not of expected format: #{path} (must be of format yyyy-mm-dd)"
|
138
|
+
extra_params = {:expected_format => 'yyyy-mm-dd'}
|
123
139
|
else
|
124
|
-
|
140
|
+
type = :unknown
|
141
|
+
message = "Error of unknown type: #{path} (#{error[:message]})"
|
125
142
|
end
|
126
143
|
end
|
144
|
+
|
145
|
+
{:type => type, :path => path, :message => message}.merge(extra_params)
|
127
146
|
end
|
128
147
|
|
129
148
|
def fragment_to_path(fragment)
|
data/spec/spec_helper.rb
CHANGED
@@ -22,7 +22,7 @@ end
|
|
22
22
|
RSpec::Matchers.define(:fail_validation_with) do |expected|
|
23
23
|
match do |actual|
|
24
24
|
schema_or_path, record = actual
|
25
|
-
@error = Openc::JsonSchema.validate(get_schema_path(schema_or_path), record)
|
25
|
+
@error = Openc::JsonSchema.validate(get_schema_path(schema_or_path), record)[:message]
|
26
26
|
expect(@error).to eq(expected)
|
27
27
|
end
|
28
28
|
|