esplanade 1.2.1 → 1.3.0

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: 85995e3ffde40ae8fb299e8bdc4ac1173283590c
4
- data.tar.gz: 0f1242bec48b135345a4b6d1680cd6f4fc98f698
3
+ metadata.gz: ff2aa7471fbccccd7a52e52ba79faa5c181c3fc9
4
+ data.tar.gz: 34d21fc0cb3cf09954ce401805076c206508b9d2
5
5
  SHA512:
6
- metadata.gz: d332f111d4860bd09e341c2c8aebfb35157e1582b6506b70d8176ef9ad118b101f14ca6f8aa98898ef95ec0394ae2be2aae9ef9a433bee86411c0367a2f93f82
7
- data.tar.gz: e8d29d45efa8908f74c2f1046c61840131a816218ebd222c618edadaca5a45dedac020a319c56625dbac9aa75140054cf30b6197d97e8602d21db14f991f05e5
6
+ metadata.gz: e4cf2e079c8773cdb0b10241ba8166834ab6b6c03b108273e9b7963efa7d812b8a2a2cc7ba249b7c429fffdb80b0dcf36b5b167665b7fef2e00177568f51a32c
7
+ data.tar.gz: 62b6623aa9df749907c7d6dc5e6413103bab3083368cc616140c63b9bb3cd4cdfa596a60c857fef5ab57e40b9e8d7a168a606b421ed8db7c079e640387bc8c7a
data/CHANGELOG.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Change log
2
2
 
3
+ ### 1.3.0 - 2018-03-16
4
+
5
+ * features
6
+ * add Esplanade::Request::ContentTypeIsNotJson erro
7
+ * add reduced version message about request body
8
+
3
9
  ### 1.2.1 - 2018-02-20
4
10
 
5
- * improvement
11
+ * features
6
12
  * more information about the invalid request
7
13
 
8
14
  ### 1.2.0 - 2018-02-15
@@ -16,12 +22,12 @@
16
22
 
17
23
  ### 1.1.2 - 2018-02-14
18
24
 
19
- * bug fixes
25
+ * fixes
20
26
  * add rewind rack.input
21
27
 
22
28
  ### 1.1.1 - 2018-02-13
23
29
 
24
- * bug fixes
30
+ * fixes
25
31
  * read body if Content-Type application/json
26
32
 
27
33
  ### 1.1.0 - 2017-10-18
@@ -31,5 +37,5 @@
31
37
 
32
38
  ### 1.0.1 - 2017-10-09
33
39
 
34
- * bug fixes
40
+ * fixes
35
41
  * allow request body to be nil
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Esplanade
2
2
 
3
3
  <a href="https://funbox.ru">
4
- <img src="https://funbox.ru/badges/sponsored_by_funbox.svg" alt="Sponsored by FunBox" width=250 />
4
+ <img src="https://funbox.ru/badges/sponsored_by_funbox_compact.svg" alt="Sponsored by FunBox" width=250 />
5
5
  </a>
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/esplanade.svg)](https://badge.fury.io/rb/esplanade)
@@ -71,21 +71,23 @@ From him the `Esplanade::Request::PrefixNotMatch`, `Esplanade::Request::NotDocum
71
71
 
72
72
  #### Esplanade::Request::PrefixNotMatch
73
73
 
74
- Error message: `{:method=>"method", :path=>"path"}`.
74
+ Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
75
75
 
76
76
  #### Esplanade::Request::NotDocumented
77
77
 
78
- Error message: `{:method=>"method", :path=>"path"}`.
78
+ Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
79
79
 
80
- #### Esplanade::Request::BodyIsNotJson
80
+ #### Esplanade::Request::ContentTypeIsNotJson
81
+
82
+ Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
81
83
 
82
- Only if the documentation for this request indicates that `Content-Type: application/json`.
84
+ #### Esplanade::Request::BodyIsNotJson
83
85
 
84
- Error message: `{:method=>"method", :path=>"path", :body=>"{\"state\": 1"}`.
86
+ Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type", :body=>"{\"state\": 1"}`.
85
87
 
86
88
  #### Esplanade::Request::Invalid
87
89
 
88
- Error message: `{:method=>"method", :path=>"path", :body=>"body", :error=>["error"]}`.
90
+ Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type", :body=>"body", :error=>["error"]}`.
89
91
 
90
92
  ### Esplanade::Response::Error
91
93
 
data/esplanade.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
20
20
  spec.add_runtime_dependency 'multi_json', '~> 1.11', '>= 1.11.1'
21
- spec.add_runtime_dependency 'tomograph', '~> 1.2', '>= 1.2.0'
21
+ spec.add_runtime_dependency 'tomograph', '~> 2.0', '>= 2.0.0'
22
22
  spec.add_development_dependency 'bundler', '~> 1.12'
23
23
  spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -8,7 +8,11 @@ module Esplanade
8
8
 
9
9
  def tomogram
10
10
  raise PrefixNotMatch, message unless @main_documentation.prefix_match?(@raw.path)
11
- @tomogram = @main_documentation.find_request(method: @raw.method, path: @raw.path)
11
+ @tomogram = @main_documentation.find_request_with_content_type(
12
+ method: @raw.method,
13
+ path: @raw.path,
14
+ content_type: @raw.content_type
15
+ )
12
16
  raise NotDocumented, message if @tomogram.nil?
13
17
  @tomogram
14
18
  end
@@ -25,6 +29,10 @@ module Esplanade
25
29
  @path ||= tomogram.path.to_s
26
30
  end
27
31
 
32
+ def content_type
33
+ @content_type ||= tomogram.content_type.to_s
34
+ end
35
+
28
36
  def responses
29
37
  @responses ||= tomogram.responses
30
38
  rescue NotDocumented
@@ -36,7 +44,8 @@ module Esplanade
36
44
  def message
37
45
  {
38
46
  method: @raw.method,
39
- path: @raw.path
47
+ path: @raw.path,
48
+ content_type: @raw.content_type
40
49
  }
41
50
  end
42
51
  end
@@ -3,17 +3,70 @@ module Esplanade
3
3
  class Error < Esplanade::Error; end
4
4
 
5
5
  class PrefixNotMatch < Error; end
6
- class NotDocumented < Error; end
7
- class BodyIsNotJson < Error; end
8
6
 
9
- class Invalid < Error
10
- attr_reader :method, :path, :body, :error
7
+ class NotDocumented < Error
8
+ def initialize(method:, path:, content_type:)
9
+ @method = method
10
+ @path = path
11
+ @content_type = content_type
12
+
13
+ super(to_hash)
14
+ end
11
15
 
12
- def initialize(method:, path:, body:, error:)
16
+ def to_hash
17
+ {
18
+ method: @method,
19
+ path: @path,
20
+ content_type: @content_type
21
+ }
22
+ end
23
+ end
24
+
25
+ class ContentTypeIsNotJson < Error
26
+ def initialize(method:, path:, content_type:)
27
+ @method = method
28
+ @path = path
29
+ @content_type = content_type
30
+
31
+ super(to_hash)
32
+ end
33
+
34
+ def to_hash
35
+ {
36
+ method: @method,
37
+ path: @path,
38
+ content_type: @content_type
39
+ }
40
+ end
41
+ end
42
+
43
+ class BodyIsNotJson < Error
44
+ def initialize(method:, path:, content_type:, body:)
45
+ @method = method
46
+ @path = path
47
+ @content_type = content_type
48
+ @body = body
49
+
50
+ super(to_hash)
51
+ end
52
+
53
+ def to_hash
54
+ {
55
+ method: @method,
56
+ path: @path,
57
+ content_type: @content_type,
58
+ body: @body
59
+ }
60
+ end
61
+ end
62
+
63
+ class Invalid < Error
64
+ def initialize(method:, path:, content_type:, body:, error:)
13
65
  @method = method
14
- @path = path
15
- @body = body
16
- @error = error
66
+ @path = path
67
+ @content_type = content_type
68
+ @body = body
69
+ @error = error
17
70
 
18
71
  super(to_hash)
19
72
  end
@@ -21,9 +74,10 @@ module Esplanade
21
74
  def to_hash
22
75
  {
23
76
  method: @method,
24
- path: @path,
25
- body: @body,
26
- error: @error
77
+ path: @path,
78
+ content_type: @content_type,
79
+ body: @body,
80
+ error: @error
27
81
  }
28
82
  end
29
83
  end
@@ -18,6 +18,10 @@ module Esplanade
18
18
  def body
19
19
  @body ||= Body.new(self, @env)
20
20
  end
21
+
22
+ def content_type
23
+ @content_type ||= @env['CONTENT_TYPE']
24
+ end
21
25
  end
22
26
  end
23
27
  end
@@ -26,13 +26,22 @@ module Esplanade
26
26
  raise BodyIsNotJson, message
27
27
  end
28
28
 
29
+ def reduced_version
30
+ @reduced_version ||= if to_string.size >= 1000
31
+ "#{to_string[0..499]}...#{to_string[500..-1]}"
32
+ else
33
+ to_string
34
+ end
35
+ end
36
+
29
37
  private
30
38
 
31
39
  def message
32
40
  {
33
41
  method: @raw_request.method,
34
42
  path: @raw_request.path,
35
- body: to_string
43
+ content_type: @raw_request.content_type,
44
+ body: reduced_version
36
45
  }
37
46
  end
38
47
  end
@@ -10,6 +10,7 @@ module Esplanade
10
10
  end
11
11
 
12
12
  def valid!
13
+ raise ContentTypeIsNotJson, mini_message unless @doc.content_type == 'application/json'
13
14
  @error ||= JSON::Validator.fully_validate(@doc.json_schema, @raw.body.to_hash)
14
15
 
15
16
  raise Invalid, message unless @error.empty?
@@ -17,10 +18,19 @@ module Esplanade
17
18
 
18
19
  private
19
20
 
21
+ def mini_message
22
+ {
23
+ method: @doc.method,
24
+ path: @doc.path,
25
+ content_type: @doc.content_type
26
+ }
27
+ end
28
+
20
29
  def message
21
30
  {
22
31
  method: @raw.method,
23
32
  path: @raw.path,
33
+ content_type: @raw.content_type,
24
34
  body: @raw.body.to_hash,
25
35
  error: @error
26
36
  }
@@ -1,3 +1,3 @@
1
1
  module Esplanade
2
- VERSION = '1.2.1'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esplanade
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -56,20 +56,20 @@ dependencies:
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '1.2'
59
+ version: '2.0'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 1.2.0
62
+ version: 2.0.0
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '1.2'
69
+ version: '2.0'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 1.2.0
72
+ version: 2.0.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: bundler
75
75
  requirement: !ruby/object:Gem::Requirement