rack-json_schema 1.1.5 → 1.1.6

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: e64c6e28164dfe606ffec931969f51da0d6e66a5
4
- data.tar.gz: 7e19454007e9b43b4f3915bdf127e5276bd6fdb2
3
+ metadata.gz: ed0069997aafd754ac22502c6821479b8b8fdc2d
4
+ data.tar.gz: 9b85a306718476fe5578bd8c8dc00365047a91df
5
5
  SHA512:
6
- metadata.gz: 7e7e277bc22ef4457488e12b36336ae96369ee9feeaf0c71b80291c1ec882c5941b3956435eb40bc2325c6841ae1424552379f55cfa9036dcbce21d5946eab4c
7
- data.tar.gz: 1368238b6dc3f699709e591249d5fcdb8566ebff96b003707ba3b8effd7fda08e7be5103947f700c5f9526ea7f20c8f226ad6b64c142c1d0c0a4a3ea6c84dfda
6
+ metadata.gz: a53a19778c8406e0d7e33b32d10fc71f69d336df648c99371e5ba691f17dfe06773253bceb349ba24a6887006357ab787d4c4c14452490dfce7f822815cf4b21
7
+ data.tar.gz: 1d0177a90def3bd715b1ec662b7508c672432d0f99a9989bc6cdf652d2ce6588d614d5f621b9e8c3c7db46841fc4e5bbc0cb710228f79b4308b4da2fc56506f4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.1.6
2
+ * Add :strict option to ignore undefined link
3
+
1
4
  ## 1.1.5
2
5
  * Check Content-Type on response validation
3
6
 
@@ -4,16 +4,18 @@ module Rack
4
4
  # Behaves as a rack-middleware
5
5
  # @param app [Object] Rack application
6
6
  # @param schema [Hash] Schema object written in JSON schema format
7
+ # @param strict [Boolean] Strict mode or not (default: true)
7
8
  # @raise [JsonSchema::SchemaError]
8
- def initialize(app, schema: nil)
9
+ def initialize(app, schema: nil, strict: nil)
9
10
  @app = app
10
11
  @schema = Schema.new(schema)
12
+ @strict = strict
11
13
  end
12
14
 
13
15
  # @raise [Rack::JsonSchema::RequestValidation::Error] Raises if given request is invalid to JSON Schema
14
16
  # @param env [Hash] Rack env
15
17
  def call(env)
16
- Validator.call(env: env, schema: @schema)
18
+ Validator.call(env: env, schema: @schema, strict: @strict)
17
19
  @app.call(env)
18
20
  end
19
21
 
@@ -25,23 +27,27 @@ module Rack
25
27
 
26
28
  # @param env [Hash] Rack env
27
29
  # @param schema [JsonSchema::Schema] Schema object
28
- def initialize(env: nil, schema: nil)
30
+ # @param strict [Boolean] Strict mode or not (default: true)
31
+ def initialize(env: nil, schema: nil, strict: nil)
29
32
  @env = env
30
33
  @schema = schema
34
+ @strict = strict
31
35
  end
32
36
 
33
37
  # Raises an error if any error detected
34
38
  # @raise [Rack::JsonSchema::RequestValidation::Error]
35
39
  def call
36
- case
37
- when !has_link_for_current_action?
40
+ if has_link_for_current_action?
41
+ case
42
+ when has_body? && !has_valid_content_type?
43
+ raise InvalidContentType
44
+ when content_type_json? && has_body? && !has_valid_json?
45
+ raise InvalidJson
46
+ when content_type_json? && has_schema? && !has_valid_parameter?
47
+ raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
48
+ end
49
+ elsif strict?
38
50
  raise LinkNotFound
39
- when has_body? && !has_valid_content_type?
40
- raise InvalidContentType
41
- when content_type_json? && has_body? && !has_valid_json?
42
- raise InvalidJson
43
- when content_type_json? && has_schema? && !has_valid_parameter?
44
- raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
45
51
  end
46
52
  end
47
53
 
@@ -131,6 +137,11 @@ module Rack
131
137
  def parameters_from_query
132
138
  request.GET
133
139
  end
140
+
141
+ # @return [Boolean] Strict mode or not.
142
+ def strict?
143
+ @strict != false
144
+ end
134
145
  end
135
146
 
136
147
  # Base error class for Rack::JsonSchema::RequestValidation
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.1.5"
3
+ VERSION = "1.1.6"
4
4
  end
5
5
  end
@@ -141,7 +141,7 @@ describe Rack::JsonSchema do
141
141
  should == 400
142
142
  response.body.should be_json_as(
143
143
  id: "invalid_parameter",
144
- message: %r<\AInvalid request\.\n#/name: failed schema .+: Expected string to match pattern>,
144
+ message: String,
145
145
  )
146
146
  end
147
147
  end
@@ -230,7 +230,7 @@ describe Rack::JsonSchema do
230
230
  should == 500
231
231
  response.body.should be_json_as(
232
232
  id: "invalid_response_type",
233
- message: /Missing required keys "id" in object/,
233
+ message: String,
234
234
  )
235
235
  end
236
236
  end
@@ -244,7 +244,7 @@ describe Rack::JsonSchema do
244
244
  should == 500
245
245
  response.body.should be_json_as(
246
246
  id: "invalid_response_type",
247
- message: /Expected data to match "uuid" format, value was: 123/,
247
+ message: String,
248
248
  )
249
249
  end
250
250
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-26 00:00:00.000000000 Z
11
+ date: 2014-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis