json-schema_builder 0.7.0 → 0.7.1

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
  SHA1:
3
- metadata.gz: 7b51dc48c6af5bbc967ad1a806b0bcc62f2cc042
4
- data.tar.gz: 541ffe361c94466b483d7836df3c3afd1546d813
3
+ metadata.gz: 74990c32e6a0f3818690fb0ce66adcb7bb14bd4e
4
+ data.tar.gz: 359ba84e515b4c059320954bcfdaaf84de2dfc1b
5
5
  SHA512:
6
- metadata.gz: 410edbc4fb0e6ca11923a2db72002c3c3147f6f5819abab96898344c92394639a68acb87796c1204ba5abf2d56cb1432b5e46fb8a1754f643c9550b704774744
7
- data.tar.gz: bfb69c49836656cd6a671c5a5fa9021f5cfc9ca16e3601bf6a9dfce48645fbf2569b24749e2b7e83ed970f5fda15978d16e069e8ce629e33fb2ca7157cca349c
6
+ metadata.gz: 0c146bbba22320150069cec3b4e903ca505748775a001ef412a49aa740c488de989ffc8ee465256f13bf734dd36c4585542774efbffc1824f3f3d795680a84ad
7
+ data.tar.gz: f5070d30ab1296356e8297de145c174e8b89e768854a1d1f4dbe73c2dc0ca86dac59141373ff4c84ce435a410c6ebeb47c7668274c9ee80c1ed0a8ba19b1ae7d
@@ -71,6 +71,7 @@ module JSON
71
71
  end
72
72
 
73
73
  def merge_children!
74
+ return if any_of.present?
74
75
  children.each do |child|
75
76
  schema.merge! child.schema
76
77
  end
@@ -13,8 +13,15 @@ module JSON
13
13
 
14
14
  def initialize_children
15
15
  self.properties = { }
16
+
16
17
  children.select(&:name).each do |child|
17
- self.properties[child.name] = child.as_json
18
+ case child.name
19
+ when Regexp
20
+ self.pattern_properties ||= { }
21
+ self.pattern_properties[child.name.source] = child.as_json
22
+ else
23
+ self.properties[child.name] = child.as_json
24
+ end
18
25
  end
19
26
  end
20
27
 
@@ -1,5 +1,5 @@
1
1
  module JSON
2
2
  module SchemaBuilder
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
5
5
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Examples::ArrayAnyOf, type: :integration do
4
+ it_behaves_like 'a builder' do
5
+ let(:expected_json) do
6
+ {
7
+ type: :object,
8
+ properties: {
9
+ an_array: {
10
+ type: :array,
11
+ items: {
12
+ anyOf: [
13
+ {
14
+ type: :object,
15
+ properties: {
16
+ a_string: {
17
+ type: :string
18
+ }
19
+ }
20
+ },
21
+ {
22
+ type: :object,
23
+ properties: {
24
+ a_number: {
25
+ type: :number
26
+ }
27
+ }
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ }
33
+ }
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ module Examples
2
+ class ArrayAnyOf
3
+ include JSON::SchemaBuilder
4
+
5
+ def example
6
+ object do
7
+ array :an_array do
8
+ items do
9
+ any_of [
10
+ object { string(:a_string) },
11
+ object { number(:a_number) }
12
+ ]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -16,13 +16,17 @@ RSpec.describe JSON::SchemaBuilder::Object, type: :unit do
16
16
  described_class.new 'name' do
17
17
  string :test1
18
18
  string :test2
19
+ string /^_/
20
+ string /^\./
19
21
  end
20
22
  end
21
23
 
22
24
  let(:string){ kind_of JSON::SchemaBuilder::String }
23
25
  its(:children){ is_expected.to include string }
24
- its('children.length'){ is_expected.to eql 2 }
26
+ its('children.length'){ is_expected.to eql 4 }
25
27
  its('properties'){ is_expected.to include test1: { 'type' => 'string' } }
26
28
  its('properties'){ is_expected.to include test2: { 'type' => 'string' } }
29
+ its('pattern_properties'){ is_expected.to include '^_' => { 'type' => 'string' } }
30
+ its('pattern_properties'){ is_expected.to include '^\.' => { 'type' => 'string' } }
27
31
  end
28
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-14 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -201,6 +201,7 @@ files:
201
201
  - lib/json/schema_builder/string.rb
202
202
  - lib/json/schema_builder/validation.rb
203
203
  - lib/json/schema_builder/version.rb
204
+ - spec/integration/array_any_of_spec.rb
204
205
  - spec/integration/array_definitions_spec.rb
205
206
  - spec/integration/context_delegation_spec.rb
206
207
  - spec/integration/custom_errors_spec.rb
@@ -221,6 +222,7 @@ files:
221
222
  - spec/spec_helper.rb
222
223
  - spec/support/.keep
223
224
  - spec/support/attribute_matcher.rb
225
+ - spec/support/examples/array_any_of.rb
224
226
  - spec/support/examples/array_definitions.rb
225
227
  - spec/support/examples/context_delegation.rb
226
228
  - spec/support/examples/custom_errors.rb
@@ -277,6 +279,7 @@ signing_key:
277
279
  specification_version: 4
278
280
  summary: Build JSON schemas with Ruby
279
281
  test_files:
282
+ - spec/integration/array_any_of_spec.rb
280
283
  - spec/integration/array_definitions_spec.rb
281
284
  - spec/integration/context_delegation_spec.rb
282
285
  - spec/integration/custom_errors_spec.rb
@@ -297,6 +300,7 @@ test_files:
297
300
  - spec/spec_helper.rb
298
301
  - spec/support/.keep
299
302
  - spec/support/attribute_matcher.rb
303
+ - spec/support/examples/array_any_of.rb
300
304
  - spec/support/examples/array_definitions.rb
301
305
  - spec/support/examples/context_delegation.rb
302
306
  - spec/support/examples/custom_errors.rb