rack-json_schema 1.3.0 → 1.4.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: f1f74c5ddb67e2e9a9dd4da8ace64d3207dbe4cf
4
- data.tar.gz: 8d0112906bb873488d6b7a793b422cf668066913
3
+ metadata.gz: 276eb5729514a350ea04991833eb262d34ed663b
4
+ data.tar.gz: c9d398ae44ccc2ca33813fb210830552e81a876b
5
5
  SHA512:
6
- metadata.gz: 1c7864c9a2ce0554b80e78b57d3554bca71833d924762f92f3d6ecfacb81009fff8a79f6cb3ee65749d2b09903e7292ee62f4fc54473835db89ca79df7d722cd
7
- data.tar.gz: 0cdb0acc5db47f64a95fd2631615d290044c3837747467c4b5231e0f7d51bd0e2ec69f4fb654a4d704e5a04f8b2a0c80eccb0de352f39f73163da7a9e792d2d3
6
+ metadata.gz: a1edd0f145b7b97ee5364e6c3e358df7ae21a47f93c6037c3411a69bf178880867347f446d510186888d8b0b1afc6da178ab5904bdd176336fc509655bbd3782
7
+ data.tar.gz: 2bd34182a08c20b032c55634413bb67746f53f35b61befa6d9e41a5569c01d6ad652f8a948551729ef47a3950a26140c11aa2de70192b3447946596948fda048
@@ -1,3 +1,6 @@
1
+ ## 1.4.0
2
+ - Allow non JSON Content-Type response on empty body
3
+
1
4
  ## 1.3.0
2
5
  - Support rails-style path format on link detection
3
6
 
@@ -33,7 +33,7 @@ module Rack
33
33
  def call
34
34
  if !has_redirection_or_error_status? && has_link_for_current_action? && has_link_of_media_type_json?
35
35
  case
36
- when !has_json_content_type?
36
+ when has_body? && !has_json_content_type?
37
37
  raise InvalidResponseContentType
38
38
  when !valid?
39
39
  raise InvalidResponseType, validator.errors
@@ -41,6 +41,11 @@ module Rack
41
41
  end
42
42
  end
43
43
 
44
+ # @return [true, false] True if any bytes are included in response body
45
+ def has_body?
46
+ !body.size.zero?
47
+ end
48
+
44
49
  # @return [true, false] True if Link mediaType is for JSON
45
50
  def has_link_of_media_type_json?
46
51
  mime_type_json?(link.media_type)
@@ -53,7 +58,7 @@ module Rack
53
58
 
54
59
  # @return [true, false] True if given data is valid to the JSON schema
55
60
  def valid?
56
- (has_list_data? && data.empty?) || validator.validate(example_item)
61
+ !has_body? || (has_list_data? && data.empty?) || validator.validate(example_item)
57
62
  end
58
63
 
59
64
  # @return [Hash] Choose an item from response data, to be validated
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -271,5 +271,17 @@ describe Rack::JsonSchema do
271
271
 
272
272
  it { should == 200 }
273
273
  end
274
+
275
+ context "with empty response body without JSON Content-Type" do
276
+ let(:response_body) do
277
+ ""
278
+ end
279
+
280
+ let(:response_headers) do
281
+ {}
282
+ end
283
+
284
+ it { should == 200 }
285
+ end
274
286
  end
275
287
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura