apiary_blueprint_convertor 0.1.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 848054e783c9a61d69e0a2be0dbdb0eef16a7388
4
- data.tar.gz: 963c51bb0f6b0ec32a8dd973d3f613973acc2741
3
+ metadata.gz: ae60b7154b1f950ea52995a28d339838c37dbfe0
4
+ data.tar.gz: 6554c053da25fc9543a2a5b913bd4a64a238aa29
5
5
  SHA512:
6
- metadata.gz: 6060f1dc3dad96ce6af4b5bac882272496cb59d4b27f440806f676a278ce95a77100eaa4bc102c2f3d3dc397d6a3d11bc5b0e4e46b829bef447a8cb127215db6
7
- data.tar.gz: 7be67e76e709b687ca30cfe4754f15f5f30ff37c1f50b71a796f24e230c558b99b0cf70f673bbcc0c002f42aff5bcd3336712f25ed397738ce5f6ffa991cfc0f
6
+ metadata.gz: 580261db38265d29ad56bad9bcf1bcb46dbdcb65776f8179c085018629f45bd34f52310cf9e8f89099d60c41f4837a06d108966064aa524a08c2b9b1177a608e
7
+ data.tar.gz: a0188bd53f80ffd71deaafa08b7eab36d4d5d6c843e66f420f227b04b7c02f4a8d6a8f6b147e9f5619b074cc735fe628fcb9924923ae1e060dfb10b42ace716d
data/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GIT
10
10
  PATH
11
11
  remote: .
12
12
  specs:
13
- apiary_blueprint_convertor (0.1.1)
13
+ apiary_blueprint_convertor (0.2.0)
14
14
 
15
15
  GEM
16
16
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
+ ![logo](https://raw.github.com/apiaryio/api-blueprint/gh-pages/assets/logo_apiblueprint.png)
2
+
1
3
  # Apiary Blueprint AST Convertor [![Build Status](https://travis-ci.org/apiaryio/apiary_blueprint_convertor.png?branch=master)](https://travis-ci.org/apiaryio/apiary_blueprint_convertor)
2
- A migration tool for legacy [Apiary Blueprint](https://github.com/apiaryio/blueprint-parser) AST into [API Blueprint](http://apiblueprint.org) AST. Converts Apiary Blueprint AST serialized into a JSON file to [API Blueprint AST](https://github.com/apiaryio/snowcrash/wiki/API-Blueprint-AST-Media-Types) JSON representation (`vnd.apiblueprint.ast.raw+json; version=1.0`).
4
+ A migration tool for legacy [Apiary Blueprint](https://github.com/apiaryio/blueprint-parser) AST into [API Blueprint](http://apiblueprint.org) AST. Converts Apiary Blueprint AST serialized into a JSON file to [API Blueprint AST](https://github.com/apiaryio/api-blueprint-ast) JSON representation (`vnd.apiblueprint.ast.raw+json; version=2.0`).
3
5
 
4
6
  ## Installation
5
7
  Add this line to your application's Gemfile:
@@ -29,6 +31,12 @@ Use this convertor together with the legacy [Apiary Blueprint Parser](https://gi
29
31
  2. Convert legacy JSON AST into API Blueprint JSON AST using `apiary_blueprint_convertor`
30
32
  3. Compose API Blueprint from API Blueprint JSON AST using `matter_compiler`
31
33
 
34
+ For example:
35
+
36
+ ```sh
37
+ $ blueprint-parser legacy_blueprint.apib | apiary_blueprint_convertor | matter_compiler --format json > new_blueprint.md
38
+ ```
39
+
32
40
  ## Contributing
33
41
  1. Fork this repository (http://github.com/apiaryio/apiary_blueprint_convertor/fork)
34
42
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -113,12 +113,13 @@ Feature: Convert AST
113
113
  Given a file named "apiblueprint_ast.json" with:
114
114
  """
115
115
  {
116
- "_version": "1.0",
117
- "metadata": {
118
- "HOST": {
116
+ "_version": "2.0",
117
+ "metadata": [
118
+ {
119
+ "name": "HOST",
119
120
  "value": "http://www.google.com/"
120
121
  }
121
- },
122
+ ],
122
123
  "name": "Sample API v2",
123
124
  "description": "Welcome to our sample API documentation. All comments can be written in (support [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax)",
124
125
  "resourceGroups": [
@@ -132,14 +133,12 @@ Feature: Convert AST
132
133
  "uriTemplate": "/shopping-cart",
133
134
  "model": null,
134
135
  "parameters": null,
135
- "headers": null,
136
136
  "actions": [
137
137
  {
138
138
  "name": null,
139
139
  "description": "List products added into your shopping-cart. (comment block again in Markdown)",
140
140
  "method": "GET",
141
141
  "parameters": null,
142
- "headers": null,
143
142
  "examples": [
144
143
  {
145
144
  "name": null,
@@ -149,11 +148,12 @@ Feature: Convert AST
149
148
  {
150
149
  "name": "200",
151
150
  "description": null,
152
- "headers": {
153
- "Content-Type": {
151
+ "headers": [
152
+ {
153
+ "name": "Content-Type",
154
154
  "value": "application/json"
155
155
  }
156
- },
156
+ ],
157
157
  "body": "{\n \"items\": [\n {\n \"url\": \"/shopping-cart/1\",\n \"product\": \"2ZY48XPZ\",\n \"quantity\": 1,\n \"name\": \"New socks\",\n \"price\": 1.25\n }\n ]\n}",
158
158
  "schema": null
159
159
  }
@@ -166,7 +166,6 @@ Feature: Convert AST
166
166
  "description": "Save new products in your shopping cart",
167
167
  "method": "POST",
168
168
  "parameters": null,
169
- "headers": null,
170
169
  "examples": [
171
170
  {
172
171
  "name": null,
@@ -175,11 +174,12 @@ Feature: Convert AST
175
174
  {
176
175
  "name": null,
177
176
  "description": null,
178
- "headers": {
179
- "Content-Type": {
177
+ "headers": [
178
+ {
179
+ "name": "Content-Type",
180
180
  "value": "application/json"
181
181
  }
182
- },
182
+ ],
183
183
  "body": "{\n \"product\": \"1AB23ORM\",\n \"quantity\": 2\n}",
184
184
  "schema": null
185
185
  }
@@ -188,22 +188,24 @@ Feature: Convert AST
188
188
  {
189
189
  "name": "201",
190
190
  "description": null,
191
- "headers": {
192
- "Content-Type": {
191
+ "headers": [
192
+ {
193
+ "name": "Content-Type",
193
194
  "value": "application/json"
194
195
  }
195
- },
196
+ ],
196
197
  "body": "{\n \"status\": \"created\",\n \"url\": \"/shopping-cart/2\"\n}",
197
198
  "schema": null
198
199
  },
199
200
  {
200
201
  "name": "401",
201
202
  "description": null,
202
- "headers": {
203
- "Content-Type": {
203
+ "headers": [
204
+ {
205
+ "name": "Content-Type",
204
206
  "value": "application/json; charset=utf-8"
205
207
  }
206
- },
208
+ ],
207
209
  "body": "{\n \"message\": \"You have not provided proper request token\"\n}",
208
210
  "schema": null
209
211
  }
@@ -225,14 +227,12 @@ Feature: Convert AST
225
227
  "uriTemplate": "/payment",
226
228
  "model": null,
227
229
  "parameters": null,
228
- "headers": null,
229
230
  "actions": [
230
231
  {
231
232
  "name": null,
232
233
  "description": "This resource allows you to submit payment information to process your *shopping cart* items",
233
234
  "method": "POST",
234
235
  "parameters": null,
235
- "headers": null,
236
236
  "examples": [
237
237
  {
238
238
  "name": null,
@@ -266,14 +266,12 @@ Feature: Convert AST
266
266
  "uriTemplate": "/resource",
267
267
  "model": null,
268
268
  "parameters": null,
269
- "headers": null,
270
269
  "actions": [
271
270
  {
272
271
  "name": null,
273
272
  "description": null,
274
273
  "method": "POST",
275
274
  "parameters": null,
276
- "headers": null,
277
275
  "examples": [
278
276
  {
279
277
  "name": null,
@@ -282,11 +280,12 @@ Feature: Convert AST
282
280
  {
283
281
  "name": null,
284
282
  "description": null,
285
- "headers": {
286
- "Content-Type": {
283
+ "headers": [
284
+ {
285
+ "name": "Content-Type",
287
286
  "value": "application/json"
288
287
  }
289
- },
288
+ ],
290
289
  "body": "{\n \"a\": \"b\",\n \"c\": \"0\"\n}",
291
290
  "schema": "{\"type\":\"object\",\"properties\":{\"a\":{\"type\":\"string\",\"format\":\"alphanumeric\"},\"c\":{\"type\":\"integer\"}}}"
292
291
  }
@@ -5,7 +5,7 @@ module ApiaryBlueprintConvertor
5
5
 
6
6
  class Convertor
7
7
 
8
- API_BLUEPRONT_AST_VERSION = "1.0"
8
+ API_BLUEPRINT_AST_VERSION = "2.0"
9
9
 
10
10
  def self.read_file(file)
11
11
  unless File.readable?(file)
@@ -33,7 +33,7 @@ module ApiaryBlueprintConvertor
33
33
 
34
34
  # Top level API Blueprint Template
35
35
  blueprint_ast = {
36
- :_version => API_BLUEPRONT_AST_VERSION,
36
+ :_version => API_BLUEPRINT_AST_VERSION,
37
37
  :metadata => nil,
38
38
  :name => nil,
39
39
  :description => nil,
@@ -77,11 +77,12 @@ module ApiaryBlueprintConvertor
77
77
  return
78
78
  end
79
79
 
80
- blueprint_ast[:metadata] = {
81
- :HOST => {
80
+ blueprint_ast[:metadata] = [
81
+ {
82
+ :name => "HOST",
82
83
  :value => "#{legacy_location}"
83
84
  }
84
- }
85
+ ]
85
86
  end
86
87
 
87
88
  # Convert array of blueprint sections
@@ -125,7 +126,6 @@ module ApiaryBlueprintConvertor
125
126
  :uriTemplate => legacy_resource[:url],
126
127
  :model => nil,
127
128
  :parameters => nil,
128
- :headers => nil,
129
129
  :actions => nil
130
130
  }
131
131
 
@@ -162,7 +162,6 @@ module ApiaryBlueprintConvertor
162
162
  :description => legacy_resource[:description],
163
163
  :method => legacy_resource[:method],
164
164
  :parameters => nil,
165
- :headers => nil,
166
165
  :examples => nil
167
166
  }
168
167
 
@@ -234,12 +233,15 @@ module ApiaryBlueprintConvertor
234
233
  # from legacy headers hash
235
234
  def self.create_headers_hash(legacy_headers)
236
235
  return nil if legacy_headers.blank?
237
- headers = {}
236
+ headers = []
238
237
 
239
238
  legacy_headers.each do |key, value|
240
- headers[key] = {
241
- :value => value
239
+ header = {
240
+ :name => key.to_s,
241
+ :value => value.to_s
242
242
  }
243
+
244
+ headers << header
243
245
  end
244
246
 
245
247
  headers
@@ -1,3 +1,3 @@
1
1
  module ApiaryBlueprintConvertor
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -88,13 +88,9 @@ class ConvertorTest < Minitest::Test
88
88
  assert_equal 1, blueprint_ast.keys.length
89
89
  assert_equal :metadata, blueprint_ast.keys.first
90
90
 
91
- assert_equal 1, blueprint_ast[:metadata].keys.length
92
- assert_equal :HOST, blueprint_ast[:metadata].keys.first
93
-
94
- assert_equal 1, blueprint_ast[:metadata][:HOST].keys.length
95
- assert_equal :value, blueprint_ast[:metadata][:HOST].keys.first
96
-
97
- assert_equal "http://google.com", blueprint_ast[:metadata][:HOST][:value]
91
+ assert_equal 1, blueprint_ast[:metadata].length
92
+ assert_equal "HOST", blueprint_ast[:metadata][0][:name]
93
+ assert_equal "http://google.com", blueprint_ast[:metadata][0][:value]
98
94
  end
99
95
 
100
96
  def test_convert_blueprint
@@ -104,6 +100,7 @@ class ConvertorTest < Minitest::Test
104
100
  assert_equal 4, blueprint_ast.keys.length
105
101
 
106
102
  assert blueprint_ast[:metadata]
103
+ assert_equal 1, blueprint_ast[:metadata].length
107
104
  assert_equal "API NAME", blueprint_ast[:name]
108
105
  assert_equal "Lorem Ipsum", blueprint_ast[:description]
109
106
  assert blueprint_ast[:resourceGroups]
@@ -145,7 +142,6 @@ class ConvertorTest < Minitest::Test
145
142
  assert_equal "/resource1", group_ast[:resources][0][:uriTemplate]
146
143
  assert_equal nil, group_ast[:resources][0][:model]
147
144
  assert_equal nil, group_ast[:resources][0][:parameters]
148
- assert_equal nil, group_ast[:resources][0][:headers]
149
145
  assert group_ast[:resources][0][:actions]
150
146
  assert_equal 2, group_ast[:resources][0][:actions].length
151
147
 
@@ -154,7 +150,6 @@ class ConvertorTest < Minitest::Test
154
150
  assert_equal "/resource2", group_ast[:resources][1][:uriTemplate]
155
151
  assert_equal nil, group_ast[:resources][1][:model]
156
152
  assert_equal nil, group_ast[:resources][1][:parameters]
157
- assert_equal nil, group_ast[:resources][1][:headers]
158
153
  assert group_ast[:resources][1][:actions]
159
154
  assert_equal 1, group_ast[:resources][1][:actions].length
160
155
  end
@@ -168,7 +163,6 @@ class ConvertorTest < Minitest::Test
168
163
  assert_equal "GET", resource_ast[:actions][0][:method]
169
164
  assert_equal "Ipsum Lorem", resource_ast[:actions][0][:description]
170
165
  assert_equal nil, resource_ast[:actions][0][:parameters]
171
- assert_equal nil, resource_ast[:actions][0][:headers]
172
166
  assert_instance_of Array, resource_ast[:actions][0][:examples]
173
167
  end
174
168
 
@@ -195,34 +189,23 @@ class ConvertorTest < Minitest::Test
195
189
  assert_equal "200", action_ast[:examples][0][:responses][0][:name]
196
190
  assert_equal nil, action_ast[:examples][0][:responses][0][:description]
197
191
 
198
- assert_instance_of Hash, action_ast[:examples][0][:responses][0][:headers]
199
- assert_equal 1, action_ast[:examples][0][:responses][0][:headers].keys.length
200
- assert_equal :'Content-Type', action_ast[:examples][0][:responses][0][:headers].keys[0]
201
- assert_instance_of Hash, action_ast[:examples][0][:responses][0][:headers][:'Content-Type']
202
- assert_equal 1, action_ast[:examples][0][:responses][0][:headers][:'Content-Type'].keys.length
203
- assert_equal :value, action_ast[:examples][0][:responses][0][:headers][:'Content-Type'].keys[0]
204
- assert_equal "text/plain", action_ast[:examples][0][:responses][0][:headers][:'Content-Type'][:value]
205
-
192
+ assert_instance_of Array, action_ast[:examples][0][:responses][0][:headers]
193
+ assert_equal 1, action_ast[:examples][0][:responses][0][:headers].length
194
+ assert_equal "Content-Type", action_ast[:examples][0][:responses][0][:headers][0][:name]
195
+ assert_equal "text/plain", action_ast[:examples][0][:responses][0][:headers][0][:value]
206
196
  assert_equal "Hello World!", action_ast[:examples][0][:responses][0][:body]
207
197
  assert_equal "0xdeadbeef", action_ast[:examples][0][:responses][0][:schema]
208
198
 
209
199
  assert_equal "404", action_ast[:examples][0][:responses][1][:name]
210
200
  assert_equal nil, action_ast[:examples][0][:responses][1][:description]
211
201
 
212
- assert_instance_of Hash, action_ast[:examples][0][:responses][1][:headers]
213
- assert_equal 2, action_ast[:examples][0][:responses][1][:headers].keys.length
202
+ assert_instance_of Array, action_ast[:examples][0][:responses][1][:headers]
203
+ assert_equal 2, action_ast[:examples][0][:responses][1][:headers].length
214
204
 
215
- assert_equal :'Content-Type', action_ast[:examples][0][:responses][1][:headers].keys[0]
216
- assert_instance_of Hash, action_ast[:examples][0][:responses][1][:headers][:'Content-Type']
217
- assert_equal 1, action_ast[:examples][0][:responses][1][:headers][:'Content-Type'].keys.length
218
- assert_equal :value, action_ast[:examples][0][:responses][1][:headers][:'Content-Type'].keys[0]
219
- assert_equal "application/json", action_ast[:examples][0][:responses][1][:headers][:'Content-Type'][:value]
220
-
221
- assert_equal :'X-Header', action_ast[:examples][0][:responses][1][:headers].keys[1]
222
- assert_instance_of Hash, action_ast[:examples][0][:responses][1][:headers][:'X-Header']
223
- assert_equal 1, action_ast[:examples][0][:responses][1][:headers][:'X-Header'].keys.length
224
- assert_equal :value, action_ast[:examples][0][:responses][1][:headers][:'X-Header'].keys[0]
225
- assert_equal "42", action_ast[:examples][0][:responses][1][:headers][:'X-Header'][:value]
205
+ assert_equal "Content-Type", action_ast[:examples][0][:responses][1][:headers][0][:name]
206
+ assert_equal "application/json", action_ast[:examples][0][:responses][1][:headers][0][:value]
207
+ assert_equal "X-Header", action_ast[:examples][0][:responses][1][:headers][1][:name]
208
+ assert_equal "42", action_ast[:examples][0][:responses][1][:headers][1][:value]
226
209
 
227
210
  assert_equal "42 not found.", action_ast[:examples][0][:responses][1][:body]
228
211
  assert_equal "0xdeadbeef", action_ast[:examples][0][:responses][1][:schema]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiary_blueprint_convertor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zdenek Nemec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler