rack-json_schema 1.1.4 → 1.1.5
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/response_validation.rb +23 -2
- data/lib/rack/json_schema/version.rb +1 -1
- data/rack-json_schema.gemspec +1 -1
- data/spec/fixtures/schema.json +8 -0
- data/spec/rack/spec_spec.rb +24 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e64c6e28164dfe606ffec931969f51da0d6e66a5
|
4
|
+
data.tar.gz: 7e19454007e9b43b4f3915bdf127e5276bd6fdb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e7e277bc22ef4457488e12b36336ae96369ee9feeaf0c71b80291c1ec882c5941b3956435eb40bc2325c6841ae1424552379f55cfa9036dcbce21d5946eab4c
|
7
|
+
data.tar.gz: 1368238b6dc3f699709e591249d5fcdb8566ebff96b003707ba3b8effd7fda08e7be5103947f700c5f9526ea7f20c8f226ad6b64c142c1d0c0a4a3ea6c84dfda
|
data/CHANGELOG.md
CHANGED
@@ -31,7 +31,7 @@ module Rack
|
|
31
31
|
# Raises an error if any error detected, skipping validation for non-defined link
|
32
32
|
# @raise [Rack::JsonSchema::ResponseValidation::InvalidResponse]
|
33
33
|
def call
|
34
|
-
if !has_error_status? && has_link_for_current_action?
|
34
|
+
if !has_error_status? && has_link_for_current_action? && has_link_of_media_type_json?
|
35
35
|
case
|
36
36
|
when !has_json_content_type?
|
37
37
|
raise InvalidResponseContentType
|
@@ -41,9 +41,14 @@ module Rack
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# @return [true, false] True if Link mediaType is for JSON
|
45
|
+
def has_link_of_media_type_json?
|
46
|
+
mime_type_json?(link.media_type)
|
47
|
+
end
|
48
|
+
|
44
49
|
# @return [true, false] True if response Content-Type is for JSON
|
45
50
|
def has_json_content_type?
|
46
|
-
|
51
|
+
mime_type_json?(mime_type)
|
47
52
|
end
|
48
53
|
|
49
54
|
# @return [true, false] True if given data is valid to the JSON schema
|
@@ -93,6 +98,22 @@ module Rack
|
|
93
98
|
def has_error_status?
|
94
99
|
response_status >= 400
|
95
100
|
end
|
101
|
+
|
102
|
+
# @return [String, nil] Response MIME Type specified in Content-Type header field
|
103
|
+
# @example
|
104
|
+
# mime_type #=> "application/json"
|
105
|
+
def mime_type
|
106
|
+
headers["Content-Type"].split(";").first if headers["Content-Type"]
|
107
|
+
end
|
108
|
+
|
109
|
+
# @return [true, false] return true if mime type is for JSON
|
110
|
+
# @example
|
111
|
+
# "application/json" #=> true
|
112
|
+
# "application/calendar+json" #=> true
|
113
|
+
# "application/vnd.myapp.custom-json" #=> false
|
114
|
+
def mime_type_json?(value)
|
115
|
+
%r<\Aapplication/(?:.*\+)?json> === value
|
116
|
+
end
|
96
117
|
end
|
97
118
|
|
98
119
|
# Base error class for Rack::JsonSchema::ResponseValidation
|
data/rack-json_schema.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_dependency "erubis"
|
21
21
|
spec.add_dependency "jdoc", ">= 0.1.4"
|
22
|
-
spec.add_dependency "json_schema"
|
22
|
+
spec.add_dependency "json_schema", "~> 0.2"
|
23
23
|
spec.add_dependency "rack"
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.5"
|
25
25
|
spec.add_development_dependency "pry"
|
data/spec/fixtures/schema.json
CHANGED
@@ -68,6 +68,14 @@
|
|
68
68
|
"rel": "self",
|
69
69
|
"title": "Info"
|
70
70
|
},
|
71
|
+
{
|
72
|
+
"description": "Info for existing apps in text format",
|
73
|
+
"href": "/apps/{(%23%2Fdefinitions%2Fapp%2Fdefinitions%2Fid)}/text",
|
74
|
+
"method": "GET",
|
75
|
+
"rel": "self",
|
76
|
+
"title": "Info",
|
77
|
+
"mediaType": "text/plain"
|
78
|
+
},
|
71
79
|
{
|
72
80
|
"description": "List existing apps.",
|
73
81
|
"href": "/apps",
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -202,12 +202,22 @@ describe Rack::JsonSchema do
|
|
202
202
|
{ "Content-Type" => "text/plain" }
|
203
203
|
end
|
204
204
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
205
|
+
context "when mediaType is specified as text/plain" do
|
206
|
+
let(:path) do
|
207
|
+
"/apps/#{response_data[:id]}/text"
|
208
|
+
end
|
209
|
+
|
210
|
+
it { should == 200 }
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when mediaType is not specified" do
|
214
|
+
it "returns invalid_response_content_type error" do
|
215
|
+
should == 500
|
216
|
+
response.body.should be_json_as(
|
217
|
+
id: "invalid_response_content_type",
|
218
|
+
message: "Response Content-Type wasn't for JSON",
|
219
|
+
)
|
220
|
+
end
|
211
221
|
end
|
212
222
|
end
|
213
223
|
|
@@ -238,5 +248,13 @@ describe Rack::JsonSchema do
|
|
238
248
|
)
|
239
249
|
end
|
240
250
|
end
|
251
|
+
|
252
|
+
context "with response content type for JSON" do
|
253
|
+
let(:response_headers) do
|
254
|
+
{ "Content-Type" => "application/json; charset=utf-8" }
|
255
|
+
end
|
256
|
+
|
257
|
+
it { should == 200 }
|
258
|
+
end
|
241
259
|
end
|
242
260
|
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.5
|
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-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: json_schema
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '0.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|