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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +21 -24
- data/lib/esplanade.rb +3 -0
- data/lib/esplanade/middleware.rb +9 -4
- data/lib/esplanade/middlewares/check_custom_response_middleware.rb +32 -0
- data/lib/esplanade/middlewares/dangerous_middleware.rb +33 -0
- data/lib/esplanade/middlewares/safe_middleware.rb +47 -0
- data/lib/esplanade/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d56ac3bbfdcd35af5878ab7c38ba6192ef4e5957
|
4
|
+
data.tar.gz: a17fd30d62e0039c6d70389e8f197e1b46a8bf17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcbf87e4765ff6ac1b388e490c03dd9c72f57e062fdd9598e247ad4425e51f1723234142af8e0b89ff8611fe7e45834abbbb7c6c49e7237f23729cbe2b07209e
|
7
|
+
data.tar.gz: 40d6f05bbc3ac4125d0e26f5ff21d0df8fd96fea36eb86efdb99547d3a16d1decb28feb8e93e86ee0cb0382bd21a1453d94cf77b0131e1974fae5ac1487be652
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -30,38 +30,35 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Usage
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
`middlewares/your_middleware.rb`
|
33
|
+
`config/application.rb`
|
36
34
|
|
37
35
|
```ruby
|
38
|
-
|
39
|
-
|
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
|
-
|
39
|
+
## Middleware
|
44
40
|
|
45
|
-
|
46
|
-
response.validation.valid!
|
41
|
+
### Esplanade::SafeMiddleware
|
47
42
|
|
48
|
-
|
49
|
-
rescue Esplanade::Error => e
|
50
|
-
your_render_error(e)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
```
|
43
|
+
Only debug logger.
|
54
44
|
|
55
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
config.middleware.use YourMiddleware
|
51
|
+
config.middleware.use Esplanade::DangerousMiddleware, apib_path: 'doc.apib'
|
52
|
+
```
|
53
|
+
|
54
|
+
### Esplanade::CheckCustomResponseMiddleware
|
62
55
|
|
63
|
-
|
64
|
-
|
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
|
-
##
|
108
|
+
## Middleware args
|
112
109
|
|
113
110
|
### apib_path
|
114
111
|
|
data/lib/esplanade.rb
CHANGED
data/lib/esplanade/middleware.rb
CHANGED
@@ -4,12 +4,17 @@ require 'esplanade/response'
|
|
4
4
|
|
5
5
|
module Esplanade
|
6
6
|
class Middleware
|
7
|
-
def initialize(
|
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:
|
11
|
-
apib_path:
|
12
|
-
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
|
data/lib/esplanade/version.rb
CHANGED
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.
|
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-
|
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
|