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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c02f8ffa259cdd0d9dc677025227bb679e904ec
4
- data.tar.gz: 50f290b85d487fb9d46caaf928e14131712eb7b2
3
+ metadata.gz: 79d209276140e0736a40756b6505b4b8a6eeec02
4
+ data.tar.gz: e6f68298e2836bd614ceb53bf2d396282cb28148
5
5
  SHA512:
6
- metadata.gz: 61102d656d4c4550f9e2e0d73322ffe7192aed237083a117c1c5cfe21d8c64dfcb9b58d64b65e30791d9d9804f5495115df3837dd4977e8d72742ad51c28a3e0
7
- data.tar.gz: 33aec895164221bbe5e58f0fa9d77509e5e273bc22578ab3b68ecfe36dfd99b5f4f7cc6e68b95e5c90b76476ffe9203e7bbe2c7a0820ebb7f049d34f130fd521
6
+ metadata.gz: e88d4285760b99907f5eeb0f14eeea65ab03e0b5f8e7136339139188918955e62b61b309530cfbca52c5848086c504685458552f0b24120340b03d74da218346
7
+ data.tar.gz: 417d7ef7f5029194670d29dc94ca3f3a7531b735f60c9363def5ee8874f1c1e07810ee3759a5e94d8f8d187f8a1343ec532da3ab3cfc438fb944b96c63217a7c
@@ -1,3 +1,6 @@
1
+ ## 1.1.4
2
+ * Skip validation of non-json request
3
+
1
4
  ## 1.1.3
2
5
  * Validate request parameters in URI query too
3
6
 
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
@@ -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": {
@@ -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.3
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-02 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis