tomograph 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -2
- data/CHANGELOG.md +5 -0
- data/exe/tomograph +10 -7
- data/lib/tomograph/api_blueprint/crafter/yaml/action.rb +13 -6
- data/lib/tomograph/api_blueprint/crafter/yaml.rb +22 -12
- data/lib/tomograph/api_blueprint/drafter_4/yaml/action.rb +10 -6
- data/lib/tomograph/api_blueprint/drafter_4/yaml.rb +20 -11
- data/lib/tomograph/api_blueprint/json_schema.rb +3 -2
- data/lib/tomograph/openapi/openapi2.rb +30 -33
- data/lib/tomograph/openapi/openapi3.rb +48 -51
- data/lib/tomograph/path.rb +1 -1
- data/lib/tomograph/tomogram.rb +7 -2
- data/lib/tomograph/version.rb +1 -1
- data/tomograph.gemspec +2 -2
- metadata +25 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab901173a56d7c3bb3627dc8e2103e21b2e6b321ab30d3df2d9c9f97726c2598
|
4
|
+
data.tar.gz: 9360f36f0a9aefb4e4c63b833cc26ac9ee88b6fb203ff59c7165af4bc7711dc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec6645d8dadd46bdb77a08b72083102d192b8e51381324fa36b0113f143f06dadf33d82e721c5f066f53e84dda109a9f9f4dc9c70512013faa0c8b8bfbdb3669
|
7
|
+
data.tar.gz: 834f29f892f7776e706d958573a2077347b2f7e06beafa55fed5ea85c59ff6a70751a1556e9682ce58a68c0bb9fe5db840dd7c1262c99d0f6aebe2abc662c838
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.4
|
3
3
|
|
4
|
-
|
4
|
+
Layout/LineLength:
|
5
5
|
Max: 120
|
6
6
|
|
7
7
|
Style/Documentation:
|
@@ -12,3 +12,21 @@ Style/FrozenStringLiteralComment:
|
|
12
12
|
|
13
13
|
Metrics/BlockLength:
|
14
14
|
Enabled: false
|
15
|
+
|
16
|
+
Naming/MemoizedInstanceVariableName:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Lint/DisjunctiveAssignmentInConstructor:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/ParameterLists:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 40
|
27
|
+
|
28
|
+
Metrics/AbcSize:
|
29
|
+
Max: 90
|
30
|
+
|
31
|
+
Metrics/ClassLength:
|
32
|
+
Max: 150
|
data/CHANGELOG.md
CHANGED
data/exe/tomograph
CHANGED
@@ -7,12 +7,15 @@ require 'methadone'
|
|
7
7
|
require 'tomograph'
|
8
8
|
require 'tomograph/version'
|
9
9
|
|
10
|
+
# rubocop:disable Style/MixinUsage
|
10
11
|
include Methadone::Main
|
11
12
|
include Methadone::CLILogging
|
13
|
+
# rubocop:enable Style/MixinUsage
|
12
14
|
|
13
15
|
version Tomograph::VERSION
|
14
16
|
description 'Converts API Blueprint to JSON Schema'
|
15
|
-
on('-d DRAFTER_VERSION', '--drafter', 'Choose drafter version: crafter or 4,
|
17
|
+
on('-d DRAFTER_VERSION', '--drafter', 'Choose drafter version: crafter or 4,
|
18
|
+
or OpenAPI version: openapi2 or openapi3. Default: use drafter v.4.')
|
16
19
|
on('--exclude-description', 'Exclude "description" keys.')
|
17
20
|
on('--split', 'Split output into files by method.')
|
18
21
|
arg :input, 'path/to/doc.yaml (API Elements)'
|
@@ -47,7 +50,7 @@ end
|
|
47
50
|
def write_split_json(actions, output)
|
48
51
|
FileUtils.mkdir_p(output)
|
49
52
|
actions.clone.each do |action|
|
50
|
-
json_name = "#{action.delete(
|
53
|
+
json_name = "#{action.delete('path')} #{action.delete('method')}.json"
|
51
54
|
[['/', '#'],
|
52
55
|
['{', '('],
|
53
56
|
['}', ')']].each do |pattern, replacement|
|
@@ -67,11 +70,11 @@ end
|
|
67
70
|
main do |input, output|
|
68
71
|
version = choose_drafter(options['drafter'])
|
69
72
|
format_key = {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
crafter: :crafter_yaml_path,
|
74
|
+
drafter_4: :drafter_yaml_path,
|
75
|
+
openapi2: :openapi2_json_path,
|
76
|
+
openapi3: :openapi3_yaml_path
|
77
|
+
}[version]
|
75
78
|
|
76
79
|
tomogram = Tomograph::Tomogram.new(format_key => input)
|
77
80
|
actions = tomogram.to_a.map(&:to_hash)
|
@@ -18,9 +18,9 @@ module Tomograph
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def content_type
|
21
|
-
if @content.first['attributes'].
|
22
|
-
|
23
|
-
|
21
|
+
if @content.first['attributes'].key?('headers') &&
|
22
|
+
@content.first['attributes']['headers']['content'][0]['content']['key']['content'] == 'Content-Type'
|
23
|
+
@content.first['attributes']['headers']['content'][0]['content']['value']['content']
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -33,7 +33,11 @@ module Tomograph
|
|
33
33
|
|
34
34
|
def json_schema(actions)
|
35
35
|
schema_node = actions.find do |action|
|
36
|
-
action &&
|
36
|
+
action &&
|
37
|
+
action.fetch('element', nil) == 'asset' &&
|
38
|
+
action.fetch('attributes', {})
|
39
|
+
.fetch('contentType', {})
|
40
|
+
.fetch('content', nil) == 'application/schema+json'
|
37
41
|
end
|
38
42
|
return {} unless schema_node
|
39
43
|
|
@@ -50,11 +54,14 @@ module Tomograph
|
|
50
54
|
response['element'] == 'httpResponse' && response['attributes']
|
51
55
|
end
|
52
56
|
@responses = @responses.map do |response|
|
57
|
+
content_type = if response['attributes'].key?('headers')
|
58
|
+
response['attributes']['headers']['content'][0]['content']['value']['content']
|
59
|
+
end
|
60
|
+
|
53
61
|
{
|
54
62
|
'status' => response['attributes']['statusCode']['content'].to_s,
|
55
63
|
'body' => json_schema(response['content']),
|
56
|
-
'content-type' =>
|
57
|
-
response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
|
64
|
+
'content-type' => content_type
|
58
65
|
}
|
59
66
|
end
|
60
67
|
end
|
@@ -24,6 +24,7 @@ module Tomograph
|
|
24
24
|
|
25
25
|
def group?(group)
|
26
26
|
return false if group['element'] == 'resource'
|
27
|
+
|
27
28
|
group['element'] != 'copy' && # Element is a human readable text
|
28
29
|
group['meta']['classes']['content'][0]['content'] == 'resourceGroup' # skip Data Structures
|
29
30
|
end
|
@@ -31,7 +32,9 @@ module Tomograph
|
|
31
32
|
def resources
|
32
33
|
@resources ||= groups.inject([]) do |result_groups, group|
|
33
34
|
result_groups.push(group['content'].each_with_object([]) do |resource, result_resources|
|
34
|
-
|
35
|
+
if resource?(resource)
|
36
|
+
result_resources.push('resource' => resource, 'resource_path' => resource_path(resource))
|
37
|
+
end
|
35
38
|
end)
|
36
39
|
end.flatten
|
37
40
|
end
|
@@ -46,9 +49,12 @@ module Tomograph
|
|
46
49
|
|
47
50
|
def transitions
|
48
51
|
@transitions ||= resources.inject([]) do |result_resources, resource|
|
49
|
-
result_resources.push(resource['resource']['content']
|
50
|
-
|
51
|
-
|
52
|
+
result_resources.push(resource['resource']['content']
|
53
|
+
.each_with_object([]) do |transition, result_transitions|
|
54
|
+
if transition?(transition)
|
55
|
+
result_transitions.push(transition_hash(transition, resource))
|
56
|
+
end
|
57
|
+
end)
|
52
58
|
end.flatten
|
53
59
|
end
|
54
60
|
|
@@ -65,18 +71,22 @@ module Tomograph
|
|
65
71
|
end
|
66
72
|
|
67
73
|
def transition_path(transition, resource_path)
|
68
|
-
transition['attributes'] && transition['attributes']['href'] &&
|
74
|
+
transition['attributes'] && transition['attributes']['href'] &&
|
75
|
+
transition['attributes']['href']['content'] || resource_path
|
69
76
|
end
|
70
77
|
|
71
78
|
def without_group_actions
|
72
79
|
transitions.inject([]) do |result_transition, transition|
|
73
|
-
result_transition.push(transition['transition']['content']
|
74
|
-
|
75
|
-
content
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
result_transition.push(transition['transition']['content']
|
81
|
+
.each_with_object([]) do |content, result_contents|
|
82
|
+
next unless action?(content)
|
83
|
+
|
84
|
+
result_contents.push(Tomograph::ApiBlueprint::Crafter::Yaml::Action.new(
|
85
|
+
content['content'],
|
86
|
+
transition['transition_path'],
|
87
|
+
transition['resource']
|
88
|
+
))
|
89
|
+
end)
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
@@ -18,9 +18,9 @@ module Tomograph
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def content_type
|
21
|
-
if @content.first['attributes'].
|
22
|
-
|
23
|
-
|
21
|
+
if @content.first['attributes'].key?('headers') &&
|
22
|
+
@content.first['attributes']['headers']['content'][0]['content']['key']['content'] == 'Content-Type'
|
23
|
+
@content.first['attributes']['headers']['content'][0]['content']['value']['content']
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -33,7 +33,8 @@ module Tomograph
|
|
33
33
|
|
34
34
|
def json_schema(actions)
|
35
35
|
schema_node = actions.find do |action|
|
36
|
-
action && action['element'] == 'asset' &&
|
36
|
+
action && action['element'] == 'asset' &&
|
37
|
+
action['attributes']['contentType']['content'] == 'application/schema+json'
|
37
38
|
end
|
38
39
|
return {} unless schema_node
|
39
40
|
|
@@ -50,11 +51,14 @@ module Tomograph
|
|
50
51
|
response['element'] == 'httpResponse' && response['attributes']
|
51
52
|
end
|
52
53
|
@responses = @responses.map do |response|
|
54
|
+
content_type = if response['attributes'].key?('headers')
|
55
|
+
response['attributes']['headers']['content'][0]['content']['value']['content']
|
56
|
+
end
|
57
|
+
|
53
58
|
{
|
54
59
|
'status' => response['attributes']['statusCode']['content'].to_s,
|
55
60
|
'body' => json_schema(response['content']),
|
56
|
-
'content-type' =>
|
57
|
-
response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
|
61
|
+
'content-type' => content_type
|
58
62
|
}
|
59
63
|
end
|
60
64
|
end
|
@@ -24,6 +24,7 @@ module Tomograph
|
|
24
24
|
|
25
25
|
def group?(group)
|
26
26
|
return false if group['element'] == 'resource'
|
27
|
+
|
27
28
|
group['element'] != 'copy' && # Element is a human readable text
|
28
29
|
group['meta']['classes']['content'][0]['content'] == 'resourceGroup' # skip Data Structures
|
29
30
|
end
|
@@ -31,7 +32,9 @@ module Tomograph
|
|
31
32
|
def resources
|
32
33
|
@resources ||= groups.inject([]) do |result_groups, group|
|
33
34
|
result_groups.push(group['content'].each_with_object([]) do |resource, result_resources|
|
34
|
-
|
35
|
+
if resource?(resource)
|
36
|
+
result_resources.push('resource' => resource, 'resource_path' => resource_path(resource))
|
37
|
+
end
|
35
38
|
end)
|
36
39
|
end.flatten
|
37
40
|
end
|
@@ -46,9 +49,12 @@ module Tomograph
|
|
46
49
|
|
47
50
|
def transitions
|
48
51
|
@transitions ||= resources.inject([]) do |result_resources, resource|
|
49
|
-
result_resources.push(resource['resource']['content']
|
50
|
-
|
51
|
-
|
52
|
+
result_resources.push(resource['resource']['content']
|
53
|
+
.each_with_object([]) do |transition, result_transitions|
|
54
|
+
if transition?(transition)
|
55
|
+
result_transitions.push(transition_hash(transition, resource))
|
56
|
+
end
|
57
|
+
end)
|
52
58
|
end.flatten
|
53
59
|
end
|
54
60
|
|
@@ -70,13 +76,16 @@ module Tomograph
|
|
70
76
|
|
71
77
|
def without_group_actions
|
72
78
|
transitions.inject([]) do |result_transition, transition|
|
73
|
-
result_transition.push(transition['transition']['content']
|
74
|
-
|
75
|
-
content
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
result_transition.push(transition['transition']['content']
|
80
|
+
.each_with_object([]) do |content, result_contents|
|
81
|
+
next unless action?(content)
|
82
|
+
|
83
|
+
result_contents.push(Tomograph::ApiBlueprint::Drafter4::Yaml::Action.new(
|
84
|
+
content['content'],
|
85
|
+
transition['transition_path'],
|
86
|
+
transition['resource']
|
87
|
+
))
|
88
|
+
end)
|
80
89
|
end
|
81
90
|
end
|
82
91
|
|
@@ -12,11 +12,12 @@ module Tomograph
|
|
12
12
|
@tomogram ||= @documentation.inject([]) do |result, action|
|
13
13
|
result.push(Tomograph::Tomogram::Action.new(
|
14
14
|
path: "#{@prefix}#{action['path']}",
|
15
|
-
method:
|
15
|
+
method: action['method'],
|
16
16
|
content_type: action['content-type'],
|
17
17
|
requests: action['requests'],
|
18
18
|
responses: action['responses'],
|
19
|
-
resource: action['resource']
|
19
|
+
resource: action['resource']
|
20
|
+
))
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
@@ -9,33 +9,33 @@ module Tomograph
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_tomogram
|
12
|
-
@tomogram ||= @documentation['paths'].
|
12
|
+
@tomogram ||= @documentation['paths'].each_with_object([]) do |action, result|
|
13
13
|
action[1].keys.each do |method|
|
14
14
|
result.push(Tomograph::Tomogram::Action.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
))
|
21
22
|
end
|
22
|
-
result
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def responses(resp, defi)
|
27
27
|
resp.inject([]) do |result, reponse|
|
28
28
|
if reponse[1]['schema']
|
29
|
-
|
29
|
+
result.push(
|
30
30
|
status: reponse[0],
|
31
31
|
body: schema(reponse[1]['schema'], defi),
|
32
32
|
'content-type': ''
|
33
|
-
|
33
|
+
)
|
34
34
|
else
|
35
35
|
result.push(
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
status: reponse[0],
|
37
|
+
body: {},
|
38
|
+
'content-type': ''
|
39
39
|
)
|
40
40
|
end
|
41
41
|
end
|
@@ -43,36 +43,33 @@ module Tomograph
|
|
43
43
|
|
44
44
|
def schema(sche, defi)
|
45
45
|
if sche.keys.include?('$ref')
|
46
|
-
res = sche.merge('definitions' => {sche[
|
47
|
-
if defi[sche[
|
48
|
-
keys = defi[sche[
|
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
49
|
keys.each do |key|
|
50
|
-
res[
|
50
|
+
res['definitions'].merge!({ key[14..-1] => defi[key[14..-1]] })
|
51
51
|
end
|
52
52
|
end
|
53
53
|
res
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
res["definitions"].merge!({key[14..-1] => defi[key[14..-1]]})
|
60
|
-
end
|
61
|
-
res
|
62
|
-
else
|
63
|
-
sche
|
54
|
+
elsif sche.to_s.include?('$ref')
|
55
|
+
res = sche.merge('definitions' => {})
|
56
|
+
keys = sche.to_s.split('"').find_all { |word| word.include?('definitions') }
|
57
|
+
keys.each do |key|
|
58
|
+
res['definitions'].merge!({ key[14..-1] => defi[key[14..-1]] })
|
64
59
|
end
|
60
|
+
res
|
61
|
+
else
|
62
|
+
sche
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
def search_hash(hash, key)
|
69
67
|
return hash[key] if hash.assoc(key)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
68
|
+
|
69
|
+
hash.delete_if { |_key, value| value.class != Hash }
|
70
|
+
new_hash = {}
|
71
|
+
hash.each_value { |values| new_hash.merge!(values) }
|
72
|
+
search_hash(new_hash, key) unless new_hash.empty?
|
76
73
|
end
|
77
74
|
|
78
75
|
def to_resources
|
@@ -5,44 +5,44 @@ module Tomograph
|
|
5
5
|
class OpenApi3
|
6
6
|
def initialize(prefix, openapi3_yaml_path)
|
7
7
|
@prefix = prefix
|
8
|
-
@documentation = YAML.
|
8
|
+
@documentation = YAML.safe_load(File.read(openapi3_yaml_path))
|
9
9
|
end
|
10
10
|
|
11
11
|
def to_tomogram
|
12
|
-
@tomogram ||= @documentation['paths'].
|
12
|
+
@tomogram ||= @documentation['paths'].each_with_object([]) do |action, result|
|
13
13
|
action[1].keys.each do |method|
|
14
14
|
result.push(Tomograph::Tomogram::Action.new(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
+
))
|
21
22
|
end
|
22
|
-
result
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def responses(resp, defi)
|
27
27
|
resp.inject([]) do |result, response|
|
28
|
-
if response[1]['content']
|
29
|
-
#TODO 403Forbidden
|
28
|
+
if response[1]['content'].nil?
|
29
|
+
# TODO: 403Forbidden
|
30
30
|
result.push(
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
status: response[0],
|
32
|
+
body: {},
|
33
|
+
'content-type': ''
|
34
34
|
)
|
35
35
|
elsif response[1]['content'].values[0]['schema']
|
36
36
|
result.push(
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
status: response[0],
|
38
|
+
body: schema(response[1]['content'].values[0]['schema'], defi),
|
39
|
+
'content-type': ''
|
40
40
|
)
|
41
41
|
else
|
42
42
|
result.push(
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
status: response[0],
|
44
|
+
body: {},
|
45
|
+
'content-type': ''
|
46
46
|
)
|
47
47
|
end
|
48
48
|
end
|
@@ -52,54 +52,51 @@ module Tomograph
|
|
52
52
|
if sche.keys.include?('$ref')
|
53
53
|
sche.merge!('components' => {})
|
54
54
|
sche['components'].merge!('schemas' => {})
|
55
|
-
sche['components']['schemas'].merge!({sche[
|
55
|
+
sche['components']['schemas'].merge!({ sche['$ref'][21..-1] => defi[sche['$ref'][21..-1]] })
|
56
56
|
|
57
|
-
if defi[sche[
|
58
|
-
keys = defi[sche[
|
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
59
|
keys.each do |key|
|
60
|
-
sche['components']['schemas'].merge!({key[21..-1] => defi[key[21..-1]]})
|
60
|
+
sche['components']['schemas'].merge!({ key[21..-1] => defi[key[21..-1]] })
|
61
61
|
|
62
|
-
|
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]]})
|
62
|
+
next unless defi[key[21..-1]].to_s.include?('$ref')
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
sche['components']['schemas'].merge!({ key3[21..-1] => defi[key3[21..-1]] })
|
71
|
-
end
|
72
|
-
end
|
64
|
+
keys2 = defi[key[21..-1]].to_s.split('"').find_all { |word| word.include?('#/components/schemas/') }
|
65
|
+
keys2.each do |key2|
|
66
|
+
sche['components']['schemas'].merge!({ key2[21..-1] => defi[key2[21..-1]] })
|
73
67
|
|
68
|
+
next unless defi[key2[21..-1]].to_s.include?('$ref')
|
69
|
+
|
70
|
+
keys3 = defi[key2[21..-1]].to_s.split('"')
|
71
|
+
.find_all { |word| word.include?('#/components/schemas/') }
|
72
|
+
.uniq
|
73
|
+
keys3.each do |key3|
|
74
|
+
sche['components']['schemas'].merge!({ key3[21..-1] => defi[key3[21..-1]] })
|
74
75
|
end
|
75
76
|
end
|
76
|
-
|
77
77
|
end
|
78
78
|
end
|
79
79
|
sche
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
res["definitions"].merge!({key[21..-1] => defi[key[21..-1]]})
|
87
|
-
end
|
88
|
-
res
|
89
|
-
else
|
90
|
-
sche
|
81
|
+
elsif sche.to_s.include?('$ref')
|
82
|
+
res = sche.merge('definitions' => {})
|
83
|
+
keys = sche.to_s.split('"').find_all { |word| word.include?('definitions') }
|
84
|
+
keys.each do |key|
|
85
|
+
res['definitions'].merge!({ key[21..-1] => defi[key[21..-1]] })
|
91
86
|
end
|
87
|
+
res
|
88
|
+
else
|
89
|
+
sche
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
95
93
|
def search_hash(hash, key)
|
96
94
|
return hash[key] if hash.assoc(key)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
95
|
+
|
96
|
+
hash.delete_if { |_key, value| value.class != Hash }
|
97
|
+
new_hash = {}
|
98
|
+
hash.each_value { |values| new_hash.merge!(values) }
|
99
|
+
search_hash(new_hash, key) unless new_hash.empty?
|
103
100
|
end
|
104
101
|
|
105
102
|
def to_resources
|
data/lib/tomograph/path.rb
CHANGED
data/lib/tomograph/tomogram.rb
CHANGED
@@ -10,7 +10,12 @@ module Tomograph
|
|
10
10
|
class Tomogram
|
11
11
|
extend Gem::Deprecate
|
12
12
|
|
13
|
-
def initialize(prefix: '',
|
13
|
+
def initialize(prefix: '',
|
14
|
+
drafter_yaml_path: nil,
|
15
|
+
tomogram_json_path: nil,
|
16
|
+
crafter_yaml_path: nil,
|
17
|
+
openapi2_json_path: nil,
|
18
|
+
openapi3_yaml_path: nil)
|
14
19
|
@documentation = if tomogram_json_path
|
15
20
|
Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path)
|
16
21
|
elsif crafter_yaml_path
|
@@ -29,7 +34,7 @@ module Tomograph
|
|
29
34
|
@actions ||= @documentation.to_tomogram
|
30
35
|
end
|
31
36
|
|
32
|
-
def to_json
|
37
|
+
def to_json(*_args)
|
33
38
|
JSON.pretty_generate(to_a.map(&:to_hash))
|
34
39
|
end
|
35
40
|
|
data/lib/tomograph/version.rb
CHANGED
data/tomograph.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path('
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'tomograph/version'
|
4
4
|
|
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'methadone', '~> 2', '>= 2.0.2'
|
22
22
|
spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.1'
|
23
|
+
spec.add_development_dependency 'json-schema', '~> 2.8', '>= 2.8.1'
|
23
24
|
spec.add_development_dependency 'rake', '>= 13.0.1'
|
24
25
|
spec.add_development_dependency 'rspec', '~> 3.10', '>= 3.10.0'
|
25
26
|
spec.add_development_dependency 'rubocop', '~> 0.81', '>= 0.81.0'
|
26
27
|
spec.add_development_dependency 'simplecov', '~> 0.21', '>= 0.21.2'
|
27
|
-
spec.add_development_dependency 'json-schema', '~> 2.8', '>= 2.8.1'
|
28
28
|
spec.required_ruby_version = '>= 2.4.0'
|
29
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.1.
|
4
|
+
version: 3.1.3
|
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: 2021-09
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: methadone
|
@@ -50,6 +50,26 @@ dependencies:
|
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: 11.1.1
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: json-schema
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '2.8'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.8.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.8'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 2.8.1
|
53
73
|
- !ruby/object:Gem::Dependency
|
54
74
|
name: rake
|
55
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,26 +144,6 @@ dependencies:
|
|
124
144
|
- - ">="
|
125
145
|
- !ruby/object:Gem::Version
|
126
146
|
version: 0.21.2
|
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
|
147
147
|
description: Convert API Blueprint, Swagger and OpenAPI to routes and JSON-Schemas
|
148
148
|
email:
|
149
149
|
- d.efimov@fun-box.ru
|
@@ -184,7 +184,7 @@ homepage: https://github.com/funbox/tomograph
|
|
184
184
|
licenses:
|
185
185
|
- MIT
|
186
186
|
metadata: {}
|
187
|
-
post_install_message:
|
187
|
+
post_install_message:
|
188
188
|
rdoc_options: []
|
189
189
|
require_paths:
|
190
190
|
- lib
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
version: '0'
|
201
201
|
requirements: []
|
202
202
|
rubygems_version: 3.1.2
|
203
|
-
signing_key:
|
203
|
+
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Convert API Blueprint, Swagger and OpenAPI to Tomogram
|
206
206
|
test_files: []
|