committee 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ module Committee::Middleware
10
10
  data = MultiJson.decode(data)
11
11
  end
12
12
  @schema = JsonSchema.parse!(data)
13
+ @schema.expand_references!
13
14
  @router = Committee::Router.new(@schema)
14
15
  end
15
16
 
@@ -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 = error_messages(errors).join("\n")
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
@@ -1,7 +1,7 @@
1
1
  module Committee
2
2
  class ResponseGenerator
3
3
  def call(link)
4
- data = generate_properties(link.parent)
4
+ data = generate_properties(link.target_schema || link.parent)
5
5
 
6
6
  # list is a special case; wrap data in an array
7
7
  data = [data] if link.rel == "instances"
@@ -2,7 +2,11 @@ module Committee
2
2
  class ResponseValidator
3
3
  def initialize(link)
4
4
  @link = link
5
- @validator = JsonSchema::Validator.new(link.parent)
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 ||= JsonSchema.parse!(data)
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\nAt "/schema/app": Expected string to match pattern "/^[a-z][a-z0-9-]{3,30}$/", value was: %@!.}
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
 
@@ -4,6 +4,7 @@ describe Committee::ResponseGenerator 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
  # GET /apps/:id
8
9
  @get_link = @link = @schema.properties["app"].links[2]
9
10
  # GET /apps
@@ -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 #/properties/app/properties/name: Expected string to match pattern "/^[a-z][a-z0-9-]{3,30}$/", value was: %@!.}
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
 
@@ -4,6 +4,7 @@ describe Committee::Router do
4
4
  before do
5
5
  data = MultiJson.decode(File.read("./test/data/schema.json"))
6
6
  schema = JsonSchema.parse!(data)
7
+ schema.expand_references!
7
8
  @router = Committee::Router.new(schema)
8
9
  end
9
10
 
@@ -1,6 +1,7 @@
1
1
  require "minitest"
2
2
  require "minitest/spec"
3
3
  require "minitest/autorun"
4
+ #require "pry-rescue/minitest"
4
5
  require "rack/test"
5
6
  require "rr"
6
7
 
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.2
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-23 00:00:00.000000000 Z
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.13
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.13
30
+ version: 0.0.20
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: multi_json
33
33
  requirement: !ruby/object:Gem::Requirement