json-schema_builder 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -1
- data/Appraisals +5 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/activesupport_4.0.gemfile +7 -0
- data/gemfiles/activesupport_4.1.gemfile +7 -0
- data/gemfiles/activesupport_4.2.gemfile +7 -0
- data/gemfiles/activesupport_5.0.gemfile +7 -0
- data/gemfiles/activesupport_5.1.gemfile +7 -0
- data/json-schema_builder.gemspec +1 -0
- data/lib/json/schema_builder/schema.rb +20 -2
- data/lib/json/schema_builder/version.rb +1 -1
- data/spec/unit/schema_spec.rb +39 -2
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0912320b00a0b8b43307a99560e5ac3f5f6eadee'
|
4
|
+
data.tar.gz: d74be2254534647d26b11c3f84dc22b67e9ac477
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d9d7ea22df0b6c54e82cbb18edbe29e28e9f43efe51d97e306fec2eb68599c44ca9adf8c68ebfeb78a48010f3037f53566be7dfc7e1b024c0af6b2843fdac2d
|
7
|
+
data.tar.gz: f65201e295b2b744af78907cc67f57d85f1e4d9280ede6b2c8d945443da56fb2ead8237f78f10aa321e5246ef3db5fddd6b4447709a42830f8e45849e056648e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
script: bundle exec rspec
|
3
3
|
rvm:
|
4
|
-
- 2.
|
4
|
+
- 2.2.8
|
5
|
+
- 2.3.5
|
6
|
+
- 2.4.2
|
5
7
|
addons:
|
6
8
|
code_climate:
|
7
9
|
repo_token:
|
8
10
|
secure: X3mDel/6C4d8uSeaKgxA2YP4Oen5N2iklmi2mH1XzK3UihzlNKcQLxYC6IMTTfYiPlLu1BTO1KTElUqWIigpHxAAJj/Lb48S8mvKFAsmv48tOP5LaTeFNdnJA49k0hCXQbItlyVBmUhEtkdyelLciP3ygcKgEcR/jZGcJM/aZBY=
|
11
|
+
gemfile:
|
12
|
+
- gemfiles/activesupport_4.0.gemfile
|
13
|
+
- gemfiles/activesupport_4.1.gemfile
|
14
|
+
- gemfiles/activesupport_4.2.gemfile
|
15
|
+
- gemfiles/activesupport_5.0.gemfile
|
16
|
+
- gemfiles/activesupport_5.1.gemfile
|
data/Appraisals
ADDED
data/json-schema_builder.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.4'
|
24
24
|
spec.add_development_dependency 'rspec-its'
|
25
25
|
spec.add_development_dependency 'pry-byebug'
|
26
|
+
spec.add_development_dependency 'appraisal'
|
26
27
|
spec.add_dependency 'activesupport', '>= 4.0'
|
27
28
|
spec.add_dependency 'json-schema', '>= 2'
|
28
29
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module JSON
|
2
2
|
module SchemaBuilder
|
3
3
|
class Schema
|
4
|
-
|
4
|
+
attr_accessor :data
|
5
5
|
delegate :[], :[]=, :to_h, :as_json, to: :data
|
6
6
|
|
7
7
|
def initialize(hash = {})
|
@@ -19,13 +19,31 @@ module JSON
|
|
19
19
|
|
20
20
|
def _deep_merge(this, other)
|
21
21
|
this.deep_merge(other) do |current_key, this_value, other_value|
|
22
|
-
if
|
22
|
+
if current_key == "anyOf"
|
23
|
+
_deep_merge_any_of(Array(this_value), Array(other_value))
|
24
|
+
elsif this_value.is_a?(::Array) && other_value.is_a?(::Array)
|
23
25
|
this_value + other_value
|
24
26
|
else
|
25
27
|
other_value
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
31
|
+
|
32
|
+
def _deep_merge_any_of(this, other)
|
33
|
+
object = self.class.new
|
34
|
+
combined = []
|
35
|
+
|
36
|
+
(this + other).each do |item|
|
37
|
+
if item[:type].to_sym == :object
|
38
|
+
object.data = object._deep_merge(object.data, item)
|
39
|
+
else
|
40
|
+
combined << item
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
combined << object.data unless object.data.empty?
|
45
|
+
combined.uniq
|
46
|
+
end
|
29
47
|
end
|
30
48
|
end
|
31
49
|
end
|
data/spec/unit/schema_spec.rb
CHANGED
@@ -1,8 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe JSON::SchemaBuilder::Schema, type: :unit do
|
4
|
-
let(:schema)
|
5
|
-
|
4
|
+
let(:schema) do
|
5
|
+
described_class.new a: 1, b: { c: 3 }, array: [123, { foo: 1, bar: { baz: 0 }}], anyOf: [
|
6
|
+
{ type: "null" },
|
7
|
+
{ type: "string" },
|
8
|
+
{
|
9
|
+
type: "object",
|
10
|
+
properties: {
|
11
|
+
one: { type: "string" },
|
12
|
+
two: { type: "string" }
|
13
|
+
}
|
14
|
+
}
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:other) do
|
19
|
+
described_class.new a: 2, "b" => { d: 4 }, array: [456, { foo: 2, bar: { qux: 1 }}], anyOf: [
|
20
|
+
{ type: "null" },
|
21
|
+
{
|
22
|
+
type: "object",
|
23
|
+
properties: {
|
24
|
+
two: { type: "string" },
|
25
|
+
three: { type: "string" }
|
26
|
+
}
|
27
|
+
}
|
28
|
+
]
|
29
|
+
end
|
30
|
+
|
6
31
|
let(:merged) do
|
7
32
|
{
|
8
33
|
"a" => 2,
|
@@ -23,6 +48,18 @@ RSpec.describe JSON::SchemaBuilder::Schema, type: :unit do
|
|
23
48
|
"qux" => 1
|
24
49
|
}
|
25
50
|
}
|
51
|
+
],
|
52
|
+
"anyOf" => [
|
53
|
+
{ "type" => "null" },
|
54
|
+
{ "type" => "string" },
|
55
|
+
{
|
56
|
+
"type" => "object",
|
57
|
+
"properties" => {
|
58
|
+
"one" => { "type" => "string" },
|
59
|
+
"two" => { "type" => "string" },
|
60
|
+
"three" => { "type" => "string" }
|
61
|
+
}
|
62
|
+
}
|
26
63
|
]
|
27
64
|
}
|
28
65
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: appraisal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: activesupport
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,10 +133,17 @@ files:
|
|
119
133
|
- ".pryrc"
|
120
134
|
- ".rspec"
|
121
135
|
- ".travis.yml"
|
136
|
+
- Appraisals
|
122
137
|
- Gemfile
|
123
138
|
- LICENSE.txt
|
124
139
|
- README.md
|
125
140
|
- Rakefile
|
141
|
+
- gemfiles/.bundle/config
|
142
|
+
- gemfiles/activesupport_4.0.gemfile
|
143
|
+
- gemfiles/activesupport_4.1.gemfile
|
144
|
+
- gemfiles/activesupport_4.2.gemfile
|
145
|
+
- gemfiles/activesupport_5.0.gemfile
|
146
|
+
- gemfiles/activesupport_5.1.gemfile
|
126
147
|
- json-schema_builder.gemspec
|
127
148
|
- lib/json/schema_builder.rb
|
128
149
|
- lib/json/schema_builder/any.rb
|