tomograph 2.5.3 → 3.1.1

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: 80116439a5a62eac61675d5d039f6b2887011fdd
4
- data.tar.gz: 0d2bd7231ebfa0a44496119ee36e9c9c80846988
2
+ SHA256:
3
+ metadata.gz: 2e5235f82fd9f87bbf895dd85eea58a1f78d9cab0d78be2a0f2f5a9554d7928f
4
+ data.tar.gz: e1bd1a93846659640ce4220079644d396522f9e3d392c93747391871de1eba63
5
5
  SHA512:
6
- metadata.gz: 2045a38046bffe45eb8904853bf4643e816c36914dcbb933ec870f8afe2b9a08407dc6d70b315acd14f5fe8e5e8a353d4685191b0e1c56d9cd286b722c7bf1f8
7
- data.tar.gz: 6f18b2f2e21d21e3613c7e7da4302fd3f6afe6a451e202966bee92b94198c3c494ca94983ae0a9971782e2e07cb29e57bb33c12286040c3a7cf57625b40acc4e
6
+ metadata.gz: 7fb24eb83a332bc7d543bd07869bee334c09582b3cc14e5f5f3bafd8ab6809c3e7bfddab4f44a534f640d61dfa41e47c5151d06eb0f7d40c0955106615c652dd
7
+ data.tar.gz: 9e24a40ae4174ce201a2d341821231fd3a6a79d90a2c213e7bb2d62ef84d5f71625b5e0643b94fac91d9b064462c7aed1507c236001c3cc3e6f767837907c8a5
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ uses: ruby/setup-ruby@v1
27
+ # uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
28
+ with:
29
+ ruby-version: 2.7
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -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
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.7.1
data/.tool-versions CHANGED
@@ -1,2 +1,2 @@
1
- ruby 2.2.0
1
+ ruby 2.7.1
2
2
  nodejs 11.3.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Change log
2
2
 
3
+ ### 3.1.1 - 2021-02-10
4
+
5
+ * setting
6
+ * improve gemspec summary and description
7
+
8
+ ### 3.1.0 - 2021-02-09
9
+
10
+ * features
11
+ * support Swagger/OpenAPI 2.0 [#47](https://github.com/funbox/tomograph/issues/47)
12
+ * support OpenAPI 3.0 [#50](https://github.com/funbox/tomograph/issues/50)
13
+ * removed
14
+ * delete travis [#45](https://github.com/funbox/tomograph/issues/45)
15
+
16
+ ### 3.0.1 - 2020-10-14
17
+
18
+ * removed
19
+ * delete apib_path [#31](https://github.com/funbox/tomograph/issues/31)
20
+ * delete drafter_4_apib_path [#32](https://github.com/funbox/tomograph/issues/32)
21
+ * replace drafter_yaml_path with drafter_4_yaml_path [#33](https://github.com/funbox/tomograph/issues/33)
22
+ * delete crafter_apib_path [#34](https://github.com/funbox/tomograph/issues/34)
23
+ * delete multi_json [#35](https://github.com/funbox/tomograph/issues/35)
24
+
25
+ ### 3.0.0 - 2020-08-27
26
+
27
+ * features
28
+ * support multi request for one resource path [#27](https://github.com/funbox/tomograph/issues/27)
29
+ * removed
30
+ * delete support drafter 3 [#29](https://github.com/funbox/tomograph/issues/29)
31
+
32
+ ### 2.5.4 - 2020-04-06
33
+
34
+ * fixed warnings on ruby 2.7
35
+ * updated dependences
36
+
37
+ # Change log
38
+
3
39
  ### 2.5.3 - 2020-03-10
4
40
 
5
41
  * bug fixes
data/README.md CHANGED
@@ -1,265 +1,386 @@
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)
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>
6
-
7
- Convert API Blueprint to JSON Schema and search.
1
+ # Tomograph
2
+
3
+ Convert API Blueprint, Swagger and OpenAPI to minimal routes with JSON Schema. For ease of use and creation of new tools.
4
+
5
+ Will look like
6
+
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
- First you need to install [drafter](https://github.com/apiaryio/drafter).
12
-
13
- Second add this line to your application's Gemfile:
85
+ Then add this line to your application's Gemfile:
14
86
 
15
87
  ```ruby
16
88
  gem 'tomograph'
17
89
  ```
18
90
 
19
- And then execute:
91
+ After that execute:
20
92
 
21
- $ bundle
93
+ ```bash
94
+ $ bundle
95
+ ```
22
96
 
23
- Or install it yourself as:
97
+ Or install the gem by yourself:
24
98
 
25
- $ gem install tomograph
99
+ ```bash
100
+ $ gem install tomograph
101
+ ```
26
102
 
27
103
  ## Usage
28
104
 
105
+ ### In code
106
+
107
+ #### OpenAPI 2.0
108
+
109
+ Also Swagger
110
+
29
111
  ```ruby
30
112
  require 'tomograph'
31
- ```
32
113
 
33
- ```ruby
34
- tomogram = Tomograph::Tomogram.new(apib_path: '/path/to/doc.apib')
114
+ tomogram = Tomograph::Tomogram.new(openapi2_json_path: '/path/to/doc.json')
35
115
  ```
36
116
 
37
- ### Command line tool
117
+ #### OpenAPI 3.0
38
118
 
39
- The command line tool allows you to convert files from API Blueprint or API Elements to JSON Schema.
40
- ```
41
- tomograph doc.apib doc.json
42
- ```
43
- Now there is support for documents pre-parsed by [drafter](https://github.com/apiaryio/drafter) versions 3 and 4, or crafter. To select the handler version, use the -d key and specify the required version. For example:
44
- ```
45
- tomograph -d 4 doc_by_drafter4.yaml doc.json
46
- ```
47
- See
48
- ```
49
- tomograph -h
50
- ```
51
- for more details on usage.
52
-
53
- ## Convert
119
+ Also OpenAPI
54
120
 
55
121
  ```ruby
56
- tomogram.to_json
122
+ require 'tomograph'
123
+
124
+ tomogram = Tomograph::Tomogram.new(openapi3_yaml_path: '/path/to/doc.yaml')
57
125
  ```
58
126
 
59
- Example input:
60
- ```apib
61
- FORMAT: 1A
62
- HOST: http://test.local
127
+ #### API Blueprint
63
128
 
64
- # project
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.
65
131
 
66
- # Group project
132
+ That is, I mean that you first need to do this
67
133
 
68
- Project
134
+ ```bash
135
+ drafter doc.apib -o doc.yaml
136
+ ```
69
137
 
70
- ## Authentication [/sessions]
138
+ and then
71
139
 
72
- ### Sign In [POST]
140
+ ```ruby
141
+ require 'tomograph'
73
142
 
74
- + Request (application/json)
143
+ tomogram = Tomograph::Tomogram.new(drafter_yaml_path: '/path/to/doc.yaml')
144
+ ```
75
145
 
76
- + Attributes
77
- + login (string, required)
78
- + password (string, required)
79
- + captcha (string, optional)
146
+ #### Tomograph
80
147
 
81
- + Response 401 (application/json)
148
+ To use additional features of the pre-converted
82
149
 
83
- + Response 429 (application/json)
150
+ ```ruby
151
+ require 'tomograph'
84
152
 
85
- + Response 201 (application/json)
153
+ tomogram = Tomograph::Tomogram.new(tomogram_json_path: '/path/to/doc.json')
154
+ ```
86
155
 
87
- + Attributes
88
- + confirmation (Confirmation, optional)
89
- + captcha (string, optional)
90
- + captcha_does_not_match (boolean, optional)
156
+ #### prefix
157
+ Default: `''`
91
158
 
159
+ You can specify API prefix and path to the spec using one of the possible formats:
92
160
 
93
- # Data Structures
161
+ ```ruby
162
+ Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
163
+ ```
94
164
 
95
- ## Confirmation (object)
96
- + id (string, required)
97
- + type (string, required)
98
- + operation (string, required)
165
+ ```ruby
166
+ Tomograph::Tomogram.new(prefix: '/api/v2', tomogram_json_path: '/path/to/doc.json')
99
167
  ```
100
168
 
101
- Example output:
102
- ```json
103
- [
104
- {
105
- "path": "/sessions",
106
- "method": "POST",
107
- "content-type": "application/json",
108
- "request": {
109
- "$schema": "http://json-schema.org/draft-04/schema#",
110
- "type": "object",
111
- "properties": {
112
- "login": {
113
- "type": "string"
169
+ #### to_json
170
+ Use `to_json` for converting to JSON, example from API Blueprint:
171
+
172
+ ```ruby
173
+ tomogram.to_json
174
+ ```
175
+
176
+ <details>
177
+ <summary>Example input</summary>
178
+
179
+ ```apib
180
+ FORMAT: 1A
181
+ HOST: http://test.local
182
+
183
+ # project
184
+
185
+ # Group project
186
+
187
+ Project
188
+
189
+ ## Authentication [/sessions]
190
+
191
+ ### Sign In [POST]
192
+
193
+ + Request (application/json)
194
+
195
+ + Attributes
196
+ + login (string, required)
197
+ + password (string, required)
198
+ + captcha (string, optional)
199
+
200
+ + Response 401 (application/json)
201
+
202
+ + Response 429 (application/json)
203
+
204
+ + Response 201 (application/json)
205
+
206
+ + Attributes
207
+ + confirmation (Confirmation, optional)
208
+ + captcha (string, optional)
209
+ + captcha_does_not_match (boolean, optional)
210
+
211
+
212
+ # Data Structures
213
+
214
+ ## Confirmation (object)
215
+ + id (string, required)
216
+ + type (string, required)
217
+ + operation (string, required)
218
+ ```
219
+ </details>
220
+
221
+ <details>
222
+ <summary>Example output</summary>
223
+
224
+ ```json
225
+ [
226
+ {
227
+ "path": "/sessions",
228
+ "method": "POST",
229
+ "content-type": "application/json",
230
+ "requests": [{
231
+ "$schema": "http://json-schema.org/draft-04/schema#",
232
+ "type": "object",
233
+ "properties": {
234
+ "login": {
235
+ "type": "string"
236
+ },
237
+ "password": {
238
+ "type": "string"
239
+ },
240
+ "captcha": {
241
+ "type": "string"
242
+ }
114
243
  },
115
- "password": {
116
- "type": "string"
244
+ "required": [
245
+ "login",
246
+ "password"
247
+ ]
248
+ }],
249
+ "responses": [
250
+ {
251
+ "status": "401",
252
+ "content-type": "application/json",
253
+ "body": {}
117
254
  },
118
- "captcha": {
119
- "type": "string"
120
- }
121
- },
122
- "required": [
123
- "login",
124
- "password"
125
- ]
126
- },
127
- "responses": [
128
- {
129
- "status": "401",
130
- "content-type": "application/json",
131
- "body": {}
132
- },
133
- {
134
- "status": "429",
135
- "content-type": "application/json",
136
- "body": {}
137
- },
138
- {
139
- "status": "201",
140
- "content-type": "application/json",
141
- "body": {
142
- "$schema": "http://json-schema.org/draft-04/schema#",
143
- "type": "object",
144
- "properties": {
145
- "confirmation": {
146
- "type": "object",
147
- "properties": {
148
- "id": {
149
- "type": "string"
150
- },
151
- "type": {
152
- "type": "string"
255
+ {
256
+ "status": "429",
257
+ "content-type": "application/json",
258
+ "body": {}
259
+ },
260
+ {
261
+ "status": "201",
262
+ "content-type": "application/json",
263
+ "body": {
264
+ "$schema": "http://json-schema.org/draft-04/schema#",
265
+ "type": "object",
266
+ "properties": {
267
+ "confirmation": {
268
+ "type": "object",
269
+ "properties": {
270
+ "id": {
271
+ "type": "string"
272
+ },
273
+ "type": {
274
+ "type": "string"
275
+ },
276
+ "operation": {
277
+ "type": "string"
278
+ }
153
279
  },
154
- "operation": {
155
- "type": "string"
156
- }
280
+ "required": [
281
+ "id",
282
+ "type",
283
+ "operation"
284
+ ]
285
+ },
286
+ "captcha": {
287
+ "type": "string"
157
288
  },
158
- "required": [
159
- "id",
160
- "type",
161
- "operation"
162
- ]
163
- },
164
- "captcha": {
165
- "type": "string"
166
- },
167
- "captcha_does_not_match": {
168
- "type": "boolean"
289
+ "captcha_does_not_match": {
290
+ "type": "boolean"
291
+ }
169
292
  }
170
293
  }
171
294
  }
172
- }
173
- ]
174
- }
175
- ]
176
- ```
177
-
178
- ## Search
295
+ ]
296
+ }
297
+ ]
298
+ ```
299
+ </details>
179
300
 
180
- ### find_request
301
+ #### to_a
302
+ ```ruby
303
+ tomogram.to_a
304
+ ```
181
305
 
306
+ #### find_request
182
307
  ```ruby
183
308
  request = tomogram.find_request(method: 'GET', path: '/status/1?qwe=rty')
184
309
  ```
185
310
 
186
- ### find_request
187
-
311
+ #### find_request_with_content_type
188
312
  ```ruby
189
313
  request = tomogram.find_request_with_content_type(method: 'GET', path: '/status/1?qwe=rty', content_type: 'application/json')
190
314
  ```
191
315
 
192
- ### find_responses
193
-
194
-
316
+ #### `find_responses`
195
317
  ```ruby
196
318
  responses = request.find_responses(status: '200')
197
319
  ```
198
320
 
199
- ## Other methods
200
-
201
- ### prefix_match?
202
-
203
- This can be useful if you use a prefix.
321
+ #### prefix_match?
322
+ This may be useful if you specify a prefix.
204
323
 
205
324
  ```ruby
206
325
  tomogram.prefix_match?('http://local/api/v2/users')
207
326
  ```
208
327
 
209
- ## Params
328
+ #### to_resources
329
+ Maps resources for API Blueprint with possible requests.
210
330
 
211
- Example:
331
+ Example output:
212
332
 
213
333
  ```ruby
214
- Tomograph::Tomogram.new(prefix: '/api/v2', apib_path: '/path/to/doc.apib')
334
+ {
335
+ '/sessions' => ['POST /sessions']
336
+ }
215
337
  ```
216
338
 
217
- or
339
+ ### Command line tool
218
340
 
219
- ```ruby
220
- Tomograph::Tomogram.new(prefix: '/api/v2', drafter_yaml_path: '/path/to/doc.yaml')
221
- ```
341
+ CLI allows you to convert files from API Blueprint (API Elements), Swagger and OpenAPI to JSON Schema.
222
342
 
223
- or
343
+ Run CLI with `-h` to get detailed help:
224
344
 
225
- ```ruby
226
- Tomograph::Tomogram.new(prefix: '/api/v2', tomogram_json_path: '/path/to/doc.json')
345
+ ```bash
346
+ tomograph -h
227
347
  ```
228
348
 
229
- ### apib_path
230
-
231
- Path to API Blueprint documentation. There must be an installed [drafter](https://github.com/apiaryio/drafter) to parse it.
232
-
233
- ### drafter_yaml_path
349
+ To specify the handler version use the `-d` flag:
234
350
 
235
- Path to API Blueprint documentation pre-parsed with `drafter` and saved to a YAML file.
236
-
237
- Drafter v.4
238
-
239
- 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.
351
+ #### OpenAPI 2.0
352
+ ```bash
353
+ tomograph -d openapi2 openapi2.json tomogram.json
354
+ ```
240
355
 
241
- Crafter
356
+ #### OpenAPI 3.0
357
+ ```bash
358
+ tomograph -d openapi3 openapi3.yaml doc.json
359
+ ```
242
360
 
243
- In case when you want to use `сrafter`, then you need to specify these parameters `crafter_apib_path`, `crafter_yaml_path`.
361
+ #### API Blueprint
362
+ ```bash
363
+ tomograph -d 4 apielemetns.yaml doc.json
364
+ ```
244
365
 
245
- ### tomogram_json_path
366
+ #### exclude-description
246
367
 
247
- Path to API Blueprint documentation converted with `tomograph` to a JSON file.
368
+ Exclude "description" keys from json-schemas.
248
369
 
249
- ### prefix
370
+ ```bash
371
+ tomograph -d 4 apielemetns.yaml doc.json --exclude-description
372
+ ```
250
373
 
251
- Default empty String. Prefix of API requests. Example: `'/api'`.
374
+ #### split
252
375
 
253
- ### to_resources
376
+ Split output into files by method. Output in dir path.
254
377
 
255
- Hash resource with requests.
256
- The result for the example above:
257
- ```ruby
258
- {
259
- '/sessions' => ['POST /sessions']
260
- }
378
+ ```bash
379
+ tomograph -d 4 --split apielemetns.yaml jsons/
261
380
  ```
262
381
 
263
382
  ## License
264
383
 
265
384
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
385
+
386
+ [![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)