committee 1.9.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/committee/response_generator.rb +16 -17
- data/test/response_generator_test.rb +28 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31054e2caff7ac27297eb960c4468de3c182f41e
|
4
|
+
data.tar.gz: d1ce477e98f2590d58b499bf320ac10d3907424c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a05732e09b0c1c97e18cccdc3cabb587a6ed20507b49cc18ff5593721120b647ef56135ae0e9d450b16e7f65f733da3bbf3b135a7e8200d29b1652acc53ee9
|
7
|
+
data.tar.gz: 470050b4314be6de778b53b1a3f84f9f762c85b00010abc6612221daaddac123ffb94addc45ea4e07769976f4f5b6ef559018c7e5053e8085385f7605d42a66d
|
@@ -12,25 +12,24 @@ module Committee
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def generate_properties(schema)
|
15
|
-
|
16
|
-
schema.
|
17
|
-
data[
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# random data based on type/format
|
28
|
-
else
|
29
|
-
raise(%{At "#{schema.id}"/"#{key}": no "example" attribute and "null" is not allowed; don't know how to generate property.})
|
30
|
-
end
|
15
|
+
# special example attribute was included; use its value
|
16
|
+
if !schema.data["example"].nil?
|
17
|
+
schema.data["example"]
|
18
|
+
# null is allowed; use that
|
19
|
+
elsif schema.type.include?("null")
|
20
|
+
nil
|
21
|
+
elsif schema.type.include?("array") && !schema.items.nil?
|
22
|
+
[generate_properties(schema.items)]
|
23
|
+
elsif !schema.properties.empty?
|
24
|
+
data = {}
|
25
|
+
schema.properties.map do |key, value|
|
26
|
+
data[key] = generate_properties(value)
|
31
27
|
end
|
28
|
+
data
|
29
|
+
else
|
30
|
+
raise(%{At "#{schema.pointer}": no "example" attribute and "null" } +
|
31
|
+
%{is not allowed; don't know how to generate property.})
|
32
32
|
end
|
33
|
-
data
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -27,6 +27,34 @@ describe Committee::ResponseGenerator do
|
|
27
27
|
assert data.is_a?(Array)
|
28
28
|
end
|
29
29
|
|
30
|
+
it "wraps list data in an array" do
|
31
|
+
@link = @list_link
|
32
|
+
|
33
|
+
@link.rel = nil
|
34
|
+
|
35
|
+
data = call
|
36
|
+
assert data.is_a?(Array)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "errors with no known route for generation" do
|
40
|
+
@link = @get_link
|
41
|
+
|
42
|
+
# tweak the schema so that it can't be generated
|
43
|
+
property = @schema.properties["app"].properties["maintenance"]
|
44
|
+
property.data["example"] = nil
|
45
|
+
property.type = []
|
46
|
+
|
47
|
+
e = assert_raises(RuntimeError) do
|
48
|
+
call
|
49
|
+
end
|
50
|
+
|
51
|
+
expected = <<-eos.gsub(/\n +/, "").strip
|
52
|
+
At "#/definitions/app/properties/maintenance": no "example" attribute and
|
53
|
+
"null" is not allowed; don't know how to generate property.
|
54
|
+
eos
|
55
|
+
assert_equal expected, e.message
|
56
|
+
end
|
57
|
+
|
30
58
|
def call
|
31
59
|
Committee::ResponseGenerator.new.call(@link)
|
32
60
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_schema
|
@@ -169,8 +169,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
172
|
+
rubygems_version: 2.2.2
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: A collection of Rack middleware to support JSON Schema.
|
176
176
|
test_files: []
|
177
|
+
has_rdoc:
|