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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmI5ZTBkM2Q5MmNiNTc3M2QwNWRhZmU5ZDYzODA1MjBlOGEwYThhMg==
4
+ NTgxODJmMjgzZjgwNjhhMDQ4MmVkNTQzMTk4MTU4ZTUxMzM2NTlkZA==
5
5
  data.tar.gz: !binary |-
6
- MWQ5ZGM5ZDUxYmM3NmM4ZjE2MTJiNTMyNDZhMDkyZjcwYWFiOGI4ZQ==
6
+ N2FhMDFhYTg5OTYzOWNhYzZhYzY5MWJkYTQwYTVhZTJhZWMyM2VmNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWM1ZGVkNDkyYzU5NzI5Mjg0NjcxNDY2MmM0ZDM1OTY2YzM4NjM0NDQxOGVi
10
- ZDNiYTlkNTE3NzI3NTM2M2M3MzMzMzY3ZTliYjhiNGVmZjBkZjc4NzI1Zjdk
11
- YmVlOTEyYzZjYmI2N2ZjYTQzNDZlNzIxYzY4MjkwYWQwMjE4NTg=
9
+ ODg5OTdmN2EzMDg1NzExNDdkMGRiMGYzNTJkNzhhYzg3OTA4ODllYjcyODUw
10
+ N2QwNGE0YzE2NGZmYjlmOGQwMWQ0MDk5NTMzMmQwNjBjM2QyNDIzYzc0MDRi
11
+ Yjk0NDcxMmMyYWVjMmJiZmVlYzFkNzEyNTQ1YjAyNDFhYmMwMmM=
12
12
  data.tar.gz: !binary |-
13
- OGUxNDU0N2RmMWZmZDAyNmY0ZmUxNWNjZDg5OTdjMTI0ZmY4ZjMwN2I2NTI2
14
- N2RjZmFjYWIxNDRjZDdkNDM1NTA5NDk4YjQ0NDRlNWVmNTU1MTQ4NGM2MWQ3
15
- NGE5N2IwMGFhY2MzYWRkNTE0OTBkYjMyMzY2YjE3OWRlOTc5MzA=
13
+ NDQ5YTYxZTI5N2JjOWVlMjAzMzNiMmRiZDkyN2EzOGM5MzQ1MDFiZjE1YWFi
14
+ NWY5Njk2NTk5MGQ5ZmYxY2FlMDE2MTBiYzcxZDA1OGQ5NTExOGI0NGY2OTVk
15
+ Y2Y5NzA0ZTRhZDEzYzg5M2JiNDcyOTI4ZWU5ZGRkYTJlNWM5NjE=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openc-json_schema (0.0.7)
4
+ openc-json_schema (0.0.8)
5
5
  json-schema-openc-fork (= 0.0.1)
6
6
 
7
7
  GEM
@@ -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
- "Missing required property: #{path}"
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
- "Disallowed additional property: #{path}"
93
+ type = :additional
94
+ message = "Disallowed additional property: #{path}"
92
95
  when 'OneOf'
93
96
  if error[:message].match(/did not match any/)
94
- "No match for property: #{path}"
97
+ type = :one_of_no_matches
98
+ message = "No match for property: #{path}"
95
99
  else
96
- "Multiple possible matches for property: #{path}"
100
+ type = :one_of_many_matches
101
+ message = "Multiple possible matches for property: #{path}"
97
102
  end
98
103
  when 'AnyOf'
99
- "No match for property: #{path}"
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
- "Property too short: #{path} (must be at least #{min_length} characters)"
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
- "Property too long: #{path} (must be at most #{max_length} characters)"
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
- "Property of wrong type: #{path} (must be of type #{allowed_types.join(', ')})"
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
- "Property not of expected format: #{path} (must be of format yyyy-mm-dd)"
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
- "Error of unknown type: #{path} (#{error[:message]})"
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)
@@ -1,5 +1,5 @@
1
1
  module Openc
2
2
  module JsonSchema
3
- VERSION = '0.0.7'
3
+ VERSION = '0.0.8'
4
4
  end
5
5
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openc-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCorporates