json-schema_builder 0.1.0 → 0.2.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bbd02201c3857389c10b1fb7b2646da0876826
|
4
|
+
data.tar.gz: 0d3d2b317e2c95e1949c11b2541e9018ad1f3611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64c161e632998919d104674c86a26095a20cdeb98f18031015efeb4fce44fc5f15dab9727e5621732b015a3c85ad97e7204f9f3713b7b0aa8102668cadbf836c
|
7
|
+
data.tar.gz: 8d6127dda6fbca78783ed2b42ab7d58fbe5a7bde5d75b86b4601b38e3091089118e4ea6c6510e46c900f5ac3c8c6e69ae0c4a8861e31809f00111320c563012f
|
data/lib/json/schema_builder.rb
CHANGED
@@ -13,6 +13,26 @@ module JSON
|
|
13
13
|
child.eval_block &block
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
def object_or_array(*args, &block)
|
18
|
+
opts = args.extract_options!
|
19
|
+
name = args.shift
|
20
|
+
nullable = opts.delete :null
|
21
|
+
|
22
|
+
entity name do
|
23
|
+
list = [
|
24
|
+
object(*args, opts) { |child| child.eval_block(&block) },
|
25
|
+
array {
|
26
|
+
items {
|
27
|
+
object(*args, opts) { |child| child.eval_block(&block) }
|
28
|
+
}
|
29
|
+
}
|
30
|
+
]
|
31
|
+
|
32
|
+
list << null if nullable
|
33
|
+
any_of list
|
34
|
+
end
|
35
|
+
end
|
16
36
|
end
|
17
37
|
end
|
18
38
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Examples::ObjectOrArray, type: :integration do
|
4
|
+
it_behaves_like 'a builder' do
|
5
|
+
let(:expected_json) do
|
6
|
+
{
|
7
|
+
anyOf: [{
|
8
|
+
type: :object,
|
9
|
+
additionalProperties: false,
|
10
|
+
properties: {
|
11
|
+
thing: { type: :any },
|
12
|
+
other: {
|
13
|
+
anyOf: [{
|
14
|
+
type: :object,
|
15
|
+
additionalProperties: false,
|
16
|
+
properties: {
|
17
|
+
stuff: { type: :string }
|
18
|
+
}
|
19
|
+
}, {
|
20
|
+
type: :array,
|
21
|
+
items: {
|
22
|
+
type: :object,
|
23
|
+
additionalProperties: false,
|
24
|
+
properties: {
|
25
|
+
stuff: { type: :string }
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}]
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}, {
|
32
|
+
type: :array,
|
33
|
+
items: {
|
34
|
+
type: :object,
|
35
|
+
additionalProperties: false,
|
36
|
+
properties: {
|
37
|
+
thing: { type: :any },
|
38
|
+
other: {
|
39
|
+
anyOf: [{
|
40
|
+
type: :object,
|
41
|
+
additionalProperties: false,
|
42
|
+
properties: {
|
43
|
+
stuff: {
|
44
|
+
type: :string
|
45
|
+
}
|
46
|
+
},
|
47
|
+
},
|
48
|
+
{
|
49
|
+
type: :array,
|
50
|
+
items: {
|
51
|
+
type: :object,
|
52
|
+
additionalProperties: false,
|
53
|
+
properties: {
|
54
|
+
stuff: {
|
55
|
+
type: :string
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}]
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}, {
|
64
|
+
type: :null
|
65
|
+
}]
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Examples
|
2
|
+
class ObjectOrArray
|
3
|
+
include JSON::SchemaBuilder
|
4
|
+
|
5
|
+
def example
|
6
|
+
object_or_array additional_properties: false, null: true do
|
7
|
+
any :thing
|
8
|
+
|
9
|
+
object_or_array :other, additional_properties: false do
|
10
|
+
string :stuff
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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.2.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-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- spec/integration/mixed_arrays_spec.rb
|
152
152
|
- spec/integration/mixed_objects_spec.rb
|
153
153
|
- spec/integration/object_definitions_spec.rb
|
154
|
+
- spec/integration/object_or_array_spec.rb
|
154
155
|
- spec/integration/rooted_spec.rb
|
155
156
|
- spec/integration/schema_builder_spec.rb
|
156
157
|
- spec/integration/scope_breaking_spec.rb
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- spec/support/examples/mixed_arrays.rb
|
169
170
|
- spec/support/examples/mixed_objects.rb
|
170
171
|
- spec/support/examples/object_definitions.rb
|
172
|
+
- spec/support/examples/object_or_array.rb
|
171
173
|
- spec/support/examples/rooted.rb
|
172
174
|
- spec/support/examples/schema_builder.rb
|
173
175
|
- spec/support/examples/scope_breaking.rb
|
@@ -221,6 +223,7 @@ test_files:
|
|
221
223
|
- spec/integration/mixed_arrays_spec.rb
|
222
224
|
- spec/integration/mixed_objects_spec.rb
|
223
225
|
- spec/integration/object_definitions_spec.rb
|
226
|
+
- spec/integration/object_or_array_spec.rb
|
224
227
|
- spec/integration/rooted_spec.rb
|
225
228
|
- spec/integration/schema_builder_spec.rb
|
226
229
|
- spec/integration/scope_breaking_spec.rb
|
@@ -238,6 +241,7 @@ test_files:
|
|
238
241
|
- spec/support/examples/mixed_arrays.rb
|
239
242
|
- spec/support/examples/mixed_objects.rb
|
240
243
|
- spec/support/examples/object_definitions.rb
|
244
|
+
- spec/support/examples/object_or_array.rb
|
241
245
|
- spec/support/examples/rooted.rb
|
242
246
|
- spec/support/examples/schema_builder.rb
|
243
247
|
- spec/support/examples/scope_breaking.rb
|