esplanade 1.5.0 → 1.8.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
  SHA256:
3
- metadata.gz: a3373c627cdf10a0e2f896e87f1d35ac03f54e35633a405feb2948e550ed8a1c
4
- data.tar.gz: f264e61df01786b3d14ecb9771691c330b6e028ddba7e2067e0a73b2fbfbace5
3
+ metadata.gz: 6ffb0698e7cf24ebc36233050d09fd554687ce58d52e7bd7ca22cdccb13d005a
4
+ data.tar.gz: a70a122a41e29e8c7124cea908110340440702af5da52b6e41a32d73348214b2
5
5
  SHA512:
6
- metadata.gz: ffa353a02394d3bafe0d2197932b3e1243bed4dd2fe11c47cc7a235f733db739c00fa698bdb9f689624fd1064c24f0af2c74a2ff26b31dbe6c4eb7e359e4cb13
7
- data.tar.gz: b9a19774d5bdd62d65854525b1a8606bc4babb0cd1eb02ffcb0737c5e12f05f72e0c81fb60866fcb86e5db5e5cebad9f7849aab75a520aec3a8176feacd06812
6
+ metadata.gz: 3ee7a3176c117d301dd0bc96bd460ae23fba1a052d371a8a0be9ce4d7f70f6234c9047fb07835573e6a1444bbc91069ed62b1972899d2e1619dfb84a09a9749a
7
+ data.tar.gz: 06dc2239fa3d97135ffcc6046fbd9b7fb2581ba8ba15e93c56df3caca5777856037a5a638118a03f86e9c43fb76257c43fcf0695ab6aaf9f65bbd5fd4c04005e
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ uses: ruby/setup-ruby@v1
27
+ # uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
28
+ with:
29
+ ruby-version: 2.7
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.4
3
4
 
4
- Metrics/LineLength:
5
- Max: 120
5
+ Layout/LineLength:
6
+ Enabled: false
6
7
 
7
8
  Style/Documentation:
8
9
  Enabled: false
@@ -13,6 +14,12 @@ Style/FrozenStringLiteralComment:
13
14
  Metrics/BlockLength:
14
15
  Enabled: false
15
16
 
17
+ Metrics/ParameterLists:
18
+ Enabled: false
19
+
20
+ Metrics/MethodLength:
21
+ Enabled: false
22
+
16
23
  Style/IfUnlessModifier:
17
24
  Enabled: false
18
25
 
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.2.0
1
+ ruby 2.7.1
data/CHANGELOG.md CHANGED
@@ -1,6 +1,30 @@
1
1
  # Change log
2
2
 
3
- ### 1.4.1 - 2020-04-07
3
+ ### 1.8.0 - 2021-09-29
4
+
5
+ * patch
6
+ * remove multi_json
7
+
8
+ ### 1.7.1 - 2021-02-10
9
+
10
+ * setting
11
+ * improve gemspec dependency for tomograph
12
+
13
+ ### 1.7.0 - 2020-12-22
14
+
15
+ * improvements
16
+ * changed middleware arguments
17
+
18
+ ### 1.6.0 - 2020-10-12
19
+
20
+ * features
21
+ * in the errors write not only a documented path but also a raw [#11](https://github.com/funbox/esplanade/issues/11)
22
+ * write in the documentation that the body is empty and nil is skipped [#13](https://github.com/funbox/esplanade/issues/13)
23
+ * redefine error PrefixNotMatch for response [#17](https://github.com/funbox/esplanade/issues/17)
24
+ * content-type can contain additional parameters [#21](https://github.com/funbox/esplanade/issues/21)
25
+ * update esplanade for the new tomograph [#29](https://github.com/funbox/esplanade/issues/29)
26
+
27
+ ### 1.5.0 - 2020-04-07
4
28
 
5
29
  * improvements
6
30
  * updated dependenses
data/README.md CHANGED
@@ -1,16 +1,36 @@
1
1
  # Esplanade
2
2
 
3
- <a href="https://funbox.ru">
4
- <img src="https://funbox.ru/badges/sponsored_by_funbox_compact.svg" alt="Sponsored by FunBox" width=250 />
5
- </a>
6
-
7
3
  [![Gem Version](https://badge.fury.io/rb/esplanade.svg)](https://badge.fury.io/rb/esplanade)
8
- [![Build Status](https://travis-ci.org/funbox/esplanade.svg?branch=master)](https://travis-ci.org/funbox/esplanade)
9
4
 
10
- This gem will help you to validate and synchronize your API in strict accordance to the documentation in
5
+ This gem helps you to validate and synchronize your API in strict accordance to the documentation in
11
6
  [API Blueprint](https://apiblueprint.org/) format.
12
- To do this it automatically searches received requestes and responses in the documentation and run validates
13
- json-schemas.
7
+ To do this it automatically searches received requests and responses in the documentation and run
8
+ JSON-schemas validators.
9
+
10
+ ## Contents
11
+
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [Middlewares](#middlewares)
15
+ - [Esplanade::SafeMiddleware](#esplanadesafemiddleware)
16
+ - [Esplanade::DangerousMiddleware](#esplanadedangerousmiddleware)
17
+ - [Esplanade::CheckCustomResponseMiddleware](#esplanadecheckcustomresponsemiddleware)
18
+ - [Esplanade::Error](#esplanadeerror)
19
+ - [Esplanade::Request::Error](#esplanaderequesterror)
20
+ - [Esplanade::Request::PrefixNotMatch](#esplanaderequestprefixnotmatch)
21
+ - [Esplanade::Request::NotDocumented](#esplanaderequestnotdocumented)
22
+ - [Esplanade::Request::ContentTypeIsNotJson](#esplanaderequestcontenttypeisnotjson)
23
+ - [Esplanade::Request::BodyIsNotJson](#esplanaderequestbodyisnotjson)
24
+ - [Esplanade::Request::Invalid](#esplanaderequestinvalid)
25
+ - [Esplanade::Response::Error](#esplanaderesponseerror)
26
+ - [Esplanade::Response::NotDocumented](#esplanaderesponsenotdocumented)
27
+ - [Esplanade::Response::BodyIsNotJson](#esplanaderesponsebodyisnotjson)
28
+ - [Esplanade::Response::Invalid](#esplanaderesponseinvalid)
29
+ - [Middleware args](#middleware-args)
30
+ - [`apib_path`](#apib_path)
31
+ - [`drafter_yaml_path`](#drafter_yaml_path)
32
+ - [`prefix`](#prefix)
33
+ - [License](#license)
14
34
 
15
35
  ## Installation
16
36
 
@@ -20,107 +40,189 @@ Add this line to your application's Gemfile:
20
40
  gem 'esplanade'
21
41
  ```
22
42
 
23
- And then execute:
43
+ After that execute:
24
44
 
25
- $ bundle
45
+ ```bash
46
+ $ bundle
47
+ ```
26
48
 
27
- Or install it yourself as:
49
+ Or install the gem by yourself:
28
50
 
29
- $ gem install esplanade
51
+ ```bash
52
+ $ gem install esplanade
53
+ ```
30
54
 
31
55
  ## Usage
32
56
 
33
- `config/application.rb`
57
+ `config/application.rb`:
34
58
 
35
59
  ```ruby
36
- config.middleware.use Esplanade::SafeMiddleware, apib_path: 'doc.apib'
60
+ config.middleware.use Esplanade::SafeMiddleware, drafter_yaml_path: 'doc.yaml'
37
61
  ```
38
62
 
39
- ## Middleware
63
+ ## Middlewares
40
64
 
41
65
  ### Esplanade::SafeMiddleware
42
66
 
43
- Only debug logger.
67
+ Debug logger.
44
68
 
45
69
  ### Esplanade::DangerousMiddleware
46
70
 
47
- It throws errors, so you will need to add your own middleware for processing.
71
+ It throws errors, so you should add your own middleware for processing.
48
72
 
49
73
  ```ruby
50
- config.middleware.use YourMiddleware
51
- config.middleware.use Esplanade::DangerousMiddleware, apib_path: 'doc.apib'
74
+ config.middleware.use YourMiddleware
75
+ config.middleware.use Esplanade::DangerousMiddleware, drafter_yaml_path: 'doc.yaml'
52
76
  ```
53
77
 
54
78
  ### Esplanade::CheckCustomResponseMiddleware
55
79
 
56
- If you want to be sure that you have documented new custom responses.
80
+ Use it if you want to be sure that you have documented new custom responses.
57
81
 
58
82
  ```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'
83
+ config.middleware.use Esplanade::CheckCustomResponseMiddleware, drafter_yaml_path: 'doc.yaml'
84
+ config.middleware.use YourMiddleware
85
+ config.middleware.use Esplanade::DangerousMiddleware, drafter_yaml_path: 'doc.yaml'
62
86
  ```
63
87
 
64
88
  ## Esplanade::Error
65
89
 
66
- From him the `Esplanade::Request::Error` and `Esplanade::Response::Error` are inherited.
90
+ Parent class for those described below.
67
91
 
68
92
  ### Esplanade::Request::Error
69
93
 
70
- From him the `Esplanade::Request::PrefixNotMatch`, `Esplanade::Request::NotDocumented`, `Esplanade::Request::BodyIsNotJson` and `Esplanade::Request::Invalid` are inherited.
94
+ Parent class for those described below. Inherited from `Esplanade::Error`.
71
95
 
72
96
  #### Esplanade::Request::PrefixNotMatch
73
97
 
74
- Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
98
+ Error message format:
99
+
100
+ ```ruby
101
+ {
102
+ :method => "method",
103
+ :path => "path",
104
+ :raw_path => "path",
105
+ :content_type => "content_type"
106
+ }
107
+ ```
75
108
 
76
109
  #### Esplanade::Request::NotDocumented
77
110
 
78
- Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
111
+ Error message format:
112
+
113
+ ```ruby
114
+ {
115
+ :method => "method",
116
+ :path => "path",
117
+ :raw_path => "path",
118
+ :content_type => "content_type"
119
+ }
120
+ ```
79
121
 
80
122
  #### Esplanade::Request::ContentTypeIsNotJson
81
123
 
82
- Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type"}`.
124
+ Error message format:
125
+
126
+ ```ruby
127
+ {
128
+ :method => "method",
129
+ :path => "path",
130
+ :raw_path => "path",
131
+ :content_type => "content_type"
132
+ }
133
+ ```
83
134
 
84
135
  #### Esplanade::Request::BodyIsNotJson
85
136
 
86
- Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type", :body=>"{\"state\": 1"}`.
137
+ Throws an error also when the body is empty and equal nil.
138
+
139
+ Error message format:
140
+
141
+ ```ruby
142
+ {
143
+ :method => "method",
144
+ :path => "path",
145
+ :raw_path => "path",
146
+ :content_type => "content_type",
147
+ :body => "body"
148
+ }
149
+ ```
87
150
 
88
151
  #### Esplanade::Request::Invalid
89
152
 
90
- Error message: `{:method=>"method", :path=>"path", :content_type=>"content_type", :body=>"body", :error=>["error"]}`.
153
+ Error message format:
154
+
155
+ ```ruby
156
+ {
157
+ :method => "method",
158
+ :path => "path",
159
+ :raw_path => "path",
160
+ :content_type => "content_type",
161
+ :body => "body",
162
+ :error => ["error"]
163
+ }
164
+ ```
91
165
 
92
166
  ### Esplanade::Response::Error
93
167
 
94
- From him the `Esplanade::Response::NotDocumented`, `Esplanade::Response::BodyIsNotJson` and `Esplanade::Response::Invalid` are inherited.
168
+ Parent class for those described below. Inherited from `Esplanade::Error`.
95
169
 
96
170
  #### Esplanade::Response::NotDocumented
97
171
 
98
- Error message: `{:request=>{:method=>"method", :path=>"path"}, :status=>"status"}`.
172
+ Error message format:
99
173
 
100
- #### Esplanade::Response::BodyIsNotJson
101
-
102
- Only if the documentation for all the responses of one request indicates that `Content-Type: application/json`.
174
+ ```ruby
175
+ {
176
+ :request => {
177
+ :method => "method",
178
+ :path => "path",
179
+ :raw_path => "path"
180
+ },
181
+ :status => "status"
182
+ }
183
+ ```
103
184
 
104
- Error message: `{:request=>{:method=>"method", :path=>"path"}, :status=>"status", :body=>"body"}`.
185
+ #### Esplanade::Response::BodyIsNotJson
105
186
 
106
- #### Esplanade::Response::Invalid
187
+ It's thrown when expected response to request isn't JSON (not `Content-Type: application/json`) and there's no non-JSON responses documented for the endpoint.
107
188
 
108
- Error message: `{:request=>{:method=>"method", :path=>"path"}, :status=>"status", :body=>"body", :error=>["error"]}`.
189
+ Error message format:
109
190
 
110
- ## Middleware args
111
-
112
- ### apib_path
191
+ ```ruby
192
+ {
193
+ :request => {
194
+ :method => "method",
195
+ :path => "path",
196
+ :raw_path => "path"
197
+ },
198
+ :status => "status",
199
+ :body => "body"
200
+ }
201
+ ```
113
202
 
114
- Path to API Blueprint documentation. There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
203
+ #### Esplanade::Response::Invalid
115
204
 
116
- ### drafter_yaml_path
205
+ Error message format:
117
206
 
118
- Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
207
+ ```ruby
208
+ {
209
+ :request => {
210
+ :method => "method",
211
+ :path => "path",
212
+ :raw_path => "path"
213
+ },
214
+ :status => "status",
215
+ :body => "body",
216
+ :error => ["error"]
217
+ }
218
+ ```
119
219
 
120
- ### prefix
220
+ ## Middleware args
121
221
 
122
- Prefix of API requests. Example: `'/api'`. The prefix is added to the requests in the documentation.
222
+ Support any [tomograph constructor-params](https://github.com/funbox/tomograph/tree/master#constructor-params)
123
223
 
124
224
  ## License
125
225
 
126
226
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
227
+
228
+ [![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)
data/esplanade.gemspec CHANGED
@@ -17,12 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.require_paths = ['lib']
18
18
 
19
19
  spec.add_runtime_dependency 'json-schema', '~> 2.6', '>= 2.6.2'
20
- spec.add_runtime_dependency 'multi_json', '~> 1.11', '>= 1.11.1'
21
- spec.add_runtime_dependency 'tomograph', '~> 2.0', '>= 2.0.0'
22
- spec.add_development_dependency 'byebug', '>= 10.0.0'
23
- spec.add_development_dependency 'rake', '~> 13'
24
- spec.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
25
- spec.add_development_dependency 'rubocop', '~> 0.81', '>= 0.81.0'
26
- spec.add_development_dependency 'simplecov', '~> 0.18', '>= 0.18'
20
+ spec.add_runtime_dependency 'tomograph', '~> 3.1', '>= 3.1.0'
21
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.3'
22
+ spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
23
+ spec.add_development_dependency 'rspec', '~> 3.10'
24
+ spec.add_development_dependency 'rubocop', '~> 1.22.0'
25
+ spec.add_development_dependency 'simplecov', '~> 0.21'
27
26
  spec.required_ruby_version = '>= 2.4.0'
28
27
  end
@@ -1,11 +1,9 @@
1
1
  module Esplanade
2
2
  class Configuration
3
- attr_accessor :apib_path,
4
- :drafter_yaml_path,
5
- :prefix
3
+ attr_accessor :params
6
4
 
7
5
  def initialize
8
- @prefix = ''
6
+ @params = {}
9
7
  end
10
8
  end
11
9
  end
@@ -4,18 +4,9 @@ require 'esplanade/response'
4
4
 
5
5
  module Esplanade
6
6
  class Middleware
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
- )
7
+ def initialize(app, **params)
13
8
  @app = app
14
- @documentation = Tomograph::Tomogram.new(
15
- prefix: prefix,
16
- apib_path: apib_path,
17
- drafter_yaml_path: drafter_yaml_path
18
- )
9
+ @documentation = Tomograph::Tomogram.new(Esplanade.configuration.params.merge(params))
19
10
  end
20
11
 
21
12
  def call(env)
@@ -4,18 +4,9 @@ require 'esplanade/response'
4
4
 
5
5
  module Esplanade
6
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
- )
7
+ def initialize(app, **params)
13
8
  @app = app
14
- @documentation = Tomograph::Tomogram.new(
15
- prefix: prefix,
16
- apib_path: apib_path,
17
- drafter_yaml_path: drafter_yaml_path
18
- )
9
+ @documentation = Tomograph::Tomogram.new(Esplanade.configuration.params.merge(params))
19
10
  end
20
11
 
21
12
  def call(env)
@@ -4,18 +4,9 @@ require 'esplanade/response'
4
4
 
5
5
  module Esplanade
6
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
- )
7
+ def initialize(app, **params)
13
8
  @app = app
14
- @documentation = Tomograph::Tomogram.new(
15
- prefix: prefix,
16
- apib_path: apib_path,
17
- drafter_yaml_path: drafter_yaml_path
18
- )
9
+ @documentation = Tomograph::Tomogram.new(Esplanade.configuration.params.merge(params))
19
10
  end
20
11
 
21
12
  def call(env)
@@ -4,18 +4,9 @@ require 'esplanade/response'
4
4
 
5
5
  module Esplanade
6
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
- )
7
+ def initialize(app, **params)
13
8
  @app = app
14
- @documentation = Tomograph::Tomogram.new(
15
- prefix: prefix,
16
- apib_path: apib_path,
17
- drafter_yaml_path: drafter_yaml_path
18
- )
9
+ @documentation = Tomograph::Tomogram.new(Esplanade.configuration.params.merge(params))
19
10
  end
20
11
 
21
12
  def call(env)
@@ -19,8 +19,8 @@ module Esplanade
19
19
  @tomogram
20
20
  end
21
21
 
22
- def json_schema
23
- @json_schema ||= tomogram.request
22
+ def json_schemas
23
+ @json_schemas ||= tomogram.requests
24
24
  end
25
25
 
26
26
  def method
@@ -47,6 +47,7 @@ module Esplanade
47
47
  {
48
48
  method: @raw.method,
49
49
  path: @raw.path,
50
+ raw_path: @raw.raw_path,
50
51
  content_type: @raw.content_type
51
52
  }
52
53
  end
@@ -5,9 +5,10 @@ module Esplanade
5
5
  class PrefixNotMatch < Error; end
6
6
 
7
7
  class NotDocumented < Error
8
- def initialize(method:, path:, content_type:)
8
+ def initialize(method:, path:, raw_path:, content_type:)
9
9
  @method = method
10
10
  @path = path
11
+ @raw_path = raw_path
11
12
  @content_type = content_type
12
13
 
13
14
  super(to_hash)
@@ -17,14 +18,16 @@ module Esplanade
17
18
  {
18
19
  method: @method,
19
20
  path: @path,
21
+ raw_path: @raw_path,
20
22
  content_type: @content_type
21
23
  }
22
24
  end
23
25
  end
24
26
 
25
27
  class ContentTypeIsNotJson < Error
26
- def initialize(method:, path:, content_type:)
28
+ def initialize(method:, path:, raw_path:, content_type:)
27
29
  @method = method
30
+ @raw_path = raw_path
28
31
  @path = path
29
32
  @content_type = content_type
30
33
 
@@ -35,15 +38,17 @@ module Esplanade
35
38
  {
36
39
  method: @method,
37
40
  path: @path,
41
+ raw_path: @raw_path,
38
42
  content_type: @content_type
39
43
  }
40
44
  end
41
45
  end
42
46
 
43
47
  class BodyIsNotJson < Error
44
- def initialize(method:, path:, content_type:, body:)
48
+ def initialize(method:, path:, raw_path:, content_type:, body:)
45
49
  @method = method
46
50
  @path = path
51
+ @raw_path = raw_path
47
52
  @content_type = content_type
48
53
  @body = body
49
54
 
@@ -54,6 +59,7 @@ module Esplanade
54
59
  {
55
60
  method: @method,
56
61
  path: @path,
62
+ raw_path: @raw_path,
57
63
  content_type: @content_type,
58
64
  body: @body
59
65
  }
@@ -61,9 +67,10 @@ module Esplanade
61
67
  end
62
68
 
63
69
  class Invalid < Error
64
- def initialize(method:, path:, content_type:, body:, error:)
70
+ def initialize(method:, path:, raw_path:, content_type:, body:, error:)
65
71
  @method = method
66
72
  @path = path
73
+ @raw_path = raw_path
67
74
  @content_type = content_type
68
75
  @body = body
69
76
  @error = error
@@ -75,6 +82,7 @@ module Esplanade
75
82
  {
76
83
  method: @method,
77
84
  path: @path,
85
+ raw_path: @raw_path,
78
86
  content_type: @content_type,
79
87
  body: @body,
80
88
  error: @error
@@ -1,5 +1,3 @@
1
- require 'multi_json'
2
-
3
1
  module Esplanade
4
2
  class Request
5
3
  class Raw
@@ -18,8 +16,8 @@ module Esplanade
18
16
  end
19
17
 
20
18
  def to_hash
21
- @hash ||= MultiJson.load(to_string)
22
- rescue MultiJson::ParseError
19
+ @hash ||= JSON.parse(to_string.to_s)
20
+ rescue JSON::ParserError
23
21
  raise BodyIsNotJson.new(**message)
24
22
  end
25
23
 
@@ -37,6 +35,7 @@ module Esplanade
37
35
  {
38
36
  method: @raw_request.method,
39
37
  path: @raw_request.path,
38
+ raw_path: @raw_request.raw_path,
40
39
  content_type: @raw_request.content_type,
41
40
  body: reduced_version
42
41
  }
@@ -15,12 +15,16 @@ module Esplanade
15
15
  @path ||= @env['PATH_INFO']
16
16
  end
17
17
 
18
+ def raw_path
19
+ @raw_path ||= "#{@env['PATH_INFO']}/#{@env['QUERY_STRING']}"
20
+ end
21
+
18
22
  def body
19
23
  @body ||= Body.new(self, @env)
20
24
  end
21
25
 
22
26
  def content_type
23
- @content_type ||= @env['CONTENT_TYPE']
27
+ @content_type ||= @env['CONTENT_TYPE'].to_s.split(';').first
24
28
  end
25
29
  end
26
30
  end
@@ -12,17 +12,38 @@ module Esplanade
12
12
  def valid!
13
13
  raise ContentTypeIsNotJson.new(**mini_message) unless @doc.content_type == 'application/json'
14
14
 
15
- @error ||= JSON::Validator.fully_validate(@doc.json_schema, @raw.body.to_hash)
15
+ @error ||= if @doc.json_schemas.size == 1
16
+ one_json_schema
17
+ else
18
+ more_than_one_json_schema
19
+ end
16
20
 
17
21
  raise Invalid.new(**message) unless @error.empty?
18
22
  end
19
23
 
20
24
  private
21
25
 
26
+ def one_json_schema
27
+ JSON::Validator.fully_validate(@doc.json_schemas.first, @raw.body.to_hash)
28
+ end
29
+
30
+ def more_than_one_json_schema
31
+ main_res = @doc.json_schemas.each do |json_schema|
32
+ res = JSON::Validator.fully_validate(json_schema, @raw.body.to_hash)
33
+ break res if res == []
34
+ end
35
+ if main_res == []
36
+ []
37
+ else
38
+ ['invalid']
39
+ end
40
+ end
41
+
22
42
  def mini_message
23
43
  {
24
44
  method: @doc.method,
25
45
  path: @doc.path,
46
+ raw_path: @raw.raw_path,
26
47
  content_type: @doc.content_type
27
48
  }
28
49
  end
@@ -31,6 +52,7 @@ module Esplanade
31
52
  {
32
53
  method: @raw.method,
33
54
  path: @raw.path,
55
+ raw_path: @raw.raw_path,
34
56
  content_type: @raw.content_type,
35
57
  body: @raw.body.to_hash,
36
58
  error: @error
@@ -27,6 +27,7 @@ module Esplanade
27
27
  {
28
28
  request: {
29
29
  method: @request.raw.method,
30
+ raw_path: @request.raw.raw_path,
30
31
  path: @request.raw.path
31
32
  },
32
33
  status: @raw.status
@@ -6,6 +6,7 @@ module Esplanade
6
6
  def initialize(request:, status:)
7
7
  @method = request[:method]
8
8
  @path = request[:path]
9
+ @raw_path = request[:raw_path]
9
10
  @status = status
10
11
 
11
12
  super(to_hash)
@@ -16,7 +17,8 @@ module Esplanade
16
17
  request:
17
18
  {
18
19
  method: @method,
19
- path: @path
20
+ path: @path,
21
+ raw_path: @raw_path
20
22
  },
21
23
  status: @status
22
24
  }
@@ -27,6 +29,7 @@ module Esplanade
27
29
  def initialize(request:, status:, body:)
28
30
  @method = request[:method]
29
31
  @path = request[:path]
32
+ @raw_path = request[:raw_path]
30
33
  @status = status
31
34
  @body = body
32
35
 
@@ -38,7 +41,8 @@ module Esplanade
38
41
  request:
39
42
  {
40
43
  method: @method,
41
- path: @path
44
+ path: @path,
45
+ raw_path: @raw_path
42
46
  },
43
47
  status: @status,
44
48
  body: @body
@@ -50,6 +54,7 @@ module Esplanade
50
54
  def initialize(request:, status:, body:, error:)
51
55
  @method = request[:method]
52
56
  @path = request[:path]
57
+ @raw_path = request[:raw_path]
53
58
  @status = status
54
59
  @body = body
55
60
  @error = error
@@ -62,7 +67,8 @@ module Esplanade
62
67
  request:
63
68
  {
64
69
  method: @method,
65
- path: @path
70
+ path: @path,
71
+ raw_path: @raw_path
66
72
  },
67
73
  status: @status,
68
74
  body: @body,
@@ -1,5 +1,3 @@
1
- require 'multi_json'
2
-
3
1
  module Esplanade
4
2
  class Response
5
3
  class Raw
@@ -16,8 +14,8 @@ module Esplanade
16
14
  end
17
15
 
18
16
  def to_hash
19
- @hash ||= MultiJson.load(to_string)
20
- rescue MultiJson::ParseError
17
+ @hash ||= JSON.parse(to_string)
18
+ rescue JSON::ParserError
21
19
  raise BodyIsNotJson.new(**message)
22
20
  end
23
21
 
@@ -27,7 +25,8 @@ module Esplanade
27
25
  {
28
26
  request: {
29
27
  method: @request.raw.method,
30
- path: @request.raw.path
28
+ path: @request.raw.path,
29
+ raw_path: @request.raw.raw_path
31
30
  },
32
31
  status: @raw_response.status,
33
32
  body: @raw_response.body.to_string
@@ -29,10 +29,10 @@ module Esplanade
29
29
  res = JSON::Validator.fully_validate(json_schema, @raw.body.to_hash)
30
30
  break res if res == []
31
31
  end
32
- if main_res != []
33
- ['invalid']
34
- else
32
+ if main_res == []
35
33
  []
34
+ else
35
+ ['invalid']
36
36
  end
37
37
  end
38
38
 
@@ -40,7 +40,8 @@ module Esplanade
40
40
  {
41
41
  request: {
42
42
  method: @request.raw.method,
43
- path: @request.raw.path
43
+ path: @request.raw.path,
44
+ raw_path: @request.raw.raw_path
44
45
  },
45
46
  status: @raw.status,
46
47
  body: @raw.body.to_string,
@@ -1,3 +1,3 @@
1
1
  module Esplanade
2
- VERSION = '1.5.0'.freeze
2
+ VERSION = '1.8.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.5.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-07 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -31,146 +31,119 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.6.2
33
33
  - !ruby/object:Gem::Dependency
34
- name: multi_json
34
+ name: tomograph
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.11'
39
+ version: '3.1'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.11.1
42
+ version: 3.1.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '1.11'
49
+ version: '3.1'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.11.1
52
+ version: 3.1.0
53
53
  - !ruby/object:Gem::Dependency
54
- name: tomograph
54
+ name: byebug
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '2.0'
59
+ version: '11.1'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 2.0.0
63
- type: :runtime
62
+ version: 11.1.3
63
+ type: :development
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: '2.0'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 2.0.0
73
- - !ruby/object:Gem::Dependency
74
- name: byebug
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: 10.0.0
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
69
+ version: '11.1'
84
70
  - - ">="
85
71
  - !ruby/object:Gem::Version
86
- version: 10.0.0
72
+ version: 11.1.3
87
73
  - !ruby/object:Gem::Dependency
88
74
  name: rake
89
75
  requirement: !ruby/object:Gem::Requirement
90
76
  requirements:
91
77
  - - "~>"
92
78
  - !ruby/object:Gem::Version
93
- version: '13'
79
+ version: '13.0'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 13.0.6
94
83
  type: :development
95
84
  prerelease: false
96
85
  version_requirements: !ruby/object:Gem::Requirement
97
86
  requirements:
98
87
  - - "~>"
99
88
  - !ruby/object:Gem::Version
100
- version: '13'
89
+ version: '13.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 13.0.6
101
93
  - !ruby/object:Gem::Dependency
102
94
  name: rspec
103
95
  requirement: !ruby/object:Gem::Requirement
104
96
  requirements:
105
97
  - - "~>"
106
98
  - !ruby/object:Gem::Version
107
- version: '3.9'
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 3.9.0
99
+ version: '3.10'
111
100
  type: :development
112
101
  prerelease: false
113
102
  version_requirements: !ruby/object:Gem::Requirement
114
103
  requirements:
115
104
  - - "~>"
116
105
  - !ruby/object:Gem::Version
117
- version: '3.9'
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: 3.9.0
106
+ version: '3.10'
121
107
  - !ruby/object:Gem::Dependency
122
108
  name: rubocop
123
109
  requirement: !ruby/object:Gem::Requirement
124
110
  requirements:
125
111
  - - "~>"
126
112
  - !ruby/object:Gem::Version
127
- version: '0.81'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: 0.81.0
113
+ version: 1.22.0
131
114
  type: :development
132
115
  prerelease: false
133
116
  version_requirements: !ruby/object:Gem::Requirement
134
117
  requirements:
135
118
  - - "~>"
136
119
  - !ruby/object:Gem::Version
137
- version: '0.81'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: 0.81.0
120
+ version: 1.22.0
141
121
  - !ruby/object:Gem::Dependency
142
122
  name: simplecov
143
123
  requirement: !ruby/object:Gem::Requirement
144
124
  requirements:
145
125
  - - "~>"
146
126
  - !ruby/object:Gem::Version
147
- version: '0.18'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: '0.18'
127
+ version: '0.21'
151
128
  type: :development
152
129
  prerelease: false
153
130
  version_requirements: !ruby/object:Gem::Requirement
154
131
  requirements:
155
132
  - - "~>"
156
133
  - !ruby/object:Gem::Version
157
- version: '0.18'
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: '0.18'
161
- description:
134
+ version: '0.21'
135
+ description:
162
136
  email:
163
137
  - d.efimov@fun-box.ru
164
138
  executables: []
165
139
  extensions: []
166
140
  extra_rdoc_files: []
167
141
  files:
168
- - ".github/workflows/gempush.yml"
142
+ - ".github/workflows/ruby.yml"
169
143
  - ".gitignore"
170
144
  - ".rubocop.yml"
171
145
  - ".ruby-version"
172
146
  - ".tool-versions"
173
- - ".travis.yml"
174
147
  - CHANGELOG.md
175
148
  - CODE_OF_CONDUCT.md
176
149
  - Gemfile
@@ -200,11 +173,11 @@ files:
200
173
  - lib/esplanade/response/raw/body.rb
201
174
  - lib/esplanade/response/validation.rb
202
175
  - lib/esplanade/version.rb
203
- homepage:
176
+ homepage:
204
177
  licenses:
205
178
  - MIT
206
179
  metadata: {}
207
- post_install_message:
180
+ post_install_message:
208
181
  rdoc_options: []
209
182
  require_paths:
210
183
  - lib
@@ -220,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
193
  version: '0'
221
194
  requirements: []
222
195
  rubygems_version: 3.1.2
223
- signing_key:
196
+ signing_key:
224
197
  specification_version: 4
225
198
  summary: Validate requests and responses against API Blueprint specifications
226
199
  test_files: []
@@ -1,28 +0,0 @@
1
- name: Ruby Gem
2
-
3
- on:
4
- push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
8
-
9
- jobs:
10
- build:
11
- name: Build + Publish
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v2
16
- - name: Set up Ruby 2.6
17
- uses: actions/setup-ruby@v1
18
-
19
- - name: Publish to RubyGems
20
- run: |
21
- mkdir -p $HOME/.gem
22
- touch $HOME/.gem/credentials
23
- chmod 0600 $HOME/.gem/credentials
24
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
25
- gem build *.gemspec
26
- gem push *.gem
27
- env:
28
- GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
- before_install: gem install bundler