tomograph 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +3 -3
- data/CHANGELOG.md +8 -0
- data/README.md +167 -54
- data/exe/tomograph +8 -2
- data/lib/tomograph/openapi/openapi2.rb +91 -0
- data/lib/tomograph/openapi/openapi3.rb +118 -0
- data/lib/tomograph/tomogram.rb +7 -6
- data/lib/tomograph/version.rb +1 -1
- data/tomograph.gemspec +1 -0
- metadata +24 -3
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b59905a33024b038fb21b6561dcb9b607845aa7c9510f0ee91fc51d89a347c
|
4
|
+
data.tar.gz: a5f9e9d20b2b0dfcaec764967b6253eab832ac6d25bcd16d528c7e0780a7f967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6cc9c2abdef8c55223b86b888a6e5c2b003a8d770ba321ba799bc95c60f41dfd395de4b4570f7dcb6ea2aec2e7a7ae1f577871dd4155683606e5a2f09e64b27
|
7
|
+
data.tar.gz: 86624093fb9aafbc3705646f75dfec2ebda49f2a66b43419c205aaf358edeca111af2ba41ff02df240dd046a51cbd95fe2976d13bb2da660c25315545e971d48
|
data/.github/workflows/ruby.yml
CHANGED
@@ -23,10 +23,10 @@ jobs:
|
|
23
23
|
- name: Set up Ruby
|
24
24
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
25
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
-
|
27
|
-
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
# uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
|
28
28
|
with:
|
29
|
-
ruby-version: 2.
|
29
|
+
ruby-version: 2.7
|
30
30
|
- name: Install dependencies
|
31
31
|
run: bundle install
|
32
32
|
- name: Run tests
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
### 3.1.0 - 2021-02-09
|
4
|
+
|
5
|
+
* features
|
6
|
+
* support Swagger/OpenAPI 2.0 [#47](https://github.com/funbox/tomograph/issues/47)
|
7
|
+
* support OpenAPI 3.0 [#50](https://github.com/funbox/tomograph/issues/50)
|
8
|
+
* removed
|
9
|
+
* delete travis [#45](https://github.com/funbox/tomograph/issues/45)
|
10
|
+
|
3
11
|
### 3.0.1 - 2020-10-14
|
4
12
|
|
5
13
|
* removed
|
data/README.md
CHANGED
@@ -1,12 +1,86 @@
|
|
1
1
|
# Tomograph
|
2
2
|
|
3
|
-
|
3
|
+
Convert API Blueprint, Swagger and OpenAPI to minimal routes with JSON Schema. For ease of use and creation of new tools.
|
4
4
|
|
5
|
-
|
5
|
+
Will look like
|
6
6
|
|
7
|
-
|
7
|
+
```json
|
8
|
+
[
|
9
|
+
{
|
10
|
+
"path": "/sessions",
|
11
|
+
"method": "POST",
|
12
|
+
"content-type": "application/json",
|
13
|
+
"requests": [{
|
14
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
15
|
+
"type": "object",
|
16
|
+
"properties": {
|
17
|
+
"login": {
|
18
|
+
"type": "string"
|
19
|
+
},
|
20
|
+
"password": {
|
21
|
+
"type": "string"
|
22
|
+
},
|
23
|
+
"captcha": {
|
24
|
+
"type": "string"
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"required": [
|
28
|
+
"login",
|
29
|
+
"password"
|
30
|
+
]
|
31
|
+
}],
|
32
|
+
"responses": [
|
33
|
+
{
|
34
|
+
"status": "401",
|
35
|
+
"content-type": "application/json",
|
36
|
+
"body": {}
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"status": "429",
|
40
|
+
"content-type": "application/json",
|
41
|
+
"body": {}
|
42
|
+
},
|
43
|
+
{
|
44
|
+
"status": "201",
|
45
|
+
"content-type": "application/json",
|
46
|
+
"body": {
|
47
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
48
|
+
"type": "object",
|
49
|
+
"properties": {
|
50
|
+
"confirmation": {
|
51
|
+
"type": "object",
|
52
|
+
"properties": {
|
53
|
+
"id": {
|
54
|
+
"type": "string"
|
55
|
+
},
|
56
|
+
"type": {
|
57
|
+
"type": "string"
|
58
|
+
},
|
59
|
+
"operation": {
|
60
|
+
"type": "string"
|
61
|
+
}
|
62
|
+
},
|
63
|
+
"required": [
|
64
|
+
"id",
|
65
|
+
"type",
|
66
|
+
"operation"
|
67
|
+
]
|
68
|
+
},
|
69
|
+
"captcha": {
|
70
|
+
"type": "string"
|
71
|
+
},
|
72
|
+
"captcha_does_not_match": {
|
73
|
+
"type": "boolean"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
]
|
79
|
+
}
|
80
|
+
]
|
81
|
+
```
|
8
82
|
|
9
|
-
|
83
|
+
## Installation
|
10
84
|
|
11
85
|
Then add this line to your application's Gemfile:
|
12
86
|
|
@@ -28,36 +102,72 @@ $ gem install tomograph
|
|
28
102
|
|
29
103
|
## Usage
|
30
104
|
|
105
|
+
### In code
|
106
|
+
|
107
|
+
#### OpenAPI 2.0
|
108
|
+
|
109
|
+
Also Swagger
|
110
|
+
|
31
111
|
```ruby
|
32
112
|
require 'tomograph'
|
33
113
|
|
34
|
-
tomogram = Tomograph::Tomogram.new(
|
114
|
+
tomogram = Tomograph::Tomogram.new(openapi2_json_path: '/path/to/doc.json')
|
35
115
|
```
|
36
116
|
|
37
|
-
|
117
|
+
#### OpenAPI 3.0
|
38
118
|
|
39
|
-
|
119
|
+
Also OpenAPI
|
40
120
|
|
41
|
-
```
|
42
|
-
tomograph
|
121
|
+
```ruby
|
122
|
+
require 'tomograph'
|
123
|
+
|
124
|
+
tomogram = Tomograph::Tomogram.new(openapi3_yaml_path: '/path/to/doc.yaml')
|
43
125
|
```
|
44
126
|
|
45
|
-
|
46
|
-
|
127
|
+
#### API Blueprint
|
128
|
+
|
129
|
+
First you need to install [drafter](https://github.com/apiaryio/drafter).
|
130
|
+
Works after conversion from API Blueprint to API Elements (in YAML file) with Drafter.
|
131
|
+
|
132
|
+
That is, I mean that you first need to do this
|
47
133
|
|
48
134
|
```bash
|
49
|
-
|
135
|
+
drafter doc.apib -o doc.yaml
|
50
136
|
```
|
51
137
|
|
52
|
-
|
138
|
+
and then
|
53
139
|
|
54
|
-
```
|
55
|
-
tomograph
|
140
|
+
```ruby
|
141
|
+
require 'tomograph'
|
142
|
+
|
143
|
+
tomogram = Tomograph::Tomogram.new(drafter_yaml_path: '/path/to/doc.yaml')
|
144
|
+
```
|
145
|
+
|
146
|
+
#### Tomograph
|
147
|
+
|
148
|
+
To use additional features of the pre-converted
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
require 'tomograph'
|
152
|
+
|
153
|
+
tomogram = Tomograph::Tomogram.new(tomogram_json_path: '/path/to/doc.json')
|
56
154
|
```
|
57
155
|
|
58
|
-
|
156
|
+
#### prefix
|
157
|
+
Default: `''`
|
158
|
+
|
159
|
+
You can specify API prefix and path to the spec using one of the possible formats:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
|
163
|
+
```
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
Tomograph::Tomogram.new(prefix: '/api/v2', tomogram_json_path: '/path/to/doc.json')
|
167
|
+
```
|
59
168
|
|
60
|
-
|
169
|
+
#### to_json
|
170
|
+
Use `to_json` for converting to JSON, example from API Blueprint:
|
61
171
|
|
62
172
|
```ruby
|
63
173
|
tomogram.to_json
|
@@ -65,7 +175,7 @@ tomogram.to_json
|
|
65
175
|
|
66
176
|
<details>
|
67
177
|
<summary>Example input</summary>
|
68
|
-
|
178
|
+
|
69
179
|
```apib
|
70
180
|
FORMAT: 1A
|
71
181
|
HOST: http://test.local
|
@@ -110,7 +220,7 @@ tomogram.to_json
|
|
110
220
|
|
111
221
|
<details>
|
112
222
|
<summary>Example output</summary>
|
113
|
-
|
223
|
+
|
114
224
|
```json
|
115
225
|
[
|
116
226
|
{
|
@@ -188,41 +298,35 @@ tomogram.to_json
|
|
188
298
|
```
|
189
299
|
</details>
|
190
300
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
### `find_request`
|
301
|
+
#### to_a
|
302
|
+
```ruby
|
303
|
+
tomogram.to_a
|
304
|
+
```
|
196
305
|
|
306
|
+
#### find_request
|
197
307
|
```ruby
|
198
308
|
request = tomogram.find_request(method: 'GET', path: '/status/1?qwe=rty')
|
199
309
|
```
|
200
310
|
|
201
|
-
|
202
|
-
|
311
|
+
#### find_request_with_content_type
|
203
312
|
```ruby
|
204
313
|
request = tomogram.find_request_with_content_type(method: 'GET', path: '/status/1?qwe=rty', content_type: 'application/json')
|
205
314
|
```
|
206
315
|
|
207
|
-
|
208
|
-
|
316
|
+
#### `find_responses`
|
209
317
|
```ruby
|
210
318
|
responses = request.find_responses(status: '200')
|
211
319
|
```
|
212
320
|
|
213
|
-
|
214
|
-
|
215
|
-
### `prefix_match?`
|
216
|
-
|
321
|
+
#### prefix_match?
|
217
322
|
This may be useful if you specify a prefix.
|
218
323
|
|
219
324
|
```ruby
|
220
325
|
tomogram.prefix_match?('http://local/api/v2/users')
|
221
326
|
```
|
222
327
|
|
223
|
-
|
224
|
-
|
225
|
-
Maps resources with possible requests.
|
328
|
+
#### to_resources
|
329
|
+
Maps resources for API Blueprint with possible requests.
|
226
330
|
|
227
331
|
Example output:
|
228
332
|
|
@@ -232,39 +336,48 @@ Example output:
|
|
232
336
|
}
|
233
337
|
```
|
234
338
|
|
235
|
-
|
339
|
+
### Command line tool
|
236
340
|
|
237
|
-
|
341
|
+
CLI allows you to convert files from API Blueprint (API Elements), Swagger and OpenAPI to JSON Schema.
|
238
342
|
|
239
|
-
|
240
|
-
Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
|
241
|
-
```
|
343
|
+
Run CLI with `-h` to get detailed help:
|
242
344
|
|
243
|
-
```
|
244
|
-
|
345
|
+
```bash
|
346
|
+
tomograph -h
|
245
347
|
```
|
246
348
|
|
247
|
-
|
248
|
-
|
249
|
-
Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
|
349
|
+
To specify the handler version use the `-d` flag:
|
250
350
|
|
251
|
-
|
351
|
+
#### OpenAPI 2.0
|
352
|
+
```bash
|
353
|
+
tomograph -d openapi2 openapi2.json tomogram.json
|
354
|
+
```
|
252
355
|
|
253
|
-
|
356
|
+
#### OpenAPI 3.0
|
357
|
+
```bash
|
358
|
+
tomograph -d openapi3 openapi3.yaml doc.json
|
359
|
+
```
|
254
360
|
|
255
|
-
|
361
|
+
#### API Blueprint
|
362
|
+
```bash
|
363
|
+
tomograph -d 4 apielemetns.yaml doc.json
|
364
|
+
```
|
256
365
|
|
257
|
-
|
366
|
+
#### exclude-description
|
258
367
|
|
259
|
-
|
368
|
+
Exclude "description" keys from json-schemas.
|
260
369
|
|
261
|
-
|
370
|
+
```bash
|
371
|
+
tomograph -d 4 apielemetns.yaml doc.json --exclude-description
|
372
|
+
```
|
262
373
|
|
263
|
-
|
374
|
+
#### split
|
264
375
|
|
265
|
-
|
376
|
+
Split output into files by method. Output in dir path.
|
266
377
|
|
267
|
-
|
378
|
+
```bash
|
379
|
+
tomograph -d 4 --split apielemetns.yaml jsons/
|
380
|
+
```
|
268
381
|
|
269
382
|
## License
|
270
383
|
|
data/exe/tomograph
CHANGED
@@ -12,7 +12,7 @@ include Methadone::CLILogging
|
|
12
12
|
|
13
13
|
version Tomograph::VERSION
|
14
14
|
description 'Converts API Blueprint to JSON Schema'
|
15
|
-
on('-d DRAFTER_VERSION', '--drafter', 'Choose drafter version: crafter or 4. Default: use drafter v.4.')
|
15
|
+
on('-d DRAFTER_VERSION', '--drafter', 'Choose drafter version: crafter or 4, or OpenAPI version: openapi2 or openapi3. Default: use drafter v.4.')
|
16
16
|
on('--exclude-description', 'Exclude "description" keys.')
|
17
17
|
on('--split', 'Split output into files by method.')
|
18
18
|
arg :input, 'path/to/doc.yaml (API Elements)'
|
@@ -33,6 +33,10 @@ def choose_drafter(opt_parser)
|
|
33
33
|
:crafter
|
34
34
|
when '4'
|
35
35
|
:drafter_4
|
36
|
+
when 'openapi2'
|
37
|
+
:openapi2
|
38
|
+
when 'openapi3'
|
39
|
+
:openapi3
|
36
40
|
when nil
|
37
41
|
:drafter_4
|
38
42
|
else
|
@@ -64,7 +68,9 @@ main do |input, output|
|
|
64
68
|
version = choose_drafter(options['drafter'])
|
65
69
|
format_key = {
|
66
70
|
crafter: :crafter_yaml_path,
|
67
|
-
drafter_4: :drafter_yaml_path
|
71
|
+
drafter_4: :drafter_yaml_path,
|
72
|
+
openapi2: :openapi2_json_path,
|
73
|
+
openapi3: :openapi3_yaml_path
|
68
74
|
}[version]
|
69
75
|
|
70
76
|
tomogram = Tomograph::Tomogram.new(format_key => input)
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'tomograph/tomogram/action'
|
2
|
+
|
3
|
+
module Tomograph
|
4
|
+
module OpenApi
|
5
|
+
class OpenApi2
|
6
|
+
def initialize(prefix, json_schema_path)
|
7
|
+
@prefix = prefix
|
8
|
+
@documentation = JSON.parse(File.read(json_schema_path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_tomogram
|
12
|
+
@tomogram ||= @documentation['paths'].inject([]) do |result, action|
|
13
|
+
action[1].keys.each do |method|
|
14
|
+
result.push(Tomograph::Tomogram::Action.new(
|
15
|
+
path: "#{@prefix}#{action[0]}",
|
16
|
+
method: method.upcase,
|
17
|
+
content_type: '',
|
18
|
+
requests: [],
|
19
|
+
responses: responses(action[1][method]['responses'], @documentation['definitions']),
|
20
|
+
resource: ''))
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def responses(resp, defi)
|
27
|
+
resp.inject([]) do |result, reponse|
|
28
|
+
if reponse[1]['schema']
|
29
|
+
result.push(
|
30
|
+
status: reponse[0],
|
31
|
+
body: schema(reponse[1]['schema'], defi),
|
32
|
+
'content-type': ''
|
33
|
+
)
|
34
|
+
else
|
35
|
+
result.push(
|
36
|
+
status: reponse[0],
|
37
|
+
body: {},
|
38
|
+
'content-type': ''
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def schema(sche, defi)
|
45
|
+
if sche.keys.include?('$ref')
|
46
|
+
res = sche.merge('definitions' => {sche["$ref"][14..-1] => defi[sche["$ref"][14..-1]]})
|
47
|
+
if defi[sche["$ref"][14..-1]].to_s.include?('$ref')
|
48
|
+
keys = defi[sche["$ref"][14..-1]].to_s.split('"').find_all{|word| word.include?('definitions') }
|
49
|
+
keys.each do |key|
|
50
|
+
res["definitions"].merge!({key[14..-1] => defi[key[14..-1]]})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
res
|
54
|
+
else
|
55
|
+
if sche.to_s.include?('$ref')
|
56
|
+
res = sche.merge('definitions' => {})
|
57
|
+
keys = sche.to_s.split('"').find_all{|word| word.include?('definitions') }
|
58
|
+
keys.each do |key|
|
59
|
+
res["definitions"].merge!({key[14..-1] => defi[key[14..-1]]})
|
60
|
+
end
|
61
|
+
res
|
62
|
+
else
|
63
|
+
sche
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def search_hash(hash, key)
|
69
|
+
return hash[key] if hash.assoc(key)
|
70
|
+
hash.delete_if{|key, value| value.class != Hash}
|
71
|
+
new_hash = Hash.new
|
72
|
+
hash.each_value {|values| new_hash.merge!(values)}
|
73
|
+
unless new_hash.empty?
|
74
|
+
search_hash(new_hash, key)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_resources
|
79
|
+
return @to_resources if @to_resources
|
80
|
+
|
81
|
+
@to_resources = @documentation.group_by { |action| action['resource'] }
|
82
|
+
@to_resources = @to_resources.each_with_object({}) do |(resource, actions), resource_map|
|
83
|
+
requests = actions.map do |action|
|
84
|
+
"#{action['method']} #{@prefix}#{action['path']}"
|
85
|
+
end
|
86
|
+
resource_map[resource] = requests
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'tomograph/tomogram/action'
|
2
|
+
|
3
|
+
module Tomograph
|
4
|
+
module OpenApi
|
5
|
+
class OpenApi3
|
6
|
+
def initialize(prefix, openapi3_yaml_path)
|
7
|
+
@prefix = prefix
|
8
|
+
@documentation = YAML.load(File.read(openapi3_yaml_path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_tomogram
|
12
|
+
@tomogram ||= @documentation['paths'].inject([]) do |result, action|
|
13
|
+
action[1].keys.each do |method|
|
14
|
+
result.push(Tomograph::Tomogram::Action.new(
|
15
|
+
path: "#{@prefix}#{action[0]}",
|
16
|
+
method: method.upcase,
|
17
|
+
content_type: '',
|
18
|
+
requests: [],
|
19
|
+
responses: responses(action[1][method]['responses'], @documentation['components']['schemas']),
|
20
|
+
resource: ''))
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def responses(resp, defi)
|
27
|
+
resp.inject([]) do |result, response|
|
28
|
+
if response[1]['content'] == nil
|
29
|
+
#TODO 403Forbidden
|
30
|
+
result.push(
|
31
|
+
status: response[0],
|
32
|
+
body: {},
|
33
|
+
'content-type': ''
|
34
|
+
)
|
35
|
+
elsif response[1]['content'].values[0]['schema']
|
36
|
+
result.push(
|
37
|
+
status: response[0],
|
38
|
+
body: schema(response[1]['content'].values[0]['schema'], defi),
|
39
|
+
'content-type': ''
|
40
|
+
)
|
41
|
+
else
|
42
|
+
result.push(
|
43
|
+
status: response[0],
|
44
|
+
body: {},
|
45
|
+
'content-type': ''
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def schema(sche, defi)
|
52
|
+
if sche.keys.include?('$ref')
|
53
|
+
sche.merge!('components' => {})
|
54
|
+
sche['components'].merge!('schemas' => {})
|
55
|
+
sche['components']['schemas'].merge!({sche["$ref"][21..-1] => defi[sche["$ref"][21..-1]]})
|
56
|
+
|
57
|
+
if defi[sche["$ref"][21..-1]].to_s.include?('$ref')
|
58
|
+
keys = defi[sche["$ref"][21..-1]].to_s.split('"').find_all{|word| word.include?('#/components/schemas/') }
|
59
|
+
keys.each do |key|
|
60
|
+
sche['components']['schemas'].merge!({key[21..-1] => defi[key[21..-1]]})
|
61
|
+
|
62
|
+
if defi[key[21..-1]].to_s.include?('$ref')
|
63
|
+
keys2 = defi[key[21..-1]].to_s.split('"').find_all{|word| word.include?('#/components/schemas/') }
|
64
|
+
keys2.each do |key2|
|
65
|
+
sche['components']['schemas'].merge!({key2[21..-1] => defi[key2[21..-1]]})
|
66
|
+
|
67
|
+
if defi[key2[21..-1]].to_s.include?('$ref')
|
68
|
+
keys3 = defi[key2[21..-1]].to_s.split('"').find_all { |word| word.include?('#/components/schemas/') }.uniq
|
69
|
+
keys3.each do |key3|
|
70
|
+
sche['components']['schemas'].merge!({ key3[21..-1] => defi[key3[21..-1]] })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
sche
|
80
|
+
|
81
|
+
else
|
82
|
+
if sche.to_s.include?('$ref')
|
83
|
+
res = sche.merge('definitions' => {})
|
84
|
+
keys = sche.to_s.split('"').find_all{|word| word.include?('definitions') }
|
85
|
+
keys.each do |key|
|
86
|
+
res["definitions"].merge!({key[21..-1] => defi[key[21..-1]]})
|
87
|
+
end
|
88
|
+
res
|
89
|
+
else
|
90
|
+
sche
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def search_hash(hash, key)
|
96
|
+
return hash[key] if hash.assoc(key)
|
97
|
+
hash.delete_if{|key, value| value.class != Hash}
|
98
|
+
new_hash = Hash.new
|
99
|
+
hash.each_value {|values| new_hash.merge!(values)}
|
100
|
+
unless new_hash.empty?
|
101
|
+
search_hash(new_hash, key)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_resources
|
106
|
+
return @to_resources if @to_resources
|
107
|
+
|
108
|
+
@to_resources = @documentation.group_by { |action| action['resource'] }
|
109
|
+
@to_resources = @to_resources.each_with_object({}) do |(resource, actions), resource_map|
|
110
|
+
requests = actions.map do |action|
|
111
|
+
"#{action['method']} #{@prefix}#{action['path']}"
|
112
|
+
end
|
113
|
+
resource_map[resource] = requests
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/tomograph/tomogram.rb
CHANGED
@@ -3,16 +3,22 @@ require 'tomograph/path'
|
|
3
3
|
require 'tomograph/api_blueprint/json_schema'
|
4
4
|
require 'tomograph/api_blueprint/drafter_4/yaml'
|
5
5
|
require 'tomograph/api_blueprint/crafter/yaml'
|
6
|
+
require 'tomograph/openapi/openapi2'
|
7
|
+
require 'tomograph/openapi/openapi3'
|
6
8
|
|
7
9
|
module Tomograph
|
8
10
|
class Tomogram
|
9
11
|
extend Gem::Deprecate
|
10
12
|
|
11
|
-
def initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil)
|
13
|
+
def initialize(prefix: '', drafter_yaml_path: nil, tomogram_json_path: nil, crafter_yaml_path: nil, openapi2_json_path: nil, openapi3_yaml_path: nil)
|
12
14
|
@documentation = if tomogram_json_path
|
13
15
|
Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path)
|
14
16
|
elsif crafter_yaml_path
|
15
17
|
Tomograph::ApiBlueprint::Crafter::Yaml.new(prefix, crafter_yaml_path)
|
18
|
+
elsif openapi2_json_path
|
19
|
+
Tomograph::OpenApi::OpenApi2.new(prefix, openapi2_json_path)
|
20
|
+
elsif openapi3_yaml_path
|
21
|
+
Tomograph::OpenApi::OpenApi3.new(prefix, openapi3_yaml_path)
|
16
22
|
else
|
17
23
|
Tomograph::ApiBlueprint::Drafter4::Yaml.new(prefix, drafter_yaml_path)
|
18
24
|
end
|
@@ -23,11 +29,6 @@ module Tomograph
|
|
23
29
|
@actions ||= @documentation.to_tomogram
|
24
30
|
end
|
25
31
|
|
26
|
-
def to_hash
|
27
|
-
to_a.map(&:to_hash)
|
28
|
-
end
|
29
|
-
deprecate :to_hash, 'to_a with method access', 2018, 8
|
30
|
-
|
31
32
|
def to_json
|
32
33
|
JSON.pretty_generate(to_a.map(&:to_hash))
|
33
34
|
end
|
data/lib/tomograph/version.rb
CHANGED
data/tomograph.gemspec
CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
|
25
25
|
spec.add_development_dependency 'rubocop', '~> 0.81', '>= 0.81.0'
|
26
26
|
spec.add_development_dependency 'simplecov', '~> 0.18', '>= 0.18.5'
|
27
|
+
spec.add_development_dependency 'json-schema', '~> 2.8', '>= 2.8.1'
|
27
28
|
spec.required_ruby_version = '>= 2.4.0'
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomograph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.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: 2021-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: methadone
|
@@ -124,6 +124,26 @@ dependencies:
|
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: 0.18.5
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: json-schema
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '2.8'
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 2.8.1
|
137
|
+
type: :development
|
138
|
+
prerelease: false
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '2.8'
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 2.8.1
|
127
147
|
description: Convert API Blueprint to routes and JSON-Schemas
|
128
148
|
email:
|
129
149
|
- d.efimov@fun-box.ru
|
@@ -137,7 +157,6 @@ files:
|
|
137
157
|
- ".rubocop.yml"
|
138
158
|
- ".ruby-version"
|
139
159
|
- ".tool-versions"
|
140
|
-
- ".travis.yml"
|
141
160
|
- CHANGELOG.md
|
142
161
|
- CODE_OF_CONDUCT.md
|
143
162
|
- Gemfile
|
@@ -153,6 +172,8 @@ files:
|
|
153
172
|
- lib/tomograph/api_blueprint/drafter_4/yaml.rb
|
154
173
|
- lib/tomograph/api_blueprint/drafter_4/yaml/action.rb
|
155
174
|
- lib/tomograph/api_blueprint/json_schema.rb
|
175
|
+
- lib/tomograph/openapi/openapi2.rb
|
176
|
+
- lib/tomograph/openapi/openapi3.rb
|
156
177
|
- lib/tomograph/path.rb
|
157
178
|
- lib/tomograph/tomogram.rb
|
158
179
|
- lib/tomograph/tomogram/action.rb
|