marty 1.0.36 → 1.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/marty/rpc_controller.rb +2 -1
- data/lib/marty/json_schema.rb +9 -6
- data/lib/marty/version.rb +1 -1
- data/spec/lib/json_schema_spec.rb +131 -46
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e2be11ff162cb9ff6d61e1f98f91e3c24b692a8
|
4
|
+
data.tar.gz: ecc6fa69360347e2ac3b607adeb495534323b68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49984e9ef1fa5e9c0145404a78a175f9c1dd333c2db218d083451e13a16f7a0e3b1b2233edee9e0e5b74d6eb996407640eb25ac695eaa32b4319ea1ab8046945
|
7
|
+
data.tar.gz: 0c7dba4c68ad11fb575c73801ce8d49d782f8d04b31733d7017b4b33fef779a2419f382364956bc2ffe984429ac1d6e457cc3ab4f4508c777be36091564f3019
|
@@ -151,7 +151,8 @@ class Marty::RpcController < ActionController::Base
|
|
151
151
|
{error: the_error,
|
152
152
|
data: res}) if the_error
|
153
153
|
is_strict && the_error ?
|
154
|
-
{error: "Error(s) validating: #{the_error}"
|
154
|
+
{error: "Error(s) validating: #{the_error}",
|
155
|
+
data: res} : res
|
155
156
|
end
|
156
157
|
end
|
157
158
|
end
|
data/lib/marty/json_schema.rb
CHANGED
@@ -5,15 +5,18 @@ module Marty
|
|
5
5
|
private
|
6
6
|
class PgEnumAttribute < JSON::Schema::Attribute
|
7
7
|
def self.validate(curr_schema, data, frag, pro, validator, opt={})
|
8
|
-
|
8
|
+
values = nil
|
9
|
+
path = '#/' + frag.join('/')
|
9
10
|
begin
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
cs = curr_schema.schema["pg_enum"]
|
12
|
+
enum = cs.constantize
|
13
|
+
values = enum::VALUES
|
14
|
+
rescue => e
|
15
|
+
msg = "The property '#{path}': '#{cs}' is not a pg_enum class"
|
13
16
|
validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors])
|
14
17
|
end
|
15
|
-
if !
|
16
|
-
msg = "#{
|
18
|
+
if values && !values.include?(data)
|
19
|
+
msg = "The property '#{path}' value '#{data}' not contained in #{enum}"
|
17
20
|
validation_error(pro, msg, frag, curr_schema, self, opt[:record_errors])
|
18
21
|
end
|
19
22
|
end
|
data/lib/marty/version.rb
CHANGED
@@ -8,6 +8,10 @@ class ElectronicsEnum
|
|
8
8
|
VALUES=Set['Phone','Keyboard','Terminator']
|
9
9
|
end
|
10
10
|
|
11
|
+
class NotAnEnum
|
12
|
+
HI = "MOM"
|
13
|
+
end
|
14
|
+
|
11
15
|
module Marty
|
12
16
|
|
13
17
|
describe JsonSchema do
|
@@ -24,20 +28,28 @@ module Marty
|
|
24
28
|
},
|
25
29
|
}
|
26
30
|
}
|
31
|
+
opt = { :validate_schema => true,
|
32
|
+
:errors_as_objects => false,
|
33
|
+
:version => Marty::JsonSchema::RAW_URI }
|
27
34
|
|
28
|
-
it "returns
|
35
|
+
it "returns no error on correct simple data" do
|
29
36
|
data = {"a" => 5}
|
30
|
-
expect(JSON::Validator.
|
37
|
+
expect(JSON::Validator.fully_validate(simple_schema, data, opt)).to eq([])
|
31
38
|
end
|
32
39
|
|
33
|
-
it "returns
|
40
|
+
it "returns error on incorrect simple data -- 1" do
|
34
41
|
data = {"a" => 5.2}
|
35
|
-
expect(JSON::Validator.
|
42
|
+
expect(JSON::Validator.
|
43
|
+
fully_validate(simple_schema, data, opt)[0]).to include(
|
44
|
+
"property '#/a' of type number did not match the following type: integer")
|
36
45
|
end
|
37
46
|
|
38
|
-
it "returns
|
47
|
+
it "returns error on incorrect simple data -- 2" do
|
39
48
|
data = {"a" => "Kangaroo"}
|
40
|
-
expect(JSON::Validator.
|
49
|
+
expect(JSON::Validator.
|
50
|
+
fully_validate(simple_schema, data, opt)[0]).to include(
|
51
|
+
"property '#/a' of type string did not match the following type: integer")
|
52
|
+
|
41
53
|
end
|
42
54
|
|
43
55
|
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
|
@@ -53,29 +65,33 @@ module Marty
|
|
53
65
|
}
|
54
66
|
}
|
55
67
|
|
56
|
-
it "returns
|
68
|
+
it "returns no error on correct existing enums" do
|
57
69
|
data = {"a" => 'Dog'}
|
58
|
-
expect(JSON::Validator.
|
70
|
+
expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
|
59
71
|
end
|
60
72
|
|
61
|
-
it "vacuously returns
|
73
|
+
it "vacuously returns no error on a field not validated" do
|
62
74
|
data = {"b" => 'Dawg'}
|
63
|
-
expect(JSON::Validator.
|
75
|
+
expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
|
64
76
|
end
|
65
77
|
|
66
|
-
it "returns
|
78
|
+
it "returns error on non-existant enums" do
|
67
79
|
data = {"a" => 'Beer'}
|
68
|
-
expect(JSON::Validator.
|
80
|
+
expect(JSON::Validator.
|
81
|
+
fully_validate(pg_schema_opt, data, opt)[0]).to include(
|
82
|
+
"property '#/a' value 'Beer' not contained in MammalEnum")
|
69
83
|
end
|
70
84
|
|
71
|
-
it "returns
|
85
|
+
it "returns no error when a optional field is not suppplied" do
|
72
86
|
data = {}
|
73
|
-
expect(JSON::Validator.
|
87
|
+
expect(JSON::Validator.fully_validate(pg_schema_opt, data, opt)).to eq([])
|
74
88
|
end
|
75
89
|
|
76
|
-
it "returns
|
90
|
+
it "returns error when a nil enum is passed even when enum is optional" do
|
77
91
|
data = {"a" => nil}
|
78
|
-
expect(JSON::Validator.
|
92
|
+
expect(JSON::Validator.
|
93
|
+
fully_validate(pg_schema_opt, data, opt)[0]).to include(
|
94
|
+
"property '#/a' value '' not contained in MammalEnum")
|
79
95
|
end
|
80
96
|
|
81
97
|
pg_schema_req = {
|
@@ -88,14 +104,52 @@ module Marty
|
|
88
104
|
}
|
89
105
|
}
|
90
106
|
|
91
|
-
it "returns
|
107
|
+
it "returns error when a required field is not supplied" do
|
92
108
|
data = {}
|
93
|
-
expect(JSON::Validator.
|
109
|
+
expect(JSON::Validator.
|
110
|
+
fully_validate(pg_schema_req, data, opt)[0]).to include(
|
111
|
+
"property '#/' did not contain a required property of 'a'")
|
94
112
|
end
|
95
113
|
|
96
|
-
it "returns
|
114
|
+
it "returns error when a nil enum is passed when enum is required" do
|
97
115
|
data = {"a" => nil}
|
98
|
-
expect(JSON::Validator.
|
116
|
+
expect(JSON::Validator.
|
117
|
+
fully_validate(pg_schema_req, data, opt)[0]).to include(
|
118
|
+
"property '#/a' value '' not contained in MammalEnum")
|
119
|
+
end
|
120
|
+
|
121
|
+
pg_schema_req_bad = {
|
122
|
+
"$schema" => "http://json-schema.org/marty-draft/schema#",
|
123
|
+
"required" => ["a"],
|
124
|
+
"properties" => {
|
125
|
+
"a" => {
|
126
|
+
"pg_enum" => "NotAnEnum"
|
127
|
+
},
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
it "returns raises meaningful error on schema enum error" do
|
132
|
+
data = {"a" => nil}
|
133
|
+
expect(JSON::Validator.
|
134
|
+
fully_validate(pg_schema_req_bad, data, opt)[0]).to include(
|
135
|
+
"property '#/a': 'NotAnEnum' is not a pg_enum class")
|
136
|
+
end
|
137
|
+
|
138
|
+
pg_schema_req_bad2 = {
|
139
|
+
"$schema" => "http://json-schema.org/marty-draft/schema#",
|
140
|
+
"required" => ["a"],
|
141
|
+
"properties" => {
|
142
|
+
"a" => {
|
143
|
+
"pg_enum" => "NotEvenAClass"
|
144
|
+
},
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
it "returns raises meaningful error on schema enum error" do
|
149
|
+
data = {"a" => nil}
|
150
|
+
expect(JSON::Validator.
|
151
|
+
fully_validate(pg_schema_req_bad2, data, opt)[0]).to include(
|
152
|
+
"property '#/a': 'NotEvenAClass' is not a pg_enum class")
|
99
153
|
end
|
100
154
|
|
101
155
|
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
|
@@ -122,14 +176,18 @@ module Marty
|
|
122
176
|
expect(JSON::Validator.validate(date_schema_opt, data)).to be true
|
123
177
|
end
|
124
178
|
|
125
|
-
it "returns
|
179
|
+
it "returns error on an improperly formatted date" do
|
126
180
|
data = {"a" => '2017-05-32'}
|
127
|
-
expect(JSON::Validator.
|
181
|
+
expect(JSON::Validator.
|
182
|
+
fully_validate(date_schema_opt, data, opt)[0]).to include(
|
183
|
+
"property '#/a' must be a date in the format of YYYY-MM-DD")
|
128
184
|
end
|
129
185
|
|
130
|
-
it "returns
|
186
|
+
it "returns error on an properly formatted datetime" do
|
131
187
|
data = {"a" => '2017-05-22T14:51:44Z'}
|
132
|
-
expect(JSON::Validator.
|
188
|
+
expect(JSON::Validator.
|
189
|
+
fully_validate(date_schema_opt, data, opt)[0]).to include(
|
190
|
+
"property '#/a' must be a date in the format of YYYY-MM-DD")
|
133
191
|
end
|
134
192
|
|
135
193
|
it "returns true when an optional date is not supplied" do
|
@@ -137,9 +195,11 @@ module Marty
|
|
137
195
|
expect(JSON::Validator.validate(date_schema_opt, data)).to be true
|
138
196
|
end
|
139
197
|
|
140
|
-
it "returns
|
198
|
+
it "returns error when a nil date is passed even when date is optional" do
|
141
199
|
data = {"a" => nil}
|
142
|
-
expect(JSON::Validator.
|
200
|
+
expect(JSON::Validator.
|
201
|
+
fully_validate(date_schema_opt, data, opt)[0]).to include(
|
202
|
+
"property '#/a' of type null did not match the following type: string")
|
143
203
|
end
|
144
204
|
|
145
205
|
date_schema_req = {
|
@@ -153,14 +213,18 @@ module Marty
|
|
153
213
|
}
|
154
214
|
}
|
155
215
|
|
156
|
-
it "returns
|
216
|
+
it "returns error when a required date field is not supplied" do
|
157
217
|
data = {}
|
158
|
-
expect(JSON::Validator.
|
218
|
+
expect(JSON::Validator.
|
219
|
+
fully_validate(date_schema_req, data, opt)[0]).to include(
|
220
|
+
"property '#/' did not contain a required property of 'a'")
|
159
221
|
end
|
160
222
|
|
161
|
-
it "returns
|
223
|
+
it "returns error when a nil date is passed when date is required" do
|
162
224
|
data = {"a" => nil}
|
163
|
-
expect(JSON::Validator.
|
225
|
+
expect(JSON::Validator.
|
226
|
+
fully_validate(date_schema_req, data, opt)[0]).to include(
|
227
|
+
"property '#/a' of type null did not match the following type: string")
|
164
228
|
end
|
165
229
|
|
166
230
|
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
|
@@ -187,9 +251,11 @@ module Marty
|
|
187
251
|
expect(JSON::Validator.validate(datetime_schema_opt, data)).to be true
|
188
252
|
end
|
189
253
|
|
190
|
-
it "returns
|
254
|
+
it "returns error on an improperly formatted datetime" do
|
191
255
|
data = {"a" => '2017-30-22T14:51:44Z'}
|
192
|
-
expect(JSON::Validator.
|
256
|
+
expect(JSON::Validator.
|
257
|
+
fully_validate(datetime_schema_opt, data, opt)[0]).to include(
|
258
|
+
"property '#/a' must be a date/time in the ISO-8601 format")
|
193
259
|
end
|
194
260
|
|
195
261
|
it "returns true when an opt field is not supplied" do
|
@@ -197,9 +263,11 @@ module Marty
|
|
197
263
|
expect(JSON::Validator.validate(datetime_schema_opt, data)).to be true
|
198
264
|
end
|
199
265
|
|
200
|
-
it "returns
|
266
|
+
it "returns error when a nil dt is passed even when dt is opt" do
|
201
267
|
data = {"a" => nil}
|
202
|
-
expect(JSON::Validator.
|
268
|
+
expect(JSON::Validator.
|
269
|
+
fully_validate(datetime_schema_opt, data, opt)[0]).to include(
|
270
|
+
"property '#/a' of type null did not match the following type: string")
|
203
271
|
end
|
204
272
|
|
205
273
|
datetime_schema_req = {
|
@@ -213,14 +281,18 @@ module Marty
|
|
213
281
|
}
|
214
282
|
}
|
215
283
|
|
216
|
-
it "returns
|
284
|
+
it "returns error when a required field is not supplied" do
|
217
285
|
data = {}
|
218
|
-
expect(JSON::Validator.
|
286
|
+
expect(JSON::Validator.
|
287
|
+
fully_validate(datetime_schema_req, data, opt)[0]).to include(
|
288
|
+
"property '#/' did not contain a required property of 'a'")
|
219
289
|
end
|
220
290
|
|
221
|
-
it "returns
|
291
|
+
it "returns error when a nil dt is passed when dt is required" do
|
222
292
|
data = {"a" => nil}
|
223
|
-
expect(JSON::Validator.
|
293
|
+
expect(JSON::Validator.
|
294
|
+
fully_validate(datetime_schema_req, data, opt)[0]).to include(
|
295
|
+
"property '#/a' of type null did not match the following type: string")
|
224
296
|
end
|
225
297
|
|
226
298
|
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
|
@@ -420,7 +492,7 @@ module Marty
|
|
420
492
|
|
421
493
|
it "validates a complex nested schema when incorrect -- 1" do
|
422
494
|
data = { "a" => 'Dog',
|
423
|
-
"b" => '2017-05-32T14:51:44Z', #
|
495
|
+
"b" => '2017-05-32T14:51:44Z', # note DD
|
424
496
|
"root1" => [ { "x" => {"w" => 0, "t" => 'Bear', "f" => 0.0},
|
425
497
|
"y" => 'Phone' },
|
426
498
|
{ "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
|
@@ -449,7 +521,9 @@ module Marty
|
|
449
521
|
"c" => 'Terminator',
|
450
522
|
"d" => 5
|
451
523
|
}
|
452
|
-
expect(JSON::Validator.
|
524
|
+
expect(JSON::Validator.
|
525
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
526
|
+
"property '#/root1/0/x/t' value 'Bar' not contained in MammalEnum")
|
453
527
|
end
|
454
528
|
|
455
529
|
it "validates a complex nested schema when incorrect -- 3" do
|
@@ -466,7 +540,9 @@ module Marty
|
|
466
540
|
"c" => 'Terminator',
|
467
541
|
"d" => 5
|
468
542
|
}
|
469
|
-
expect(JSON::Validator.
|
543
|
+
expect(JSON::Validator.
|
544
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
545
|
+
"property '#/root1/1/x/f' was not divisible by 5.0")
|
470
546
|
end
|
471
547
|
|
472
548
|
it "validates a complex nested schema when incorrect -- 4" do
|
@@ -483,7 +559,10 @@ module Marty
|
|
483
559
|
"c" => 'Terminator',
|
484
560
|
"d" => 5
|
485
561
|
}
|
486
|
-
expect(JSON::Validator.
|
562
|
+
expect(JSON::Validator.
|
563
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
564
|
+
"property '#/root1/1/y' value 'Trminator' not contained "\
|
565
|
+
"in ElectronicsEnum")
|
487
566
|
end
|
488
567
|
|
489
568
|
it "validates a complex nested schema when incorrect -- 5" do
|
@@ -500,7 +579,9 @@ module Marty
|
|
500
579
|
"c" => 'Terminator',
|
501
580
|
"d" => 5
|
502
581
|
}
|
503
|
-
expect(JSON::Validator.
|
582
|
+
expect(JSON::Validator.
|
583
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
584
|
+
"property '#/root1/2/x/w' did not have a maximum value of 3, inclusively")
|
504
585
|
end
|
505
586
|
|
506
587
|
it "validates a complex nested schema when incorrect -- 6" do
|
@@ -510,14 +591,16 @@ module Marty
|
|
510
591
|
"y" => 'Phone' },
|
511
592
|
{ "x" => {"w" => 1, "t" => 'Human', "f" => 5.0},
|
512
593
|
"y" => 'Terminator' },
|
513
|
-
{ "x" => {"w" => 5, "t" => 'Dog', "f" => 65.0}, #
|
594
|
+
{ "x" => {"w" => -5, "t" => 'Dog', "f" => 65.0}, #
|
514
595
|
"y" => 'Phone' } ],
|
515
596
|
"root2" => [ {"m1" => 'Cat', "e" => 'Keyboard', "m2" => 'Dog' },
|
516
597
|
{"m1" => 'Dog', "e" => 'Phone', "m2" => 'Cow' }],
|
517
598
|
"c" => 'Terminator',
|
518
599
|
"d" => 5
|
519
600
|
}
|
520
|
-
expect(JSON::Validator.
|
601
|
+
expect(JSON::Validator.
|
602
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
603
|
+
"property '#/root1/2/x/w' did not have a minimum value of 0, inclusively")
|
521
604
|
end
|
522
605
|
|
523
606
|
it "validates a complex nested schema when incorrect -- 7" do
|
@@ -534,7 +617,9 @@ module Marty
|
|
534
617
|
"c" => 'Terminator',
|
535
618
|
"d" => 5
|
536
619
|
}
|
537
|
-
expect(JSON::Validator.
|
620
|
+
expect(JSON::Validator.
|
621
|
+
fully_validate(nested_schema, data, opt)[0]).to include(
|
622
|
+
"property '#/root2/1/e' value 'Dog' not contained in ElectronicsEnum")
|
538
623
|
end
|
539
624
|
|
540
625
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: marty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2017-09-
|
17
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: pg
|