rack-json_schema 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff47484c2c4c5c2aa4b576f3ae2973ed9330308c
4
- data.tar.gz: a9b9edd703d900683a5d05a8a78571351a99cf13
3
+ metadata.gz: 71a875cdb899f6012d3925ff4eb241c096365e39
4
+ data.tar.gz: ecfd5744142dc70b32ea668c2c31ac8050a2d772
5
5
  SHA512:
6
- metadata.gz: f0dfd8e634d117c97c808a4084de7b63ebbd1e69c8cbe85566e736023d4695ddb7156ec3923e559ce0dc48803dfbb298556a0242feb064652dc258c1ecf56a05
7
- data.tar.gz: 721c53040d685f5a07d96370b891e4e5917ec3fcbc21c41802a57fddd2d3cad61e6adbb4e76fc6fb50c298fc60a060ed56a4ebb93fad7a679a4644ff0fcada49
6
+ metadata.gz: 57f39fdc41445c42dc183d8d62ca9876e0c01d0acad3ed247b1122e069d00f7984c5363584c351bb8cbc14d723d5767fdbf85179e003e0c0a20621784c9dfcf8
7
+ data.tar.gz: fbbb0eed5084b41c827589d7b80b661d301eb308e6ea0ed57e97180989ef6931bb3d6ccd7be0965bc0bef0ee74596504e3c87682fc8b014cafaa99ad12e45883
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.0
2
+ - Skip content_type check if strict mode is turned off (thx @tomoya55)
3
+
1
4
  ## 1.1.8
2
5
  - Improve error message on LinkNotFound (thx @take)
3
6
 
@@ -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
- 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}"
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.new("Could not find the link definition for request path #{path}.")
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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module JsonSchema
3
- VERSION = "1.1.8"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -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.1.8
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-01-27 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis