rack-json_schema 1.1.8 → 1.2.0
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 +13 -8
- data/lib/rack/json_schema/version.rb +1 -1
- data/spec/rack/spec_spec.rb +16 -1
- 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: 71a875cdb899f6012d3925ff4eb241c096365e39
|
4
|
+
data.tar.gz: ecfd5744142dc70b32ea668c2c31ac8050a2d772
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f39fdc41445c42dc183d8d62ca9876e0c01d0acad3ed247b1122e069d00f7984c5363584c351bb8cbc14d723d5767fdbf85179e003e0c0a20621784c9dfcf8
|
7
|
+
data.tar.gz: fbbb0eed5084b41c827589d7b80b661d301eb308e6ea0ed57e97180989ef6931bb3d6ccd7be0965bc0bef0ee74596504e3c87682fc8b014cafaa99ad12e45883
|
data/CHANGELOG.md
CHANGED
@@ -38,16 +38,20 @@ module Rack
|
|
38
38
|
# @raise [Rack::JsonSchema::RequestValidation::Error]
|
39
39
|
def call
|
40
40
|
if has_link_for_current_action?
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
if has_body? && !has_valid_content_type?
|
42
|
+
if strict?
|
43
|
+
raise InvalidContentType
|
44
|
+
end
|
45
|
+
else
|
46
|
+
case
|
47
|
+
when content_type_json? && has_body? && !has_valid_json?
|
48
|
+
raise InvalidJson
|
49
|
+
when content_type_json? && has_schema? && !has_valid_parameter?
|
50
|
+
raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
|
51
|
+
end
|
48
52
|
end
|
49
53
|
elsif strict?
|
50
|
-
raise LinkNotFound
|
54
|
+
raise LinkNotFound, "Could not find the link definition for request path #{path}."
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -80,6 +84,7 @@ module Rack
|
|
80
84
|
mime_type.nil? || Rack::Mime.match?(link.enc_type, mime_type)
|
81
85
|
end
|
82
86
|
|
87
|
+
# @return [true, false] True if the current link supports json format
|
83
88
|
def content_type_json?
|
84
89
|
Rack::Mime.match?(link.enc_type, "application/json")
|
85
90
|
end
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -5,11 +5,12 @@ describe Rack::JsonSchema do
|
|
5
5
|
|
6
6
|
let(:app) do
|
7
7
|
local_schema = schema
|
8
|
+
local_strict = strict
|
8
9
|
local_response_body = response_body
|
9
10
|
local_response_headers = response_headers
|
10
11
|
Rack::Builder.app do
|
11
12
|
use Rack::JsonSchema::ErrorHandler
|
12
|
-
use Rack::JsonSchema::RequestValidation, schema: local_schema
|
13
|
+
use Rack::JsonSchema::RequestValidation, schema: local_schema, strict: local_strict
|
13
14
|
use Rack::JsonSchema::ResponseValidation, schema: local_schema
|
14
15
|
run ->(env) do
|
15
16
|
[200, local_response_headers, [local_response_body]]
|
@@ -45,6 +46,10 @@ describe Rack::JsonSchema do
|
|
45
46
|
File.expand_path("../../fixtures/schema.json", __FILE__)
|
46
47
|
end
|
47
48
|
|
49
|
+
let(:strict) do
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
48
53
|
let(:response) do
|
49
54
|
last_response
|
50
55
|
end
|
@@ -119,6 +124,16 @@ describe Rack::JsonSchema do
|
|
119
124
|
message: "Invalid content type",
|
120
125
|
)
|
121
126
|
end
|
127
|
+
|
128
|
+
context "when strict is false" do
|
129
|
+
let(:strict) do
|
130
|
+
false
|
131
|
+
end
|
132
|
+
|
133
|
+
it "skips content_type check" do
|
134
|
+
should == 200
|
135
|
+
end
|
136
|
+
end
|
122
137
|
end
|
123
138
|
|
124
139
|
context "with valid request property", :with_valid_post_request do
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|