committee 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/committee/middleware/base.rb +1 -0
- data/lib/committee/request_validator.rb +1 -13
- data/lib/committee/response_generator.rb +1 -1
- data/lib/committee/response_validator.rb +5 -1
- data/lib/committee/test/methods.rb +5 -1
- data/test/request_validator_test.rb +2 -1
- data/test/response_generator_test.rb +1 -0
- data/test/response_validator_test.rb +2 -1
- data/test/router_test.rb +1 -0
- data/test/test_helper.rb +1 -0
- metadata +4 -4
@@ -7,22 +7,10 @@ module Committee
|
|
7
7
|
if link.schema
|
8
8
|
valid, errors = link.schema.validate(params)
|
9
9
|
if !valid
|
10
|
-
errors =
|
10
|
+
errors = JsonSchema::SchemaError.aggregate(errors).join("\n")
|
11
11
|
raise InvalidRequest, "Invalid request.\n\n#{errors}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def error_messages(errors)
|
19
|
-
errors.map do |error|
|
20
|
-
if error.schema
|
21
|
-
%{At "#{error.schema.uri}": #{error.message}}
|
22
|
-
else
|
23
|
-
error.message
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
15
|
end
|
28
16
|
end
|
@@ -2,7 +2,11 @@ module Committee
|
|
2
2
|
class ResponseValidator
|
3
3
|
def initialize(link)
|
4
4
|
@link = link
|
5
|
-
|
5
|
+
|
6
|
+
# we should eventually move off of validating against parent schema too
|
7
|
+
# ... this is a Herokuism and not in the specification
|
8
|
+
schema = link.target_schema || link.parent
|
9
|
+
@validator = JsonSchema::Validator.new(schema)
|
6
10
|
end
|
7
11
|
|
8
12
|
def call(headers, data)
|
@@ -6,7 +6,11 @@ module Committee::Test
|
|
6
6
|
data = MultiJson.decode(data)
|
7
7
|
end
|
8
8
|
|
9
|
-
@schema ||=
|
9
|
+
@schema ||= begin
|
10
|
+
schema = JsonSchema.parse!(data)
|
11
|
+
schema.expand_references!
|
12
|
+
schema
|
13
|
+
end
|
10
14
|
@router ||= Committee::Router.new(@schema)
|
11
15
|
|
12
16
|
link =
|
@@ -4,6 +4,7 @@ describe Committee::RequestValidator do
|
|
4
4
|
before do
|
5
5
|
@schema =
|
6
6
|
JsonSchema.parse!(MultiJson.decode(File.read("./test/data/schema.json")))
|
7
|
+
@schema.expand_references!
|
7
8
|
# POST /apps/:id
|
8
9
|
@link = @link = @schema.properties["app"].links[0]
|
9
10
|
end
|
@@ -22,7 +23,7 @@ describe Committee::RequestValidator do
|
|
22
23
|
e = assert_raises(Committee::InvalidRequest) do
|
23
24
|
call(params)
|
24
25
|
end
|
25
|
-
message = %{Invalid request.\n\
|
26
|
+
message = %{Invalid request.\n\n#/name: failed schema #/definitions/app/links/0/schema/properties/name: Expected string to match pattern "/^[a-z][a-z0-9-]{3,30}$/", value was: %@!.}
|
26
27
|
assert_equal message, e.message
|
27
28
|
end
|
28
29
|
|
@@ -8,6 +8,7 @@ describe Committee::ResponseValidator do
|
|
8
8
|
}
|
9
9
|
@schema =
|
10
10
|
JsonSchema.parse!(MultiJson.decode(File.read("./test/data/schema.json")))
|
11
|
+
@schema.expand_references!
|
11
12
|
# GET /apps/:id
|
12
13
|
@get_link = @link = @schema.properties["app"].links[2]
|
13
14
|
# GET /apps
|
@@ -43,7 +44,7 @@ describe Committee::ResponseValidator do
|
|
43
44
|
it "raises errors generated by json_schema" do
|
44
45
|
@data.merge!("name" => "%@!")
|
45
46
|
e = assert_raises(Committee::InvalidResponse) { call }
|
46
|
-
message = %{Invalid response.\n\n#/name: failed schema #/
|
47
|
+
message = %{Invalid response.\n\n#/name: failed schema #/definitions/app/properties/name: Expected string to match pattern "/^[a-z][a-z0-9-]{3,30}$/", value was: %@!.}
|
47
48
|
assert_equal message, e.message
|
48
49
|
end
|
49
50
|
|
data/test/router_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-05-
|
13
|
+
date: 2014-05-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.0.
|
22
|
+
version: 0.0.20
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 0.0.
|
30
|
+
version: 0.0.20
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: multi_json
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|