schema_matcher 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 51684856418fd56fd7ef6a7faabc9c46be7be6110a48110be1870cb2ee1038e5
4
- data.tar.gz: 8e113af8073d7fa372c6411e568a73de2064776227c51f8f1ece2c688f62e36b
3
+ metadata.gz: 773842bd2566a9e84ec13aa802716985e701ff99412cceec55487830c175b787
4
+ data.tar.gz: c4a971362f1fc71ebcb19459b822bfeab0ec0cb222940e7f80c5d2a423cdfae2
5
5
  SHA512:
6
- metadata.gz: 94cf1b55c50e0755ce16580e74fd193775f8863f884da398b15959ec4bdfe80abdeabf94a423b3df24f16a7355006ec579597e9b2ad2a648bcb3a41801aa8174
7
- data.tar.gz: b4dc059a5d1de2ac2091fe791a669080d30c40d40ed8d19ea67676996c0fcae895b788d292ebeeefd65a93d575b79fbd177f81c4b2a9784db90a74e49f4021cb
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
- SchemaMatcher
27
- .schema[schema_name]
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::Draft4
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['properties'] = JSON::Schema::PropertiesAttribute
10
+ @attributes['$ref'] = ExtendedRefAttribute
11
11
  @uri = URI.parse(SCHEMA_URI)
12
- @names = ['draft4-custom', SCHEMA_URI]
12
+ @names = ['draft3-custom', SCHEMA_URI]
13
13
  end
14
14
  end
15
15
 
16
- class ExtendedTypeAttribute < JSON::Schema::TypeV4Attribute
16
+ module NullablePossibility
17
17
  # rubocop:disable Metrics/ParameterLists
18
- def self.validate(current_schema, data, fragments, processor, validator, options = {})
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
@@ -1,3 +1,3 @@
1
1
  module SchemaMatcher
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  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.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-07-29 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema