schema_matcher 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema_matcher/assertion.rb +12 -4
- data/lib/schema_matcher/extended_schema.rb +13 -5
- data/lib/schema_matcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 773842bd2566a9e84ec13aa802716985e701ff99412cceec55487830c175b787
|
4
|
+
data.tar.gz: c4a971362f1fc71ebcb19459b822bfeab0ec0cb222940e7f80c5d2a423cdfae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccc99d4d80f7f4476cddbf75f01f3878fc017b71d0a8489c92d3794529bd9083afcca3d5a4296e27bec0ef4ce3a4c8644c9d380e26ed0277058242819e2add8d
|
7
|
+
data.tar.gz: 48189cecce55bc08bda9b43794a93f1a27167fae631193565ce1e165ddb33f6a66fcc4a57a19573077fc611bf577986c3fb1a77f3188cfb99db18ba4d3b52ea4
|
@@ -23,16 +23,24 @@ module SchemaMatcher
|
|
23
23
|
attr_reader :payload, :schema_name, :last_error_message, :options
|
24
24
|
|
25
25
|
def schema
|
26
|
-
|
27
|
-
|
26
|
+
entity_schema =
|
27
|
+
if array?
|
28
|
+
{ 'type' => 'array', 'items' => SchemaMatcher.schema[schema_name] }
|
29
|
+
else
|
30
|
+
SchemaMatcher.schema[schema_name]
|
31
|
+
end
|
32
|
+
entity_schema
|
28
33
|
.merge('$schema' => SchemaMatcher::ExtendedSchema::SCHEMA_URI)
|
29
34
|
.merge!(definitions: SchemaMatcher.schema)
|
30
35
|
end
|
31
36
|
|
37
|
+
def array?
|
38
|
+
options.key?(:array) ? options[:array] : payload.is_a?(Array)
|
39
|
+
end
|
40
|
+
|
32
41
|
def validator_options
|
33
42
|
{
|
34
|
-
strict: true
|
35
|
-
list: options.key?(:array) ? options[:array] : payload.is_a?(Array)
|
43
|
+
strict: true
|
36
44
|
}
|
37
45
|
end
|
38
46
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'json-schema'
|
2
2
|
|
3
3
|
module SchemaMatcher
|
4
|
-
class ExtendedSchema < JSON::Schema::
|
4
|
+
class ExtendedSchema < JSON::Schema::Draft3
|
5
5
|
SCHEMA_URI = 'http://tempuri.org/schema_matcher/extended_schema'.freeze
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
super
|
9
9
|
@attributes['type'] = ExtendedTypeAttribute
|
10
|
-
@attributes['
|
10
|
+
@attributes['$ref'] = ExtendedRefAttribute
|
11
11
|
@uri = URI.parse(SCHEMA_URI)
|
12
|
-
@names = ['
|
12
|
+
@names = ['draft3-custom', SCHEMA_URI]
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
module NullablePossibility
|
17
17
|
# rubocop:disable Metrics/ParameterLists
|
18
|
-
def
|
18
|
+
def validate(current_schema, data, fragments, processor, validator, options = {})
|
19
19
|
return if data.nil? && current_schema.schema['x-nullable']
|
20
20
|
|
21
21
|
super
|
@@ -23,5 +23,13 @@ module SchemaMatcher
|
|
23
23
|
# rubocop:enable Metrics/ParameterLists
|
24
24
|
end
|
25
25
|
|
26
|
+
class ExtendedTypeAttribute < JSON::Schema::TypeAttribute
|
27
|
+
extend NullablePossibility
|
28
|
+
end
|
29
|
+
|
30
|
+
class ExtendedRefAttribute < JSON::Schema::RefAttribute
|
31
|
+
extend NullablePossibility
|
32
|
+
end
|
33
|
+
|
26
34
|
JSON::Validator.register_validator(ExtendedSchema.new)
|
27
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Rudskikh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|