rack-json_schema 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/rack/json_schema/request_validation.rb +22 -11
- data/lib/rack/json_schema/version.rb +1 -1
- data/spec/rack/spec_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed0069997aafd754ac22502c6821479b8b8fdc2d
|
4
|
+
data.tar.gz: 9b85a306718476fe5578bd8c8dc00365047a91df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a53a19778c8406e0d7e33b32d10fc71f69d336df648c99371e5ba691f17dfe06773253bceb349ba24a6887006357ab787d4c4c14452490dfce7f822815cf4b21
|
7
|
+
data.tar.gz: 1d0177a90def3bd715b1ec662b7508c672432d0f99a9989bc6cdf652d2ce6588d614d5f621b9e8c3c7db46841fc4e5bbc0cb710228f79b4308b4da2fc56506f4
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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
|
-
|
37
|
-
|
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
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -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:
|
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:
|
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:
|
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.
|
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-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|