tomograph 2.5.0 → 3.0.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
- SHA1:
3
- metadata.gz: 937a82ea94c38bdfbb1a92a6710936c7d525e228
4
- data.tar.gz: 33cf0b7e2a4643acf32175e22c9ade017e3db49d
2
+ SHA256:
3
+ metadata.gz: c457270d6d9ab0b7d23c4af643248636f3fe9b3f673858700505ab55ee31716f
4
+ data.tar.gz: d089a1f21d1ab2e739854f962eff9e0e7fcdc3cdb631a595f84a328afc016823
5
5
  SHA512:
6
- metadata.gz: a88be0b668cce03d6c6b2a13fca948bc620cd92c21936de32189db078f1872fe67b1a63c7a3e93da3352d9eeee755583f2406aac92691e268676dff65b6ac050
7
- data.tar.gz: 9d07f3e96dfd6ba0c7075682c048719072c2cb6c3df22754703de42371f3bc5c6bed63af18c069076f0d80ca47f82dc3221db3d8e4c45064ec0607d4e5954a4d
6
+ metadata.gz: 4f31296ba8532f93e0f89f881e0c0aa07a3a2a2752d2f6764be9ac6bf0ee5a8e1103b4f5bc2eb9b8ef0472f70432acaec379d2b914338fefed6f8e7c2842f3d3
7
+ data.tar.gz: b54f9a273905b2e7d3bd2d91777f46fc5c626dec43124abf6a3b5fed85a63e3ec63e21568498e6f072ab48020a58e6c833ab89a2ef7bf2692acc184c614cb6d4
@@ -0,0 +1,28 @@
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
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}}
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.7
3
3
 
4
4
  Metrics/LineLength:
5
5
  Max: 120
@@ -1 +1 @@
1
- 2.2.10
1
+ 2.7.1
@@ -0,0 +1,2 @@
1
+ ruby 2.7.1
2
+ nodejs 11.3.0
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- before_install: gem install bundler -v 1.12
5
-
3
+ - 2.4
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
@@ -1,6 +1,35 @@
1
1
  # Change log
2
2
 
3
- ### 2.5.0 - 2018-05-28
3
+ ### 3.0.0 - 2020-08-27
4
+
5
+ * features
6
+ * support multi request for one resource path [#27](https://github.com/funbox/tomograph/issues/27)
7
+ * removed
8
+ * delete support drafter 3 [#29](https://github.com/funbox/tomograph/issues/29)
9
+
10
+ ### 2.5.4 - 2020-04-06
11
+
12
+ * fixed warnings on ruby 2.7
13
+ * updated dependences
14
+
15
+ # Change log
16
+
17
+ ### 2.5.3 - 2020-03-10
18
+
19
+ * bug fixes
20
+ * fix parser status to string
21
+
22
+ ### 2.5.2 - 2020-01-10
23
+
24
+ * bug fixes
25
+ * fix parser for new crafter version
26
+
27
+ ### 2.5.1 - 2019-12-09
28
+
29
+ * bug fixes
30
+ * fix content_type parsing.
31
+
32
+ ### 2.5.0 - 2019-05-28
4
33
 
5
34
  * features
6
35
  * аdded support for documents with pre-parsed by drafter 4.
data/README.md CHANGED
@@ -1,194 +1,210 @@
1
- # Tomograph [![Build Status](https://travis-ci.org/funbox/tomograph.svg?branch=master)](https://travis-ci.org/funbox/tomograph) [![Gem Version](https://badge.fury.io/rb/tomograph.svg)](https://badge.fury.io/rb/tomograph)
1
+ # Tomograph
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>
3
+ [![Build Status](https://travis-ci.org/funbox/tomograph.svg?branch=master)](https://travis-ci.org/funbox/tomograph) [![Gem Version](https://badge.fury.io/rb/tomograph.svg)](https://badge.fury.io/rb/tomograph)
6
4
 
7
5
  Convert API Blueprint to JSON Schema and search.
8
6
 
9
7
  ## Installation
10
8
 
11
- Add this line to your application's Gemfile:
9
+ First you need to install [drafter](https://github.com/apiaryio/drafter).
10
+
11
+ Then add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
14
  gem 'tomograph'
15
15
  ```
16
16
 
17
- And then execute:
17
+ After that execute:
18
18
 
19
- $ bundle
19
+ ```bash
20
+ $ bundle
21
+ ```
20
22
 
21
- Or install it yourself as:
23
+ Or install the gem by yourself:
22
24
 
23
- $ gem install tomograph
25
+ ```bash
26
+ $ gem install tomograph
27
+ ```
24
28
 
25
29
  ## Usage
26
30
 
27
31
  ```ruby
28
32
  require 'tomograph'
29
- ```
30
33
 
31
- ```ruby
32
34
  tomogram = Tomograph::Tomogram.new(apib_path: '/path/to/doc.apib')
33
35
  ```
34
36
 
35
37
  ### Command line tool
36
38
 
37
- The command line tool allows you to convert files from API Blueprint or API Elements to JSON Schema.
38
- ```
39
+ CLI allows you to convert files from API Blueprint or API Elements to JSON Schema.
40
+
41
+ ```bash
39
42
  tomograph doc.apib doc.json
40
43
  ```
41
- Now there is support for documents pre-parsed by [drafter](https://github.com/apiaryio/drafter) versions 3 and 4. To select the handler version, use the -d key and specify the required version. For example:
42
- ```
44
+
45
+ There is also support for documents pre-parsed by [drafter](https://github.com/apiaryio/drafter) versions 3 and 4, or `crafter`.
46
+ To specify the handler version use the `-d` flag:
47
+
48
+ ```bash
43
49
  tomograph -d 4 doc_by_drafter4.yaml doc.json
44
50
  ```
45
- See
46
- ```
51
+
52
+ Run CLI with `-h` to get detailed help:
53
+
54
+ ```bash
47
55
  tomograph -h
48
56
  ```
49
- for more details on usage.
50
57
 
51
58
  ## Convert
52
59
 
60
+ Use `to_json` for converting APIB to JSON:
61
+
53
62
  ```ruby
54
63
  tomogram.to_json
55
64
  ```
56
65
 
57
- Example input:
58
- ```apib
59
- FORMAT: 1A
60
- HOST: http://test.local
61
-
62
- # project
63
-
64
- # Group project
65
-
66
- Project
67
-
68
- ## Authentication [/sessions]
69
-
70
- ### Sign In [POST]
71
-
72
- + Request (application/json)
73
-
74
- + Attributes
75
- + login (string, required)
76
- + password (string, required)
77
- + captcha (string, optional)
78
-
79
- + Response 401 (application/json)
80
-
81
- + Response 429 (application/json)
82
-
83
- + Response 201 (application/json)
84
-
85
- + Attributes
86
- + confirmation (Confirmation, optional)
87
- + captcha (string, optional)
88
- + captcha_does_not_match (boolean, optional)
89
-
90
-
91
- # Data Structures
92
-
93
- ## Confirmation (object)
94
- + id (string, required)
95
- + type (string, required)
96
- + operation (string, required)
97
- ```
98
-
99
- Example output:
100
- ```json
101
- [
102
- {
103
- "path": "/sessions",
104
- "method": "POST",
105
- "content-type": "application/json",
106
- "request": {
107
- "$schema": "http://json-schema.org/draft-04/schema#",
108
- "type": "object",
109
- "properties": {
110
- "login": {
111
- "type": "string"
66
+ <details>
67
+ <summary>Example input</summary>
68
+
69
+ ```apib
70
+ FORMAT: 1A
71
+ HOST: http://test.local
72
+
73
+ # project
74
+
75
+ # Group project
76
+
77
+ Project
78
+
79
+ ## Authentication [/sessions]
80
+
81
+ ### Sign In [POST]
82
+
83
+ + Request (application/json)
84
+
85
+ + Attributes
86
+ + login (string, required)
87
+ + password (string, required)
88
+ + captcha (string, optional)
89
+
90
+ + Response 401 (application/json)
91
+
92
+ + Response 429 (application/json)
93
+
94
+ + Response 201 (application/json)
95
+
96
+ + Attributes
97
+ + confirmation (Confirmation, optional)
98
+ + captcha (string, optional)
99
+ + captcha_does_not_match (boolean, optional)
100
+
101
+
102
+ # Data Structures
103
+
104
+ ## Confirmation (object)
105
+ + id (string, required)
106
+ + type (string, required)
107
+ + operation (string, required)
108
+ ```
109
+ </details>
110
+
111
+ <details>
112
+ <summary>Example output</summary>
113
+
114
+ ```json
115
+ [
116
+ {
117
+ "path": "/sessions",
118
+ "method": "POST",
119
+ "content-type": "application/json",
120
+ "requests": [{
121
+ "$schema": "http://json-schema.org/draft-04/schema#",
122
+ "type": "object",
123
+ "properties": {
124
+ "login": {
125
+ "type": "string"
126
+ },
127
+ "password": {
128
+ "type": "string"
129
+ },
130
+ "captcha": {
131
+ "type": "string"
132
+ }
112
133
  },
113
- "password": {
114
- "type": "string"
134
+ "required": [
135
+ "login",
136
+ "password"
137
+ ]
138
+ }],
139
+ "responses": [
140
+ {
141
+ "status": "401",
142
+ "content-type": "application/json",
143
+ "body": {}
115
144
  },
116
- "captcha": {
117
- "type": "string"
118
- }
119
- },
120
- "required": [
121
- "login",
122
- "password"
123
- ]
124
- },
125
- "responses": [
126
- {
127
- "status": "401",
128
- "content-type": "application/json",
129
- "body": {}
130
- },
131
- {
132
- "status": "429",
133
- "content-type": "application/json",
134
- "body": {}
135
- },
136
- {
137
- "status": "201",
138
- "content-type": "application/json",
139
- "body": {
140
- "$schema": "http://json-schema.org/draft-04/schema#",
141
- "type": "object",
142
- "properties": {
143
- "confirmation": {
144
- "type": "object",
145
- "properties": {
146
- "id": {
147
- "type": "string"
148
- },
149
- "type": {
150
- "type": "string"
145
+ {
146
+ "status": "429",
147
+ "content-type": "application/json",
148
+ "body": {}
149
+ },
150
+ {
151
+ "status": "201",
152
+ "content-type": "application/json",
153
+ "body": {
154
+ "$schema": "http://json-schema.org/draft-04/schema#",
155
+ "type": "object",
156
+ "properties": {
157
+ "confirmation": {
158
+ "type": "object",
159
+ "properties": {
160
+ "id": {
161
+ "type": "string"
162
+ },
163
+ "type": {
164
+ "type": "string"
165
+ },
166
+ "operation": {
167
+ "type": "string"
168
+ }
151
169
  },
152
- "operation": {
153
- "type": "string"
154
- }
170
+ "required": [
171
+ "id",
172
+ "type",
173
+ "operation"
174
+ ]
155
175
  },
156
- "required": [
157
- "id",
158
- "type",
159
- "operation"
160
- ]
161
- },
162
- "captcha": {
163
- "type": "string"
164
- },
165
- "captcha_does_not_match": {
166
- "type": "boolean"
176
+ "captcha": {
177
+ "type": "string"
178
+ },
179
+ "captcha_does_not_match": {
180
+ "type": "boolean"
181
+ }
167
182
  }
168
183
  }
169
184
  }
170
- }
171
- ]
172
- }
173
- ]
174
- ```
185
+ ]
186
+ }
187
+ ]
188
+ ```
189
+ </details>
175
190
 
176
191
  ## Search
177
192
 
178
- ### find_request
193
+ Use these methods to search through parsed API Blueprint spec to get request => responses hash maps.
194
+
195
+ ### `find_request`
179
196
 
180
197
  ```ruby
181
198
  request = tomogram.find_request(method: 'GET', path: '/status/1?qwe=rty')
182
199
  ```
183
200
 
184
- ### find_request
201
+ ### `find_request_with_content_type`
185
202
 
186
203
  ```ruby
187
204
  request = tomogram.find_request_with_content_type(method: 'GET', path: '/status/1?qwe=rty', content_type: 'application/json')
188
205
  ```
189
206
 
190
- ### find_responses
191
-
207
+ ### `find_responses`
192
208
 
193
209
  ```ruby
194
210
  responses = request.find_responses(status: '200')
@@ -196,64 +212,70 @@ responses = request.find_responses(status: '200')
196
212
 
197
213
  ## Other methods
198
214
 
199
- ### prefix_match?
215
+ ### `prefix_match?`
200
216
 
201
- This can be useful if you use a prefix.
217
+ This may be useful if you specify a prefix.
202
218
 
203
219
  ```ruby
204
220
  tomogram.prefix_match?('http://local/api/v2/users')
205
221
  ```
206
222
 
207
- ## Params
223
+ ### `to_resources`
208
224
 
209
- Example:
225
+ Maps resources with possible requests.
226
+
227
+ Example output:
210
228
 
211
229
  ```ruby
212
- Tomograph::Tomogram.new(prefix: '/api/v2', apib_path: '/path/to/doc.apib')
230
+ {
231
+ '/sessions' => ['POST /sessions']
232
+ }
213
233
  ```
214
234
 
215
- or
235
+ ## Constructor params
236
+
237
+ You can specify API prefix and path to the spec using one of the possible formats:
216
238
 
217
239
  ```ruby
218
- Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
240
+ Tomograph::Tomogram.new(prefix: '/api/v2', apib_path: '/path/to/doc.apib')
219
241
  ```
220
242
 
221
- or
243
+ ```ruby
244
+ Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
245
+ ```
222
246
 
223
247
  ```ruby
224
248
  Tomograph::Tomogram.new(prefix: '/api/v2', tomogram_json_path: '/path/to/doc.json')
225
249
  ```
226
250
 
227
- ### apib_path
251
+ ### `apib_path`
228
252
 
229
253
  Path to API Blueprint documentation. There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
230
254
 
231
- ### drafter_yaml_path
255
+ ### `drafter_yaml_path`
232
256
 
233
257
  Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
234
258
 
235
- Drafter v.4
259
+ ### Drafter v4 & Crafter support
236
260
 
237
- If you are using a `drafter v.4`, then you need to use the following parameters`drafter_4_apib_path` and `drafter_4_yaml_path` respectively.
261
+ If you are using a `drafter v4`, you should use `drafter_4_apib_path` and `drafter_4_yaml_path` respectively.
238
262
 
239
- ### tomogram_json_path
263
+ In case when you want to use `сrafter`, then you should pass these params: `crafter_apib_path`, `crafter_yaml_path`.
264
+
265
+ ### `tomogram_json_path`
240
266
 
241
267
  Path to API Blueprint documentation converted with `tomograph` to a JSON file.
242
268
 
243
- ### prefix
269
+ ### `prefix`
244
270
 
245
- Default empty String. Prefix of API requests. Example: `'/api'`.
271
+ Default: `''`
246
272
 
247
- ### to_resources
273
+ Prefix for API requests.
248
274
 
249
- Hash resource with requests.
250
- The result for the example above:
251
- ```ruby
252
- {
253
- '/sessions' => ['POST /sessions']
254
- }
255
- ```
275
+ Example: `'/api'`.
256
276
 
257
277
  ## License
258
278
 
259
279
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
280
+
281
+ [![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)
@@ -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, 3 or 4. Default: use drafter v.3.')
15
+ on('-d DRAFTER_VERSION', '--drafter', 'Choose drafter version: crafter or 4. Default: use drafter v.4.')
16
16
  on('-f INPUT_FORMAT', '--format', 'Force input format: "apib" or "yaml". Default: detect by file extension.')
17
17
  on('--exclude-description', 'Exclude "description" keys.')
18
18
  on('--split', 'Split output into files by method.')
@@ -52,12 +52,10 @@ def choose_drafter(opt_parser)
52
52
  case opt_parser
53
53
  when 'crafter'
54
54
  :crafter
55
- when '3'
56
- :drafter_3
57
55
  when '4'
58
56
  :drafter_4
59
57
  when nil
60
- :drafter_3
58
+ :drafter_4
61
59
  else
62
60
  raise 'Unsupported drafter version!'
63
61
  end
@@ -88,17 +86,13 @@ main do |input, output|
88
86
  version = choose_drafter(options['drafter'])
89
87
  format_key = case format
90
88
  when :apib
91
- if version == :drafter_3
92
- :apib_path
93
- elsif version == :crafter
89
+ if version == :crafter
94
90
  :crafter_apib_path
95
91
  else
96
92
  :drafter_4_apib_path
97
93
  end
98
94
  when :yaml
99
- if version == :drafter_3
100
- :drafter_yaml_path
101
- elsif version == :crafter
95
+ if version == :crafter
102
96
  :crafter_yaml_path
103
97
  else
104
98
  :drafter_4_yaml_path
@@ -29,7 +29,7 @@ module Tomograph
29
29
  def group?(group)
30
30
  return false if group['element'] == 'resource'
31
31
  group['element'] != 'copy' && # Element is a human readable text
32
- group['meta']['classes'][0] == 'resourceGroup' # skip Data Structures
32
+ group['meta']['classes']['content'][0]['content'] == 'resourceGroup' # skip Data Structures
33
33
  end
34
34
 
35
35
  def resources
@@ -101,15 +101,15 @@ module Tomograph
101
101
  path: "#{@prefix}#{related_actions.first.path}",
102
102
  method: related_actions.first.method,
103
103
  content_type: related_actions.first.content_type,
104
- request: related_actions.first.request,
105
- responses: related_actions.map(&:responses).flatten,
104
+ requests: related_actions.map(&:request).flatten.uniq,
105
+ responses: related_actions.map(&:responses).flatten.uniq,
106
106
  resource: related_actions.first.resource
107
107
  }
108
108
  end
109
109
 
110
110
  def to_tomogram
111
111
  @tomogram ||= actions.inject([]) do |result, action|
112
- result.push(Tomograph::Tomogram::Action.new(action))
112
+ result.push(Tomograph::Tomogram::Action.new(**action))
113
113
  end
114
114
  end
115
115
 
@@ -18,8 +18,10 @@ module Tomograph
18
18
  end
19
19
 
20
20
  def content_type
21
- @content_type ||= @content.first['attributes'].has_key?('headers') ?
22
- @content.first['attributes']['headers']['content'][0]['content']['value']['content'] : nil
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
23
25
  end
24
26
 
25
27
  def request
@@ -49,7 +51,7 @@ module Tomograph
49
51
  end
50
52
  @responses = @responses.map do |response|
51
53
  {
52
- 'status' => response['attributes']['statusCode']['content'],
54
+ 'status' => response['attributes']['statusCode']['content'].to_s,
53
55
  'body' => json_schema(response['content']),
54
56
  'content-type' => response['attributes'].has_key?('headers') ?
55
57
  response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
@@ -101,15 +101,15 @@ module Tomograph
101
101
  path: "#{@prefix}#{related_actions.first.path}",
102
102
  method: related_actions.first.method,
103
103
  content_type: related_actions.first.content_type,
104
- request: related_actions.first.request,
105
- responses: related_actions.map(&:responses).flatten,
104
+ requests: related_actions.map(&:request).flatten.uniq,
105
+ responses: related_actions.map(&:responses).flatten.uniq,
106
106
  resource: related_actions.first.resource
107
107
  }
108
108
  end
109
109
 
110
110
  def to_tomogram
111
111
  @tomogram ||= actions.inject([]) do |result, action|
112
- result.push(Tomograph::Tomogram::Action.new(action))
112
+ result.push(Tomograph::Tomogram::Action.new(**action))
113
113
  end
114
114
  end
115
115
 
@@ -18,8 +18,10 @@ module Tomograph
18
18
  end
19
19
 
20
20
  def content_type
21
- @content_type ||= @content.first['attributes'].has_key?('headers') ?
22
- @content.first['attributes']['headers']['content'][0]['content']['value']['content'] : nil
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
23
25
  end
24
26
 
25
27
  def request
@@ -49,7 +51,7 @@ module Tomograph
49
51
  end
50
52
  @responses = @responses.map do |response|
51
53
  {
52
- 'status' => response['attributes']['statusCode']['content'],
54
+ 'status' => response['attributes']['statusCode']['content'].to_s,
53
55
  'body' => json_schema(response['content']),
54
56
  'content-type' => response['attributes'].has_key?('headers') ?
55
57
  response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
@@ -14,7 +14,7 @@ module Tomograph
14
14
  path: "#{@prefix}#{action['path']}",
15
15
  method: action['method'],
16
16
  content_type: action['content-type'],
17
- request: action['request'],
17
+ requests: action['requests'],
18
18
  responses: action['responses'],
19
19
  resource: action['resource']))
20
20
  end
@@ -1,7 +1,6 @@
1
1
  require 'multi_json'
2
2
  require 'tomograph/path'
3
3
  require 'tomograph/api_blueprint/json_schema'
4
- require 'tomograph/api_blueprint/drafter_3/yaml'
5
4
  require 'tomograph/api_blueprint/drafter_4/yaml'
6
5
  require 'tomograph/api_blueprint/crafter/yaml'
7
6
 
@@ -12,12 +11,10 @@ module Tomograph
12
11
  def initialize(prefix: '', apib_path: nil, drafter_yaml_path: nil, tomogram_json_path: nil, drafter_4_apib_path: nil, drafter_4_yaml_path: nil, crafter_apib_path: nil, crafter_yaml_path: nil)
13
12
  @documentation = if tomogram_json_path
14
13
  Tomograph::ApiBlueprint::JsonSchema.new(prefix, tomogram_json_path)
15
- elsif drafter_4_yaml_path || drafter_4_apib_path
16
- Tomograph::ApiBlueprint::Drafter4::Yaml.new(prefix, drafter_4_apib_path, drafter_4_yaml_path)
17
14
  elsif crafter_yaml_path || crafter_apib_path
18
15
  Tomograph::ApiBlueprint::Crafter::Yaml.new(prefix, crafter_apib_path, crafter_yaml_path)
19
16
  else
20
- Tomograph::ApiBlueprint::Drafter3::Yaml.new(prefix, apib_path, drafter_yaml_path)
17
+ Tomograph::ApiBlueprint::Drafter4::Yaml.new(prefix, drafter_4_apib_path, drafter_4_yaml_path)
21
18
  end
22
19
  @prefix = prefix
23
20
  end
@@ -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.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -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', '~> 10.0'
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_runtime_dependency 'multi_json', '~> 1.14', '>= 1.14.1'
23
+ spec.add_development_dependency 'byebug', '~> 11.1', '>= 11.1.1'
24
+ spec.add_development_dependency 'rake', '>= 13.0.1'
25
+ spec.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.81', '>= 0.81.0'
27
+ spec.add_development_dependency 'simplecov', '~> 0.18', '>= 0.18.5'
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.0
4
+ version: 3.0.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: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2020-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -16,148 +16,134 @@ 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
34
  name: multi_json
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.11'
39
+ version: '1.14'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.11.1
42
+ version: 1.14.1
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: '1.14'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.11.1
53
- - !ruby/object:Gem::Dependency
54
- name: bundler
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.12'
60
- type: :development
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '1.12'
52
+ version: 1.14.1
67
53
  - !ruby/object:Gem::Dependency
68
54
  name: byebug
69
55
  requirement: !ruby/object:Gem::Requirement
70
56
  requirements:
71
57
  - - "~>"
72
58
  - !ruby/object:Gem::Version
73
- version: '8.2'
59
+ version: '11.1'
74
60
  - - ">="
75
61
  - !ruby/object:Gem::Version
76
- version: 8.2.1
62
+ version: 11.1.1
77
63
  type: :development
78
64
  prerelease: false
79
65
  version_requirements: !ruby/object:Gem::Requirement
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: '8.2'
69
+ version: '11.1'
84
70
  - - ">="
85
71
  - !ruby/object:Gem::Version
86
- version: 8.2.1
72
+ version: 11.1.1
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: '10.0'
79
+ version: 13.0.1
94
80
  type: :development
95
81
  prerelease: false
96
82
  version_requirements: !ruby/object:Gem::Requirement
97
83
  requirements:
98
- - - "~>"
84
+ - - ">="
99
85
  - !ruby/object:Gem::Version
100
- version: '10.0'
86
+ version: 13.0.1
101
87
  - !ruby/object:Gem::Dependency
102
88
  name: rspec
103
89
  requirement: !ruby/object:Gem::Requirement
104
90
  requirements:
105
91
  - - "~>"
106
92
  - !ruby/object:Gem::Version
107
- version: '3.4'
93
+ version: '3.9'
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: 3.4.0
96
+ version: 3.9.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: '3.9'
118
104
  - - ">="
119
105
  - !ruby/object:Gem::Version
120
- version: 3.4.0
106
+ version: 3.9.0
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.52.1
113
+ version: '0.81'
128
114
  - - ">="
129
115
  - !ruby/object:Gem::Version
130
- version: 0.52.1
116
+ version: 0.81.0
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.81'
138
124
  - - ">="
139
125
  - !ruby/object:Gem::Version
140
- version: 0.52.1
126
+ version: 0.81.0
141
127
  - !ruby/object:Gem::Dependency
142
128
  name: simplecov
143
129
  requirement: !ruby/object:Gem::Requirement
144
130
  requirements:
145
131
  - - "~>"
146
132
  - !ruby/object:Gem::Version
147
- version: '0.11'
133
+ version: '0.18'
148
134
  - - ">="
149
135
  - !ruby/object:Gem::Version
150
- version: 0.11.2
136
+ version: 0.18.5
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: '0.18'
158
144
  - - ">="
159
145
  - !ruby/object:Gem::Version
160
- version: 0.11.2
146
+ version: 0.18.5
161
147
  description: Convert API Blueprint to routes and JSON-Schemas
162
148
  email:
163
149
  - d.efimov@fun-box.ru
@@ -166,9 +152,11 @@ executables:
166
152
  extensions: []
167
153
  extra_rdoc_files: []
168
154
  files:
155
+ - ".github/workflows/gempush.yml"
169
156
  - ".gitignore"
170
157
  - ".rubocop.yml"
171
158
  - ".ruby-version"
159
+ - ".tool-versions"
172
160
  - ".travis.yml"
173
161
  - CHANGELOG.md
174
162
  - CODE_OF_CONDUCT.md
@@ -182,8 +170,6 @@ files:
182
170
  - lib/tomograph.rb
183
171
  - lib/tomograph/api_blueprint/crafter/yaml.rb
184
172
  - lib/tomograph/api_blueprint/crafter/yaml/action.rb
185
- - lib/tomograph/api_blueprint/drafter_3/yaml.rb
186
- - lib/tomograph/api_blueprint/drafter_3/yaml/action.rb
187
173
  - lib/tomograph/api_blueprint/drafter_4/yaml.rb
188
174
  - lib/tomograph/api_blueprint/drafter_4/yaml/action.rb
189
175
  - lib/tomograph/api_blueprint/json_schema.rb
@@ -205,15 +191,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
191
  requirements:
206
192
  - - ">="
207
193
  - !ruby/object:Gem::Version
208
- version: '0'
194
+ version: 2.4.0
209
195
  required_rubygems_version: !ruby/object:Gem::Requirement
210
196
  requirements:
211
197
  - - ">="
212
198
  - !ruby/object:Gem::Version
213
199
  version: '0'
214
200
  requirements: []
215
- rubyforge_project:
216
- rubygems_version: 2.4.5.5
201
+ rubygems_version: 3.1.2
217
202
  signing_key:
218
203
  specification_version: 4
219
204
  summary: Convert API Blueprint to Tomogram
@@ -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,63 +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
- @content_type ||= @content.first['attributes'].has_key?('headers') ?
22
- @content.first['attributes']['headers']['content'][0]['content']['value']['content'] : nil
23
- end
24
-
25
- def request
26
- return @request if @request
27
-
28
- request_action = @content.find { |el| el['element'] == 'httpRequest' }
29
- @request = json_schema(request_action['content'])
30
- end
31
-
32
- def json_schema(actions)
33
- schema_node = actions.find do |action|
34
- action && action['element'] == 'asset' && action['attributes']['contentType'] == 'application/schema+json'
35
- end
36
- return {} unless schema_node
37
-
38
- MultiJson.load(schema_node['content'])
39
- rescue MultiJson::ParseError => e
40
- puts "[Tomograph] Error while parsing #{e}. skipping..."
41
- {}
42
- end
43
-
44
- def responses
45
- return @responses if @responses
46
-
47
- @responses = @content.select do |response|
48
- response['element'] == 'httpResponse' && response['attributes']
49
- end
50
- @responses = @responses.map do |response|
51
- {
52
- 'status' => response['attributes']['statusCode'],
53
- 'body' => json_schema(response['content']),
54
- 'content-type' => response['attributes'].has_key?('headers') ?
55
- response['attributes']['headers']['content'][0]['content']['value']['content'] : nil
56
- }
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end