rack-json_schema 1.5.0 → 1.5.1

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: 71834752a3561e3bf63a60884a2335f172cc58ff
4
- data.tar.gz: d631e1916036d2c632611d7f49571283cf01d069
3
+ metadata.gz: e1bc0b3aeb691e9f03410743681b3aeb47636727
4
+ data.tar.gz: 78f4809fbaa6d7732b5ba700f464be4187ad6263
5
5
  SHA512:
6
- metadata.gz: 3496d7e180b999cfb6350ea7db3cfc12ca0f060390ba2715e72eb378cdcf0c52d850a42cc8eec6601dd79381f87f7578f3787520d9ab023066db284651146fc7
7
- data.tar.gz: da8d31beb10245571b67fb7e955ee4fb9ffd1ce6ee35d46f47dd6e4ad2c65fa3bdf4c6b069bf62a3f509973d834a7786e867a6b63e971a0aa38ecee0729130c3
6
+ metadata.gz: 82933f6a328ccb1f7809880262f4f2119c19962c6830082ca188b768c995a55701f58f2e6f6d003c2522a3667d43f7eee91237bd844e4ccdc30da52733feb643
7
+ data.tar.gz: 694562757728e378acf77e615247bc480f51048b9f649eb4ccc9b503889a1a545d39ad5af3ce860cb485e390186ddcce14853dd55c35a97ccceac606b21da49d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.5.1
2
+ - Fix error when request body is an Array in JSON
3
+
1
4
  ## 1.5.0
2
5
  - Separate :strict option into 2 other options
3
6
 
@@ -56,7 +56,11 @@ module Rack
56
56
  when content_type_json? && has_body? && !has_valid_json?
57
57
  raise InvalidJson
58
58
  when content_type_json? && has_schema? && !has_valid_parameter?
59
- raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
59
+ if has_hash_request_body?
60
+ raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
61
+ else
62
+ raise InvalidParameter, "Invalid request. Request body must be an Object in JSON."
63
+ end
60
64
  end
61
65
  end
62
66
  elsif !ignore_missing_path?
@@ -66,8 +70,12 @@ module Rack
66
70
 
67
71
  private
68
72
 
73
+ def has_hash_request_body?
74
+ parsed_body.is_a?(Hash)
75
+ end
76
+
69
77
  def has_valid_json?
70
- parameters
78
+ parsed_body
71
79
  true
72
80
  rescue JSON::JSONError
73
81
  false
@@ -75,7 +83,7 @@ module Rack
75
83
 
76
84
  # @return [true, false] True if request parameters are all valid
77
85
  def has_valid_parameter?
78
- schema_validation_result[0]
86
+ parsed_body.is_a?(Hash) && schema_validation_result[0]
79
87
  end
80
88
 
81
89
  # @return [true, false] True if any schema is defined for the current action
@@ -151,7 +159,7 @@ module Rack
151
159
  # @raise [JSON::JSONError]
152
160
  def parameters_from_body
153
161
  if has_body?
154
- JSON.parse(body)
162
+ parsed_body
155
163
  else
156
164
  {}
157
165
  end
@@ -161,6 +169,10 @@ module Rack
161
169
  def parameters_from_query
162
170
  request.GET
163
171
  end
172
+
173
+ def parsed_body
174
+ @parsed_body ||= JSON.parse(body)
175
+ end
164
176
  end
165
177
 
166
178
  # Base error class for Rack::JsonSchema::RequestValidation
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.5.0"
3
+ VERSION = "1.5.1"
4
4
  end
5
5
  end
@@ -155,6 +155,14 @@ describe Rack::JsonSchema do
155
155
  end
156
156
  end
157
157
 
158
+ context "with Array request body", :with_valid_post_request do
159
+ let(:params) do
160
+ [].to_json
161
+ end
162
+
163
+ it { should == 400 }
164
+ end
165
+
158
166
  context "with valid request property", :with_valid_post_request do
159
167
  it { should == 200 }
160
168
  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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura