tomograph 2.5.3 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,13 @@ require 'tomograph/path'
3
3
  module Tomograph
4
4
  class Tomogram
5
5
  class Action
6
- attr_reader :path, :method, :content_type, :request, :responses, :resource
6
+ attr_reader :path, :method, :content_type, :requests, :responses, :resource
7
7
 
8
- def initialize(path:, method:, content_type:, request:, responses:, resource:)
8
+ def initialize(path:, method:, content_type:, requests:, responses:, resource:)
9
9
  @path ||= Tomograph::Path.new(path)
10
10
  @method ||= method
11
11
  @content_type ||= content_type
12
- @request ||= request
12
+ @requests ||= requests
13
13
  @responses ||= responses
14
14
  @resource ||= resource
15
15
  end
@@ -25,7 +25,7 @@ module Tomograph
25
25
  'path' => path,
26
26
  'method' => method,
27
27
  'content-type' => content_type,
28
- 'request' => request,
28
+ 'requests' => requests,
29
29
  'responses' => responses,
30
30
  'resource' => resource
31
31
  }
@@ -1,3 +1,3 @@
1
1
  module Tomograph
2
- VERSION = '2.5.3'.freeze
2
+ VERSION = '3.1.1'.freeze
3
3
  end
data/tomograph.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['d.efimov']
9
9
  spec.email = ['d.efimov@fun-box.ru']
10
10
 
11
- spec.summary = 'Convert API Blueprint to Tomogram'
12
- spec.description = 'Convert API Blueprint to routes and JSON-Schemas'
11
+ spec.summary = 'Convert API Blueprint, Swagger and OpenAPI to Tomogram'
12
+ spec.description = 'Convert API Blueprint, Swagger and OpenAPI to routes and JSON-Schemas'
13
13
  spec.homepage = 'https://github.com/funbox/tomograph'
14
14
  spec.license = 'MIT'
15
15
 
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'methadone', '~> 1.9', '>= 1.9.5'
22
- spec.add_runtime_dependency 'multi_json', '~> 1.11', '>= 1.11.1'
23
- spec.add_development_dependency 'bundler', '~> 1.12'
24
- spec.add_development_dependency 'byebug', '~> 8.2', '>= 8.2.1'
25
- spec.add_development_dependency 'rake', '>= 12.3.3'
26
- spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
27
- spec.add_development_dependency 'rubocop', '~> 0.52.1', '>= 0.52.1'
28
- spec.add_development_dependency 'simplecov', '~> 0.11', '>= 0.11.2'
21
+ spec.add_runtime_dependency 'methadone', '~> 2', '>= 2.0.2'
22
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.1'
23
+ spec.add_development_dependency 'rake', '>= 13.0.1'
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.5'
27
+ spec.add_development_dependency 'json-schema', '~> 2.8', '>= 2.8.1'
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: 2.5.3
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - d.efimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -16,149 +16,135 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.9.5
22
+ version: 2.0.2
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '1.9'
29
+ version: '2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.9.5
32
+ version: 2.0.2
33
33
  - !ruby/object:Gem::Dependency
34
- name: multi_json
34
+ name: byebug
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.11'
39
+ version: '11.1'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.11.1
43
- type: :runtime
42
+ version: 11.1.1
43
+ type: :development
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: '11.1'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.11.1
52
+ version: 11.1.1
53
53
  - !ruby/object:Gem::Dependency
54
- name: bundler
54
+ name: rake
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
- version: '1.12'
59
+ version: 13.0.1
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - "~>"
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: '1.12'
66
+ version: 13.0.1
67
67
  - !ruby/object:Gem::Dependency
68
- name: byebug
68
+ name: rspec
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '8.2'
73
+ version: '3.9'
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 8.2.1
76
+ version: 3.9.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '8.2'
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 8.2.1
87
- - !ruby/object:Gem::Dependency
88
- name: rake
89
- requirement: !ruby/object:Gem::Requirement
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: 12.3.3
94
- type: :development
95
- prerelease: false
96
- version_requirements: !ruby/object:Gem::Requirement
97
- requirements:
83
+ version: '3.9'
98
84
  - - ">="
99
85
  - !ruby/object:Gem::Version
100
- version: 12.3.3
86
+ version: 3.9.0
101
87
  - !ruby/object:Gem::Dependency
102
- name: rspec
88
+ name: rubocop
103
89
  requirement: !ruby/object:Gem::Requirement
104
90
  requirements:
105
91
  - - "~>"
106
92
  - !ruby/object:Gem::Version
107
- version: '3.4'
93
+ version: '0.81'
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: 3.4.0
96
+ version: 0.81.0
111
97
  type: :development
112
98
  prerelease: false
113
99
  version_requirements: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: '3.4'
103
+ version: '0.81'
118
104
  - - ">="
119
105
  - !ruby/object:Gem::Version
120
- version: 3.4.0
106
+ version: 0.81.0
121
107
  - !ruby/object:Gem::Dependency
122
- name: rubocop
108
+ name: simplecov
123
109
  requirement: !ruby/object:Gem::Requirement
124
110
  requirements:
125
111
  - - "~>"
126
112
  - !ruby/object:Gem::Version
127
- version: 0.52.1
113
+ version: '0.18'
128
114
  - - ">="
129
115
  - !ruby/object:Gem::Version
130
- version: 0.52.1
116
+ version: 0.18.5
131
117
  type: :development
132
118
  prerelease: false
133
119
  version_requirements: !ruby/object:Gem::Requirement
134
120
  requirements:
135
121
  - - "~>"
136
122
  - !ruby/object:Gem::Version
137
- version: 0.52.1
123
+ version: '0.18'
138
124
  - - ">="
139
125
  - !ruby/object:Gem::Version
140
- version: 0.52.1
126
+ version: 0.18.5
141
127
  - !ruby/object:Gem::Dependency
142
- name: simplecov
128
+ name: json-schema
143
129
  requirement: !ruby/object:Gem::Requirement
144
130
  requirements:
145
131
  - - "~>"
146
132
  - !ruby/object:Gem::Version
147
- version: '0.11'
133
+ version: '2.8'
148
134
  - - ">="
149
135
  - !ruby/object:Gem::Version
150
- version: 0.11.2
136
+ version: 2.8.1
151
137
  type: :development
152
138
  prerelease: false
153
139
  version_requirements: !ruby/object:Gem::Requirement
154
140
  requirements:
155
141
  - - "~>"
156
142
  - !ruby/object:Gem::Version
157
- version: '0.11'
143
+ version: '2.8'
158
144
  - - ">="
159
145
  - !ruby/object:Gem::Version
160
- version: 0.11.2
161
- description: Convert API Blueprint to routes and JSON-Schemas
146
+ version: 2.8.1
147
+ description: Convert API Blueprint, Swagger and OpenAPI to routes and JSON-Schemas
162
148
  email:
163
149
  - d.efimov@fun-box.ru
164
150
  executables:
@@ -166,11 +152,11 @@ executables:
166
152
  extensions: []
167
153
  extra_rdoc_files: []
168
154
  files:
155
+ - ".github/workflows/ruby.yml"
169
156
  - ".gitignore"
170
157
  - ".rubocop.yml"
171
158
  - ".ruby-version"
172
159
  - ".tool-versions"
173
- - ".travis.yml"
174
160
  - CHANGELOG.md
175
161
  - CODE_OF_CONDUCT.md
176
162
  - Gemfile
@@ -183,11 +169,11 @@ files:
183
169
  - lib/tomograph.rb
184
170
  - lib/tomograph/api_blueprint/crafter/yaml.rb
185
171
  - lib/tomograph/api_blueprint/crafter/yaml/action.rb
186
- - lib/tomograph/api_blueprint/drafter_3/yaml.rb
187
- - lib/tomograph/api_blueprint/drafter_3/yaml/action.rb
188
172
  - lib/tomograph/api_blueprint/drafter_4/yaml.rb
189
173
  - lib/tomograph/api_blueprint/drafter_4/yaml/action.rb
190
174
  - lib/tomograph/api_blueprint/json_schema.rb
175
+ - lib/tomograph/openapi/openapi2.rb
176
+ - lib/tomograph/openapi/openapi3.rb
191
177
  - lib/tomograph/path.rb
192
178
  - lib/tomograph/tomogram.rb
193
179
  - lib/tomograph/tomogram/action.rb
@@ -206,16 +192,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
192
  requirements:
207
193
  - - ">="
208
194
  - !ruby/object:Gem::Version
209
- version: '0'
195
+ version: 2.4.0
210
196
  required_rubygems_version: !ruby/object:Gem::Requirement
211
197
  requirements:
212
198
  - - ">="
213
199
  - !ruby/object:Gem::Version
214
200
  version: '0'
215
201
  requirements: []
216
- rubyforge_project:
217
- rubygems_version: 2.4.5
202
+ rubygems_version: 3.1.2
218
203
  signing_key:
219
204
  specification_version: 4
220
- summary: Convert API Blueprint to Tomogram
205
+ summary: Convert API Blueprint, Swagger and OpenAPI to Tomogram
221
206
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2
4
- before_install: gem install bundler -v 1.12
5
-
@@ -1,128 +0,0 @@
1
- require 'yaml'
2
- require 'tomograph/api_blueprint/drafter_3/yaml/action'
3
- require 'tomograph/tomogram/action'
4
-
5
- module Tomograph
6
- module ApiBlueprint
7
- class Drafter3
8
- class Yaml
9
- def initialize(prefix, apib_path, drafter_yaml_path)
10
- @prefix = prefix
11
- @documentation = if apib_path
12
- YAML.safe_load(`drafter #{apib_path}`)
13
- elsif drafter_yaml_path
14
- YAML.safe_load(File.read(drafter_yaml_path))
15
- end
16
- end
17
-
18
- def groups
19
- @groups ||= @documentation['content'][0]['content'].inject([]) do |result_groups, group|
20
- next result_groups unless group?(group)
21
- result_groups.push(group)
22
- end
23
- end
24
-
25
- def group?(group)
26
- group['element'] != 'copy' && # Element is a human readable text
27
- group['meta']['classes'][0] == 'resourceGroup' # skip Data Structures
28
- end
29
-
30
- def resources
31
- @resources ||= groups.inject([]) do |result_groups, group|
32
- result_groups.push(group['content'].inject([]) do |result_resources, resource|
33
- next result_resources unless resource?(resource)
34
- result_resources.push('resource' => resource, 'resource_path' => resource_path(resource))
35
- end)
36
- end.flatten
37
- end
38
-
39
- def resource?(resource)
40
- resource['element'] != 'copy' # Element is a human readable text
41
- end
42
-
43
- def resource_path(resource)
44
- resource['attributes'] && resource['attributes']['href']
45
- end
46
-
47
- def transitions
48
- @transitions ||= resources.inject([]) do |result_resources, resource|
49
- result_resources.push(resource['resource']['content'].inject([]) do |result_transitions, transition|
50
- next result_transitions unless transition?(transition)
51
- result_transitions.push(transition_hash(transition, resource))
52
- end)
53
- end.flatten
54
- end
55
-
56
- def transition?(transition)
57
- transition['element'] == 'transition'
58
- end
59
-
60
- def transition_hash(transition, resource)
61
- {
62
- 'transition' => transition,
63
- 'transition_path' => transition_path(transition, resource['resource_path']),
64
- 'resource' => resource['resource_path']
65
- }
66
- end
67
-
68
- def transition_path(transition, resource_path)
69
- transition['attributes'] && transition['attributes']['href'] || resource_path
70
- end
71
-
72
- def without_group_actions
73
- transitions.inject([]) do |result_transition, transition|
74
- result_transition.push(transition['transition']['content'].inject([]) do |result_contents, content|
75
- next result_contents unless action?(content)
76
- result_contents.push(Tomograph::ApiBlueprint::Drafter3::Yaml::Action.new(
77
- content['content'],
78
- transition['transition_path'],
79
- transition['resource']
80
- ))
81
- end)
82
- end
83
- end
84
-
85
- def action?(content)
86
- content['element'] == 'httpTransaction'
87
- end
88
-
89
- def actions
90
- @actions ||= without_group_actions
91
- .flatten
92
- .group_by { |action| "#{action.method} #{action.path}" }.map do |_key, related_actions|
93
- action_hash(related_actions)
94
- end.flatten
95
- end
96
-
97
- def action_hash(related_actions)
98
- {
99
- path: "#{@prefix}#{related_actions.first.path}",
100
- method: related_actions.first.method,
101
- content_type: related_actions.first.content_type,
102
- request: related_actions.first.request,
103
- responses: related_actions.map(&:responses).flatten,
104
- resource: related_actions.first.resource
105
- }
106
- end
107
-
108
- def to_tomogram
109
- @tomogram ||= actions.inject([]) do |result, action|
110
- result.push(Tomograph::Tomogram::Action.new(action))
111
- end
112
- end
113
-
114
- def to_resources
115
- return @to_resources if @to_resources
116
-
117
- @to_resources = actions.group_by { |action| action[:resource] }
118
- @to_resources = @to_resources.inject({}) do |res, related_actions|
119
- requests = related_actions[1].map do |action|
120
- "#{action[:method]} #{action[:path]}"
121
- end
122
- res.merge(related_actions[1].first[:resource] => requests)
123
- end
124
- end
125
- end
126
- end
127
- end
128
- end
@@ -1,65 +0,0 @@
1
- require 'tomograph/tomogram/action'
2
-
3
- module Tomograph
4
- module ApiBlueprint
5
- class Drafter3
6
- class Yaml
7
- class Action
8
- def initialize(content, path, resource)
9
- @content = content
10
- @path = path
11
- @resource = resource
12
- end
13
-
14
- attr_reader :path, :resource
15
-
16
- def method
17
- @method ||= @content.first['attributes']['method']
18
- end
19
-
20
- def content_type
21
- if @content.first['attributes'].has_key?('headers')
22
- @content.first['attributes']['headers']['content'][0]['content']['key']['content'] == 'Content-Type' ?
23
- @content.first['attributes']['headers']['content'][0]['content']['value']['content'] : nil
24
- end
25
- end
26
-
27
- def request
28
- return @request if @request
29
-
30
- request_action = @content.find { |el| el['element'] == 'httpRequest' }
31
- @request = json_schema(request_action['content'])
32
- end
33
-
34
- def json_schema(actions)
35
- schema_node = actions.find do |action|
36
- action && action['element'] == 'asset' && action['attributes']['contentType'] == 'application/schema+json'
37
- end
38
- return {} unless schema_node
39
-
40
- MultiJson.load(schema_node['content'])
41
- rescue MultiJson::ParseError => e
42
- puts "[Tomograph] Error while parsing #{e}. skipping..."
43
- {}
44
- end
45
-
46
- def responses
47
- return @responses if @responses
48
-
49
- @responses = @content.select do |response|
50
- response['element'] == 'httpResponse' && response['attributes']
51
- end
52
- @responses = @responses.map do |response|
53
- {
54
- 'status' => response['attributes']['statusCode'].to_s,
55
- 'body' => json_schema(response['content']),
56
- 'content-type' => response['attributes'].has_key?('headers') ?
57
- response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
58
- }
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end