committee 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31054e2caff7ac27297eb960c4468de3c182f41e
4
- data.tar.gz: d1ce477e98f2590d58b499bf320ac10d3907424c
3
+ metadata.gz: a4fc461157687d09fe003b166837aa9e8ad7b13d
4
+ data.tar.gz: aabe41cef72a73b9f23941dc2ee7e05f3a2af894
5
5
  SHA512:
6
- metadata.gz: f5a05732e09b0c1c97e18cccdc3cabb587a6ed20507b49cc18ff5593721120b647ef56135ae0e9d450b16e7f65f733da3bbf3b135a7e8200d29b1652acc53ee9
7
- data.tar.gz: 470050b4314be6de778b53b1a3f84f9f762c85b00010abc6612221daaddac123ffb94addc45ea4e07769976f4f5b6ef559018c7e5053e8085385f7605d42a66d
6
+ metadata.gz: ef692420a20da95986e77e558b15ff5d74d01f7710d7039e29d12a0abdf68b1e8a30d836d58a44095cf0af57e9510bb19c00ae740c6eb2df71e973ac83cff83b
7
+ data.tar.gz: 9df276033f41e4ac1c607c2c9d03b1364f25994abc4daeb5ecdff3b41c18a7dba88a72c1b2273f41d2aafc5e0ec73db2996108d436d85a44a76ed379104cc88d
data/bin/committee-stub CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "multi_json"
4
3
  require 'optparse'
4
+ require 'yaml'
5
5
 
6
6
  require_relative "../lib/committee"
7
7
 
@@ -33,7 +33,7 @@ unless args.count == 1
33
33
  exit
34
34
  end
35
35
 
36
- schema = MultiJson.decode(File.read(args[0]))
36
+ schema = ::YAML.load(File.read(args[0]))
37
37
 
38
38
  app = Rack::Builder.new {
39
39
  unless options[:tolerant]
@@ -8,7 +8,7 @@ module Committee::Middleware
8
8
  data = options[:schema] || raise("need option `schema`")
9
9
  if data.is_a?(String)
10
10
  warn_string_deprecated
11
- data = MultiJson.decode(data)
11
+ data = JSON.parse(data)
12
12
  end
13
13
  @raise = options[:raise]
14
14
  @schema = JsonSchema.parse!(data)
@@ -39,7 +39,7 @@ module Committee::Middleware
39
39
  :not_found,
40
40
  "That request method and path combination isn't defined."
41
41
  ).render
42
- rescue MultiJson::LoadError
42
+ rescue JSON::ParserError
43
43
  raise Committee::InvalidRequest if @raise
44
44
  @error_class.new(400, :bad_request, "Request body wasn't valid JSON.").render
45
45
  end
@@ -13,7 +13,7 @@ module Committee::Middleware
13
13
  response.each do |chunk|
14
14
  full_body << chunk
15
15
  end
16
- data = MultiJson.decode(full_body)
16
+ data = JSON.parse(full_body)
17
17
  Committee::ResponseValidator.new(link).call(status, headers, data)
18
18
  end
19
19
 
@@ -21,7 +21,7 @@ module Committee::Middleware
21
21
  rescue Committee::InvalidResponse
22
22
  raise if @raise
23
23
  @error_class.new(500, :invalid_response, $!.message).render
24
- rescue MultiJson::LoadError
24
+ rescue JSON::ParserError
25
25
  raise Committee::InvalidResponse if @raise
26
26
  @error_class.new(500, :invalid_response, "Response wasn't valid JSON.").render
27
27
  end
@@ -26,7 +26,7 @@ module Committee::Middleware
26
26
  headers.merge!(call_headers)
27
27
  end
28
28
  status = link.rel == "create" ? 201 : 200
29
- [status, headers, [MultiJson.encode(data, pretty: true)]]
29
+ [status, headers, [JSON.generate(data, pretty: true)]]
30
30
  else
31
31
  @app.call(request.env)
32
32
  end
@@ -16,7 +16,7 @@ module Committee
16
16
  elsif @optimistic_json
17
17
  begin
18
18
  parse_json
19
- rescue MultiJson::LoadError
19
+ rescue JSON::ParserError
20
20
  nil
21
21
  end
22
22
  end
@@ -66,7 +66,7 @@ module Committee
66
66
  def parse_json
67
67
  if (body = @request.body.read).length != 0
68
68
  @request.body.rewind
69
- hash = MultiJson.decode(body)
69
+ hash = JSON.parse(body)
70
70
  # We want a hash specifically. '42', 42, and [42] will all be
71
71
  # decoded properly, but we can't use them here.
72
72
  if !hash.is_a?(Hash)
@@ -3,7 +3,7 @@ module Committee::Test
3
3
  def assert_schema_conform
4
4
  if (data = schema_contents).is_a?(String)
5
5
  warn_string_deprecated
6
- data = MultiJson.decode(data)
6
+ data = JSON.parse(data)
7
7
  end
8
8
 
9
9
  @schema ||= begin
@@ -19,7 +19,7 @@ module Committee::Test
19
19
  end
20
20
 
21
21
  if validate_response?(last_response.status)
22
- data = MultiJson.decode(last_response.body)
22
+ data = JSON.parse(last_response.body)
23
23
  Committee::ResponseValidator.new(link).call(last_response.status, last_response.headers, data)
24
24
  end
25
25
  end
@@ -32,7 +32,7 @@ module Committee::Test
32
32
  # easier to access as a string
33
33
  # blob
34
34
  def schema_contents
35
- MultiJson.decode(File.read(schema_path))
35
+ JSON.parse(File.read(schema_path))
36
36
  end
37
37
 
38
38
  def schema_path
@@ -16,7 +16,7 @@ module Committee
16
16
  [
17
17
  status,
18
18
  { "Content-Type" => "application/json" },
19
- [MultiJson.encode(error_body)]
19
+ [JSON.generate(error_body)]
20
20
  ]
21
21
  end
22
22
  end
data/lib/committee.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require "json"
1
2
  require "json_schema"
2
- require "multi_json"
3
3
  require "rack"
4
4
 
5
5
  require_relative "committee/errors"
@@ -13,7 +13,7 @@ describe Committee::Middleware::RequestValidation do
13
13
  "name" => "cloudnasium"
14
14
  }
15
15
  header "Content-Type", "application/json"
16
- post "/apps", MultiJson.encode(params)
16
+ post "/apps", JSON.generate(params)
17
17
  assert_equal 200, last_response.status
18
18
  end
19
19
 
@@ -23,7 +23,7 @@ describe Committee::Middleware::RequestValidation do
23
23
  params = {
24
24
  "name" => 1
25
25
  }
26
- post "/apps", MultiJson.encode(params)
26
+ post "/apps", JSON.generate(params)
27
27
  assert_equal 400, last_response.status
28
28
  assert_match /invalid request/i, last_response.body
29
29
  end
@@ -42,7 +42,7 @@ describe Committee::Middleware::RequestValidation do
42
42
  "name" => "cloudnasium"
43
43
  }
44
44
  header "Content-Type", "application/json"
45
- post "/v1/apps", MultiJson.encode(params)
45
+ post "/v1/apps", JSON.generate(params)
46
46
  assert_equal 200, last_response.status
47
47
  end
48
48
 
@@ -60,7 +60,7 @@ describe Committee::Middleware::RequestValidation do
60
60
  "name" => "cloudnasium"
61
61
  }
62
62
  header "Content-Type", "application/json"
63
- post "/apps", MultiJson.encode(params)
63
+ post "/apps", JSON.generate(params)
64
64
  assert_equal 200, last_response.status
65
65
  end
66
66
 
@@ -90,7 +90,7 @@ describe Committee::Middleware::RequestValidation do
90
90
  "name" => "cloudnasium"
91
91
  }
92
92
  header "Content-Type", "text/html"
93
- post "/apps", MultiJson.encode(params)
93
+ post "/apps", JSON.generate(params)
94
94
  assert_equal 200, last_response.status
95
95
  end
96
96
 
@@ -98,7 +98,7 @@ describe Committee::Middleware::RequestValidation do
98
98
 
99
99
  def new_rack_app(options = {})
100
100
  options = {
101
- schema: MultiJson.decode(File.read("./test/data/schema.json"))
101
+ schema: JSON.parse(File.read("./test/data/schema.json"))
102
102
  }.merge(options)
103
103
  Rack::Builder.new {
104
104
  use Committee::Middleware::RequestValidation, options
@@ -8,7 +8,7 @@ describe Committee::Middleware::ResponseValidation do
8
8
  end
9
9
 
10
10
  it "passes through a valid response" do
11
- @app = new_rack_app(MultiJson.encode([ValidApp]))
11
+ @app = new_rack_app(JSON.generate([ValidApp]))
12
12
  get "/apps"
13
13
  assert_equal 200, last_response.status
14
14
  end
@@ -40,14 +40,14 @@ describe Committee::Middleware::ResponseValidation do
40
40
  end
41
41
 
42
42
  it "takes a prefix" do
43
- @app = new_rack_app(MultiJson.encode([ValidApp]), {}, prefix: "/v1")
43
+ @app = new_rack_app(JSON.generate([ValidApp]), {}, prefix: "/v1")
44
44
  get "/v1/apps"
45
45
  assert_equal 200, last_response.status
46
46
  end
47
47
 
48
48
  it "warns when sending a deprecated string" do
49
49
  mock(Committee).warn_deprecated.with_any_args
50
- @app = new_rack_app(MultiJson.encode([ValidApp]), {},
50
+ @app = new_rack_app(JSON.generate([ValidApp]), {},
51
51
  schema: File.read("./test/data/schema.json"))
52
52
  get "/apps"
53
53
  assert_equal 200, last_response.status
@@ -67,7 +67,7 @@ describe Committee::Middleware::ResponseValidation do
67
67
  "Content-Type" => "application/json"
68
68
  }.merge(headers)
69
69
  options = {
70
- schema: MultiJson.decode(File.read("./test/data/schema.json"))
70
+ schema: JSON.parse(File.read("./test/data/schema.json"))
71
71
  }.merge(options)
72
72
  Rack::Builder.new {
73
73
  use Committee::Middleware::ResponseValidation, options
@@ -11,7 +11,7 @@ describe Committee::Middleware::Stub do
11
11
  @app = new_rack_app
12
12
  get "/apps/heroku-api"
13
13
  assert_equal 200, last_response.status
14
- data = MultiJson.decode(last_response.body)
14
+ data = JSON.parse(last_response.body)
15
15
  assert_equal ValidApp.keys.sort, data.keys.sort
16
16
  end
17
17
 
@@ -26,7 +26,7 @@ describe Committee::Middleware::Stub do
26
26
  get "/apps/heroku-api"
27
27
  assert_equal 200, last_response.status
28
28
  assert_equal ValidApp,
29
- MultiJson.decode(last_response.headers["Committee-Response"])
29
+ JSON.parse(last_response.headers["Committee-Response"])
30
30
  end
31
31
 
32
32
  it "optionally returns the application's response" do
@@ -34,7 +34,7 @@ describe Committee::Middleware::Stub do
34
34
  get "/apps/heroku-api"
35
35
  assert_equal 429, last_response.status
36
36
  assert_equal ValidApp,
37
- MultiJson.decode(last_response.headers["Committee-Response"])
37
+ JSON.parse(last_response.headers["Committee-Response"])
38
38
  assert_equal "", last_response.body
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ describe Committee::Middleware::Stub do
42
42
  @app = new_rack_app(prefix: "/v1")
43
43
  get "/v1/apps/heroku-api"
44
44
  assert_equal 200, last_response.status
45
- data = MultiJson.decode(last_response.body)
45
+ data = JSON.parse(last_response.body)
46
46
  assert_equal ValidApp.keys.sort, data.keys.sort
47
47
  end
48
48
 
@@ -51,7 +51,7 @@ describe Committee::Middleware::Stub do
51
51
  @app = new_rack_app(schema: File.read("./test/data/schema.json"))
52
52
  get "/apps/heroku-api"
53
53
  assert_equal 200, last_response.status
54
- data = MultiJson.decode(last_response.body)
54
+ data = JSON.parse(last_response.body)
55
55
  assert_equal ValidApp.keys.sort, data.keys.sort
56
56
  end
57
57
 
@@ -60,12 +60,12 @@ describe Committee::Middleware::Stub do
60
60
  def new_rack_app(options = {})
61
61
  suppress = options.delete(:suppress)
62
62
  options = {
63
- schema: MultiJson.decode(File.read("./test/data/schema.json"))
63
+ schema: JSON.parse(File.read("./test/data/schema.json"))
64
64
  }.merge(options)
65
65
  Rack::Builder.new {
66
66
  use Committee::Middleware::Stub, options
67
67
  run lambda { |env|
68
- headers = { "Committee-Response" => MultiJson.encode(env["committee.response"]) }
68
+ headers = { "Committee-Response" => JSON.generate(env["committee.response"]) }
69
69
  env["committee.suppress"] = suppress
70
70
  [429, headers, []]
71
71
  }
@@ -5,7 +5,7 @@ require "stringio"
5
5
  describe Committee::RequestValidator do
6
6
  before do
7
7
  @schema =
8
- JsonSchema.parse!(MultiJson.decode(File.read("./test/data/schema.json")))
8
+ JsonSchema.parse!(JSON.parse(File.read("./test/data/schema.json")))
9
9
  @schema.expand_references!
10
10
  # POST /apps/:id
11
11
  @link = @link = @schema.properties["app"].links[0]
@@ -3,7 +3,7 @@ require_relative "test_helper"
3
3
  describe Committee::ResponseGenerator do
4
4
  before do
5
5
  @schema =
6
- JsonSchema.parse!(MultiJson.decode(File.read("./test/data/schema.json")))
6
+ JsonSchema.parse!(JSON.parse(File.read("./test/data/schema.json")))
7
7
  @schema.expand_references!
8
8
  # GET /apps/:id
9
9
  @get_link = @link = @schema.properties["app"].links[2]
@@ -8,7 +8,7 @@ describe Committee::ResponseValidator do
8
8
  }
9
9
  @data = ValidApp.dup
10
10
  @schema =
11
- JsonSchema.parse!(MultiJson.decode(File.read("./test/data/schema.json")))
11
+ JsonSchema.parse!(JSON.parse(File.read("./test/data/schema.json")))
12
12
  @schema.expand_references!
13
13
  # GET /apps/:id
14
14
  @get_link = @link = @schema.properties["app"].links[2]
data/test/router_test.rb CHANGED
@@ -30,7 +30,7 @@ describe Committee::Router do
30
30
  end
31
31
 
32
32
  def router(options = {})
33
- data = MultiJson.decode(File.read("./test/data/schema.json"))
33
+ data = JSON.parse(File.read("./test/data/schema.json"))
34
34
  schema = JsonSchema.parse!(data)
35
35
  schema.expand_references!
36
36
  Committee::Router.new(schema, options)
@@ -21,13 +21,13 @@ describe Committee::Middleware::Stub do
21
21
 
22
22
  describe "#assert_schema_conform" do
23
23
  it "passes through a valid response" do
24
- @app = new_rack_app(MultiJson.encode([ValidApp]))
24
+ @app = new_rack_app(JSON.generate([ValidApp]))
25
25
  get "/apps"
26
26
  assert_schema_conform
27
27
  end
28
28
 
29
29
  it "detects an invalid response Content-Type" do
30
- @app = new_rack_app(MultiJson.encode([ValidApp]), {})
30
+ @app = new_rack_app(JSON.generate([ValidApp]), {})
31
31
  get "/apps"
32
32
  e = assert_raises(Committee::InvalidResponse) do
33
33
  assert_schema_conform
@@ -38,7 +38,7 @@ describe Committee::Middleware::Stub do
38
38
  it "warns when sending a deprecated string" do
39
39
  stub(self).schema_contents { File.read(schema_path) }
40
40
  mock(Committee).warn_deprecated.with_any_args
41
- @app = new_rack_app(MultiJson.encode([ValidApp]))
41
+ @app = new_rack_app(JSON.generate([ValidApp]))
42
42
  get "/apps"
43
43
  assert_schema_conform
44
44
  end
@@ -15,7 +15,7 @@ describe Committee::ValidationError do
15
15
  response = [
16
16
  400,
17
17
  { "Content-Type" => "application/json" },
18
- [MultiJson.encode(body)]
18
+ [JSON.generate(body)]
19
19
  ]
20
20
 
21
21
  assert_equal @error.render, response
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.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandur
@@ -31,20 +31,6 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.6.1
34
- - !ruby/object:Gem::Dependency
35
- name: multi_json
36
- requirement: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.10'
41
- type: :runtime
42
- prerelease: false
43
- version_requirements: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.10'
48
34
  - !ruby/object:Gem::Dependency
49
35
  name: rack
50
36
  requirement: !ruby/object:Gem::Requirement
@@ -174,4 +160,3 @@ signing_key:
174
160
  specification_version: 4
175
161
  summary: A collection of Rack middleware to support JSON Schema.
176
162
  test_files: []
177
- has_rdoc: