fitting 2.3.0 → 2.4.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 +8 -0
- data/README.md +60 -23
- data/lib/fitting/configuration/legacy.rb +3 -1
- data/lib/fitting/configuration/yaml.rb +5 -1
- data/lib/fitting/statistics/template.rb +4 -1
- data/lib/fitting/storage/white_list.rb +82 -3
- data/lib/fitting/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39a9c98935fdc1df35f3ee2a3777873fc5b4961a
|
4
|
+
data.tar.gz: 6526756da2a69633d954dc9f4e488de09f3cfd70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be0e322093ef0574c3bd71587a8c808344b20d519e40dcc652b7edf21e090779a0852f32da4fc186bfb819642393daeba8b9317f68ab6a6c01ee28d69110ed6
|
7
|
+
data.tar.gz: 56f0baa5c8745db69f0233e3a2ceeee7dc92b8fff9e008ade95212c520c06d31ca04fbc1771b64dd8ca6c0e3e171e326d015f31e75f8befc0783ae046e163403
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
<img src="https://funbox.ru/badges/sponsored_by_funbox.svg" alt="Sponsored by FunBox" width=250 />
|
5
5
|
</a>
|
6
6
|
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/fitting.svg)](https://badge.fury.io/rb/fitting)
|
7
8
|
[![Build Status](https://travis-ci.org/funbox/fitting.svg?branch=master)](https://travis-ci.org/funbox/fitting)
|
8
9
|
|
9
10
|
This gem will help you implement your API in strict accordance to the documentation in [API Blueprint](https://apiblueprint.org/) format.
|
@@ -27,16 +28,18 @@ Or install it yourself as:
|
|
27
28
|
|
28
29
|
## Usage
|
29
30
|
|
31
|
+
In your `.fitting.yml`:
|
32
|
+
|
33
|
+
```yaml
|
34
|
+
apib_path: /path/to/doc.apib
|
35
|
+
```
|
36
|
+
|
30
37
|
In your `spec_helper.rb`:
|
31
38
|
|
32
39
|
```ruby
|
33
40
|
require 'fitting'
|
34
41
|
|
35
42
|
Fitting.statistics
|
36
|
-
|
37
|
-
Fitting.configure do |config|
|
38
|
-
config.apib_path = '/path/to/doc.apib'
|
39
|
-
end
|
40
43
|
```
|
41
44
|
|
42
45
|
or
|
@@ -55,10 +58,6 @@ RSpec.configure do |config|
|
|
55
58
|
responses.statistics.save
|
56
59
|
end
|
57
60
|
end
|
58
|
-
|
59
|
-
Fitting.configure do |config|
|
60
|
-
config.apib_path = '/path/to/doc.apib'
|
61
|
-
end
|
62
61
|
```
|
63
62
|
|
64
63
|
## Example output
|
@@ -142,13 +141,17 @@ Default: all paths. This is an array of paths that are mandatory for implementat
|
|
142
141
|
This list does not affect the work of the matcher.
|
143
142
|
This list is only for the report in the console.
|
144
143
|
|
145
|
-
```
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
144
|
+
```yaml
|
145
|
+
white_list:
|
146
|
+
/users:
|
147
|
+
- DELETE
|
148
|
+
- POST
|
149
|
+
/users/{id}:
|
150
|
+
- GET
|
151
|
+
- PATCH
|
152
|
+
/users/{id}/employees:
|
153
|
+
- GET
|
154
|
+
/sessions: []
|
152
155
|
```
|
153
156
|
|
154
157
|
Empty array `[]` means all methods.
|
@@ -159,22 +162,56 @@ Default: all resources. This is an array of resources that are mandatory for imp
|
|
159
162
|
This list does not affect the work of the matcher.
|
160
163
|
This list is only for the report in the console.
|
161
164
|
|
162
|
-
```
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
}
|
165
|
+
```yaml
|
166
|
+
resource_white_list:
|
167
|
+
/users:
|
168
|
+
- DELETE /users/{id}
|
169
|
+
- POST /users
|
170
|
+
- GET /users/{id}
|
171
|
+
- PATCH /users/{id}
|
172
|
+
/users/{id}/employees:
|
173
|
+
- GET /users/{id}/employees
|
174
|
+
/sessions: []
|
168
175
|
```
|
169
176
|
|
170
177
|
Empty array `[]` means all methods.
|
171
178
|
|
179
|
+
### include_resources
|
180
|
+
|
181
|
+
Default: all resources if `include_resources` and `include_actions` is not used.
|
182
|
+
This is an array of resources that are mandatory for implementation.
|
183
|
+
This list does not affect the work of the matcher.
|
184
|
+
This list is only for the report in the console.
|
185
|
+
|
186
|
+
```yaml
|
187
|
+
include_resources:
|
188
|
+
- /sessions
|
189
|
+
```
|
190
|
+
|
191
|
+
### include_actions
|
192
|
+
|
193
|
+
Default: all paths if `include_resources` and `include_actions` is not used.
|
194
|
+
This is an array of paths that are mandatory for implementation.
|
195
|
+
This list does not affect the work of the matcher.
|
196
|
+
This list is only for the report in the console.
|
197
|
+
|
198
|
+
```yaml
|
199
|
+
include_actions:
|
200
|
+
- DELETE /users/{id}
|
201
|
+
- POST /users
|
202
|
+
- GET /users/{id}
|
203
|
+
- PATCH /users/{id}
|
204
|
+
- GET /users/{id}/employees
|
205
|
+
```
|
206
|
+
|
172
207
|
### ignore_list
|
173
208
|
|
174
209
|
You can use ignore list for omit checks with matchers.
|
175
210
|
|
176
|
-
```
|
177
|
-
|
211
|
+
```yaml
|
212
|
+
ignore_list:
|
213
|
+
- %r{/api/v1/users/[1-9].}
|
214
|
+
- %r{/api/v1/comments}
|
178
215
|
```
|
179
216
|
|
180
217
|
It's work only for match_schema (NOT FOR strictly_match_schema)
|
@@ -10,7 +10,9 @@ module Fitting
|
|
10
10
|
:prefix,
|
11
11
|
:white_list,
|
12
12
|
:resource_white_list,
|
13
|
-
:ignore_list
|
13
|
+
:ignore_list,
|
14
|
+
:include_resources,
|
15
|
+
:include_actions
|
14
16
|
|
15
17
|
def initialize(yaml, title = 'fitting')
|
16
18
|
@apib_path = yaml['apib_path']
|
@@ -20,6 +22,8 @@ module Fitting
|
|
20
22
|
@white_list = yaml['white_list']
|
21
23
|
@resource_white_list = yaml['resource_white_list']
|
22
24
|
@ignore_list = yaml['ignore_list']
|
25
|
+
@include_resources = yaml['include_resources']
|
26
|
+
@include_actions = yaml['include_actions']
|
23
27
|
@title = title
|
24
28
|
default
|
25
29
|
end
|
@@ -19,7 +19,7 @@ module Fitting
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def stats
|
22
|
-
if
|
22
|
+
if @config.white_list.present? || @config.resource_white_list.present? || @config.include_resources.present?
|
23
23
|
[
|
24
24
|
['[Black list]', black_statistics].join("\n"),
|
25
25
|
['[White list]', white_statistics].join("\n"),
|
@@ -80,8 +80,11 @@ module Fitting
|
|
80
80
|
|
81
81
|
def white_list
|
82
82
|
@white_list ||= Fitting::Storage::WhiteList.new(
|
83
|
+
@config.prefix,
|
83
84
|
@config.white_list,
|
84
85
|
@config.resource_white_list,
|
86
|
+
@config.include_resources,
|
87
|
+
@config.include_actions,
|
85
88
|
@config.tomogram.to_resources
|
86
89
|
)
|
87
90
|
end
|
@@ -3,17 +3,28 @@ require 'tomograph'
|
|
3
3
|
module Fitting
|
4
4
|
module Storage
|
5
5
|
class WhiteList
|
6
|
-
def initialize(white_list, resource_white_list, resources)
|
6
|
+
def initialize(prefix, white_list, resource_white_list, include_resources, include_actions, resources)
|
7
|
+
@prefix = prefix
|
7
8
|
@white_list = white_list
|
8
9
|
@resource_white_list = resource_white_list
|
10
|
+
@include_resources = include_resources
|
11
|
+
@include_actions = include_actions
|
9
12
|
@resources = resources
|
10
13
|
@warnings = []
|
11
14
|
end
|
12
15
|
|
13
16
|
def to_a
|
14
|
-
return nil if @white_list == nil && @resource_white_list == nil
|
17
|
+
return nil if @white_list == nil && @resource_white_list == nil && @include_resources == nil && @include_actions == nil
|
15
18
|
return @white_list if @white_list
|
16
|
-
@white_list = transformation
|
19
|
+
return @white_list = transformation if @resource_white_list
|
20
|
+
@white_list = {}
|
21
|
+
if @include_resources
|
22
|
+
@white_list.merge!(new_transformation)
|
23
|
+
end
|
24
|
+
if @include_actions
|
25
|
+
@white_list.merge!(postnew_transformation)
|
26
|
+
end
|
27
|
+
@white_list
|
17
28
|
end
|
18
29
|
|
19
30
|
def without_group
|
@@ -71,6 +82,74 @@ module Fitting
|
|
71
82
|
path: Tomograph::Path.new(array[1]).to_s
|
72
83
|
}
|
73
84
|
end
|
85
|
+
|
86
|
+
def new_transformation
|
87
|
+
@new_resources = {}
|
88
|
+
@resources.map do |key, value|
|
89
|
+
@new_resources.merge!(Tomograph::Path.new(key).to_s => value)
|
90
|
+
end
|
91
|
+
result = new_without_group.group_by { |action| action[:path] }
|
92
|
+
result.inject({}) do |res, group|
|
93
|
+
methods = group.last.map { |gr| gr[:method] }
|
94
|
+
res.merge(group.first => methods)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def new_without_group
|
99
|
+
return @newwithout_group_list if @newwithout_group_list
|
100
|
+
@newwithout_group_list = @include_resources.inject([]) do |all_requests, resource|
|
101
|
+
if resource[0] == '/'
|
102
|
+
new_resource_selection(resource, all_requests)
|
103
|
+
else
|
104
|
+
new_resource_selection("/#{resource}", all_requests)
|
105
|
+
end
|
106
|
+
end.flatten.uniq
|
107
|
+
puts_warnings
|
108
|
+
@newwithout_group_list
|
109
|
+
end
|
110
|
+
|
111
|
+
def new_resource_selection(resource, all_requests)
|
112
|
+
new_find_warnings(resource)
|
113
|
+
new_requests(@new_resources[resource], all_requests)
|
114
|
+
end
|
115
|
+
|
116
|
+
def new_requests(resource, all_requests)
|
117
|
+
return all_requests unless resource
|
118
|
+
|
119
|
+
resource.map do |request|
|
120
|
+
all_requests.push(request_hash(request))
|
121
|
+
end
|
122
|
+
all_requests
|
123
|
+
end
|
124
|
+
|
125
|
+
def new_find_warnings(resource)
|
126
|
+
return nil if @new_resources[resource]
|
127
|
+
@warnings.push(
|
128
|
+
"FITTING WARNING: In the documentation there isn't resource from the resource_white_list #{resource}"
|
129
|
+
)
|
130
|
+
end
|
131
|
+
|
132
|
+
def postnew_transformation
|
133
|
+
result = postnew_without_group.group_by { |action| action[:path] }
|
134
|
+
result.inject({}) do |res, group|
|
135
|
+
methods = group.last.map { |gr| gr[:method] }
|
136
|
+
res.merge(group.first => methods)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def postnew_without_group
|
141
|
+
return @postnewwithout_group_list if @postnewwithout_group_list
|
142
|
+
@postnewwithout_group_list = @include_actions.inject([]) do |all_requests, resource|
|
143
|
+
method, path = resource.split(' ')
|
144
|
+
if path[0] == '/'
|
145
|
+
new_requests(["#{method} #{@prefix}#{path}"], all_requests)
|
146
|
+
else
|
147
|
+
new_requests(["#{method} #{@prefix}/#{path}"], all_requests)
|
148
|
+
end
|
149
|
+
end.flatten.uniq
|
150
|
+
puts_warnings
|
151
|
+
@postnewwithout_group_list
|
152
|
+
end
|
74
153
|
end
|
75
154
|
end
|
76
155
|
end
|
data/lib/fitting/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fitting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2018-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|