rack-json_schema 1.1.3 → 1.1.4
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 +6 -2
- data/lib/rack/json_schema/version.rb +1 -1
- data/spec/fixtures/schema.json +24 -0
- data/spec/rack/spec_spec.rb +21 -0
- 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: 79d209276140e0736a40756b6505b4b8a6eeec02
|
4
|
+
data.tar.gz: e6f68298e2836bd614ceb53bf2d396282cb28148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e88d4285760b99907f5eeb0f14eeea65ab03e0b5f8e7136339139188918955e62b61b309530cfbca52c5848086c504685458552f0b24120340b03d74da218346
|
7
|
+
data.tar.gz: 417d7ef7f5029194670d29dc94ca3f3a7531b735f60c9363def5ee8874f1c1e07810ee3759a5e94d8f8d187f8a1343ec532da3ab3cfc438fb944b96c63217a7c
|
data/CHANGELOG.md
CHANGED
@@ -38,9 +38,9 @@ module Rack
|
|
38
38
|
raise LinkNotFound
|
39
39
|
when has_body? && !has_valid_content_type?
|
40
40
|
raise InvalidContentType
|
41
|
-
when has_body? && !has_valid_json?
|
41
|
+
when content_type_json? && has_body? && !has_valid_json?
|
42
42
|
raise InvalidJson
|
43
|
-
when has_schema? && !has_valid_parameter?
|
43
|
+
when content_type_json? && has_schema? && !has_valid_parameter?
|
44
44
|
raise InvalidParameter, "Invalid request.\n#{schema_validation_error_message}"
|
45
45
|
end
|
46
46
|
end
|
@@ -74,6 +74,10 @@ module Rack
|
|
74
74
|
mime_type.nil? || Rack::Mime.match?(link.enc_type, mime_type)
|
75
75
|
end
|
76
76
|
|
77
|
+
def content_type_json?
|
78
|
+
Rack::Mime.match?(link.enc_type, "application/json")
|
79
|
+
end
|
80
|
+
|
77
81
|
# @return [Array] A result of schema validation for the current action
|
78
82
|
def schema_validation_result
|
79
83
|
@schema_validation_result ||= link.schema.validate(parameters)
|
data/spec/fixtures/schema.json
CHANGED
@@ -28,6 +28,12 @@
|
|
28
28
|
"type": [
|
29
29
|
"string"
|
30
30
|
]
|
31
|
+
},
|
32
|
+
"file": {
|
33
|
+
"description": "an attachment of app",
|
34
|
+
"example": "",
|
35
|
+
"readOnly": false,
|
36
|
+
"type": "string"
|
31
37
|
}
|
32
38
|
},
|
33
39
|
"links": [
|
@@ -85,6 +91,24 @@
|
|
85
91
|
]
|
86
92
|
},
|
87
93
|
"title": "Update"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"description": "Upload an attachment file for an app",
|
97
|
+
"href": "/apps/{(%23%2Fdefinitions%2Fapp%2Fdefinitions%2Fid)}/files",
|
98
|
+
"method": "POST",
|
99
|
+
"rel": "create",
|
100
|
+
"encType": "multipart/form-data",
|
101
|
+
"schema": {
|
102
|
+
"properties": {
|
103
|
+
"file": {
|
104
|
+
"$ref": "#/definitions/app/definitions/file"
|
105
|
+
}
|
106
|
+
},
|
107
|
+
"type": [
|
108
|
+
"object"
|
109
|
+
]
|
110
|
+
},
|
111
|
+
"title": "Create"
|
88
112
|
}
|
89
113
|
],
|
90
114
|
"properties": {
|
data/spec/rack/spec_spec.rb
CHANGED
@@ -146,6 +146,27 @@ describe Rack::JsonSchema do
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
+
context "with non-json content type with non-json request body", :with_valid_post_request do
|
150
|
+
|
151
|
+
let(:path) do
|
152
|
+
"/apps/#{app_id}/files"
|
153
|
+
end
|
154
|
+
|
155
|
+
let(:app_id) do
|
156
|
+
1
|
157
|
+
end
|
158
|
+
|
159
|
+
let(:params) do
|
160
|
+
{ file: Rack::Test::UploadedFile.new(schema_path, 'text/x-yaml') }
|
161
|
+
end
|
162
|
+
|
163
|
+
before do
|
164
|
+
env["CONTENT_TYPE"] = "multipart/form-data"
|
165
|
+
end
|
166
|
+
|
167
|
+
it { should == 200 }
|
168
|
+
end
|
169
|
+
|
149
170
|
context "with malformed JSON request body", :with_valid_post_request do
|
150
171
|
let(:params) do
|
151
172
|
"malformed"
|
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.4
|
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-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|