esplanade 1.1.2 → 1.2.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: bc7479b76e247ba0d85009c91c9114b000069b78
4
- data.tar.gz: 7efc7851a8cce81fc368ca748a69309f2e382c43
3
+ metadata.gz: d56ac3bbfdcd35af5878ab7c38ba6192ef4e5957
4
+ data.tar.gz: a17fd30d62e0039c6d70389e8f197e1b46a8bf17
5
5
  SHA512:
6
- metadata.gz: 7e107bd64e45b84dfe9575e0e2e3324bb4e9b4cb565f50eb96de51b3e35bf71afbbe89434a541fa33251023cac1ec582addce0a6b44e121a0fa495bea61b1f6b
7
- data.tar.gz: 751af6d98761fd85d58a11a017c12111f0997ca00bda8528e4f50ef19bc9a305a93293636bff0139374dcde430ed124fa55cc07a20da0afad2a867fba105b4cf
6
+ metadata.gz: fcbf87e4765ff6ac1b388e490c03dd9c72f57e062fdd9598e247ad4425e51f1723234142af8e0b89ff8611fe7e45834abbbb7c6c49e7237f23729cbe2b07209e
7
+ data.tar.gz: 40d6f05bbc3ac4125d0e26f5ff21d0df8fd96fea36eb86efdb99547d3a16d1decb28feb8e93e86ee0cb0382bd21a1453d94cf77b0131e1974fae5ac1487be652
@@ -1,5 +1,14 @@
1
1
  # Change log
2
2
 
3
+ ### 1.2.0 - 2018-02-15
4
+
5
+ * features
6
+ * add safe and dangerous middleware
7
+ * add middleware for check custom response
8
+ * deprecations
9
+ * configure
10
+ * Esplanade::Middleware
11
+
3
12
  ### 1.1.2 - 2018-02-14
4
13
 
5
14
  * bug fixes
data/README.md CHANGED
@@ -30,38 +30,35 @@ Or install it yourself as:
30
30
 
31
31
  ## Usage
32
32
 
33
- Example:
34
-
35
- `middlewares/your_middleware.rb`
33
+ `config/application.rb`
36
34
 
37
35
  ```ruby
38
- class YourMiddleware < Esplanade::Middleware
39
- def call(env)
40
- request = Esplanade::Request.new(@documentation, env)
41
- request.validation.valid!
36
+ config.middleware.use Esplanade::SafeMiddleware, apib_path: 'doc.apib'
37
+ ```
42
38
 
43
- status, headers, body = @app.call(env)
39
+ ## Middleware
44
40
 
45
- response = Esplanade::Response.new(request, status, body)
46
- response.validation.valid!
41
+ ### Esplanade::SafeMiddleware
47
42
 
48
- [status, headers, body]
49
- rescue Esplanade::Error => e
50
- your_render_error(e)
51
- end
52
- end
53
- ```
43
+ Only debug logger.
54
44
 
55
- `config/application.rb`
45
+ ### Esplanade::DangerousMiddleware
46
+
47
+ It throws errors, so you will need to add your own middleware for processing.
56
48
 
57
49
  ```ruby
58
- require 'esplanade'
59
- Esplanade.configure do |config|
60
- config.apib_path = 'doc/backend.apib'
61
- end
50
+ config.middleware.use YourMiddleware
51
+ config.middleware.use Esplanade::DangerousMiddleware, apib_path: 'doc.apib'
52
+ ```
53
+
54
+ ### Esplanade::CheckCustomResponseMiddleware
62
55
 
63
- require_relative '../middlewares/your_middleware'
64
- config.middleware.use YourMiddleware
56
+ If you want to be sure that you have documented new custom responses.
57
+
58
+ ```ruby
59
+ config.middleware.use Esplanade::CheckCustomResponseMiddleware, apib_path: 'doc.apib'
60
+ config.middleware.use YourMiddleware
61
+ config.middleware.use Esplanade::DangerousMiddleware, apib_path: 'doc.apib'
65
62
  ```
66
63
 
67
64
  ## Esplanade::Error
@@ -108,7 +105,7 @@ Error message: `{:request=>{:method=>"method", :path=>"path"}, :status=>"status"
108
105
 
109
106
  Error message: `{:request=>{:method=>"method", :path=>"path"}, :status=>"status", :body=>"body", :error=>["error"]}`.
110
107
 
111
- ## Config
108
+ ## Middleware args
112
109
 
113
110
  ### apib_path
114
111
 
@@ -1,4 +1,7 @@
1
1
  require 'esplanade/middleware'
2
+ require 'esplanade/middlewares/safe_middleware'
3
+ require 'esplanade/middlewares/dangerous_middleware'
4
+ require 'esplanade/middlewares/check_custom_response_middleware'
2
5
  require 'esplanade/configuration'
3
6
 
4
7
  module Esplanade
@@ -4,12 +4,17 @@ require 'esplanade/response'
4
4
 
5
5
  module Esplanade
6
6
  class Middleware
7
- def initialize(app)
7
+ def initialize(
8
+ app,
9
+ prefix: Esplanade.configuration.prefix,
10
+ apib_path: Esplanade.configuration.apib_path,
11
+ drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
12
+ )
8
13
  @app = app
9
14
  @documentation = Tomograph::Tomogram.new(
10
- prefix: Esplanade.configuration.prefix,
11
- apib_path: Esplanade.configuration.apib_path,
12
- drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
15
+ prefix: prefix,
16
+ apib_path: apib_path,
17
+ drafter_yaml_path: drafter_yaml_path
13
18
  )
14
19
  end
15
20
 
@@ -0,0 +1,32 @@
1
+ require 'tomograph'
2
+ require 'esplanade/request'
3
+ require 'esplanade/response'
4
+
5
+ module Esplanade
6
+ class CheckCustomResponseMiddleware
7
+ def initialize(
8
+ app,
9
+ prefix: Esplanade.configuration.prefix,
10
+ apib_path: Esplanade.configuration.apib_path,
11
+ drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
12
+ )
13
+ @app = app
14
+ @documentation = Tomograph::Tomogram.new(
15
+ prefix: prefix,
16
+ apib_path: apib_path,
17
+ drafter_yaml_path: drafter_yaml_path
18
+ )
19
+ end
20
+
21
+ def call(env)
22
+ request = Esplanade::Request.new(@documentation, env)
23
+
24
+ status, headers, body = @app.call(env)
25
+
26
+ response = Esplanade::Response.new(request, status, body)
27
+ response.validation.valid!
28
+
29
+ [status, headers, body]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require 'tomograph'
2
+ require 'esplanade/request'
3
+ require 'esplanade/response'
4
+
5
+ module Esplanade
6
+ class DangerousMiddleware
7
+ def initialize(
8
+ app,
9
+ prefix: Esplanade.configuration.prefix,
10
+ apib_path: Esplanade.configuration.apib_path,
11
+ drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
12
+ )
13
+ @app = app
14
+ @documentation = Tomograph::Tomogram.new(
15
+ prefix: prefix,
16
+ apib_path: apib_path,
17
+ drafter_yaml_path: drafter_yaml_path
18
+ )
19
+ end
20
+
21
+ def call(env)
22
+ request = Esplanade::Request.new(@documentation, env)
23
+ request.validation.valid!
24
+
25
+ status, headers, body = @app.call(env)
26
+
27
+ response = Esplanade::Response.new(request, status, body)
28
+ response.validation.valid!
29
+
30
+ [status, headers, body]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,47 @@
1
+ require 'tomograph'
2
+ require 'esplanade/request'
3
+ require 'esplanade/response'
4
+
5
+ module Esplanade
6
+ class SafeMiddleware
7
+ def initialize(
8
+ app,
9
+ prefix: Esplanade.configuration.prefix,
10
+ apib_path: Esplanade.configuration.apib_path,
11
+ drafter_yaml_path: Esplanade.configuration.drafter_yaml_path
12
+ )
13
+ @app = app
14
+ @documentation = Tomograph::Tomogram.new(
15
+ prefix: prefix,
16
+ apib_path: apib_path,
17
+ drafter_yaml_path: drafter_yaml_path
18
+ )
19
+ end
20
+
21
+ def call(env)
22
+ request = Esplanade::Request.new(@documentation, env)
23
+ check_request(request)
24
+
25
+ status, headers, body = @app.call(env)
26
+
27
+ response = Esplanade::Response.new(request, status, body)
28
+ check_response(response)
29
+
30
+ [status, headers, body]
31
+ end
32
+
33
+ def check_request(request)
34
+ request.validation.valid!
35
+ Rails.logger.debug 'ESPLANADE SAYS THAT THE REQUEST IS VALID'
36
+ rescue Esplanade::Request::Error => e
37
+ Rails.logger.debug "ESPLANADE SKIP: #{e.inspect}"
38
+ end
39
+
40
+ def check_response(response)
41
+ response.validation.valid!
42
+ Rails.logger.debug 'ESPLANADE SAYS THAT THE RESPONSE IS VALID'
43
+ rescue Esplanade::Response::Error => e
44
+ Rails.logger.debug "ESPLANADE SKIP: #{e.inspect}"
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Esplanade
2
- VERSION = '1.1.2'.freeze
2
+ VERSION = '1.2.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.1.2
4
+ version: 1.2.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-14 00:00:00.000000000 Z
11
+ date: 2018-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -202,6 +202,9 @@ files:
202
202
  - lib/esplanade/configuration.rb
203
203
  - lib/esplanade/error.rb
204
204
  - lib/esplanade/middleware.rb
205
+ - lib/esplanade/middlewares/check_custom_response_middleware.rb
206
+ - lib/esplanade/middlewares/dangerous_middleware.rb
207
+ - lib/esplanade/middlewares/safe_middleware.rb
205
208
  - lib/esplanade/request.rb
206
209
  - lib/esplanade/request/doc.rb
207
210
  - lib/esplanade/request/raw.rb