rapis 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Apifile +35 -26
- data/CHANGELOG.md +6 -0
- data/README.md +121 -153
- data/lib/rapis.rb +1 -0
- data/lib/rapis/converter.rb +65 -29
- data/lib/rapis/template_functions.rb +103 -0
- data/lib/rapis/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 453b9823828f6ea422721fcd30b6c5d4079b0e3c
|
4
|
+
data.tar.gz: 303c6211e22df3a2339fc9839d090434ead227d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d62c8f3227b79f63e328d8523d6c57f115fc6528e5c57ee6f373c07d5a6e75469787d4c819822d3022034662db401b030a35273d75166b6152c0d63c4fa46f9
|
7
|
+
data.tar.gz: 40c68ce182a28a4373aceee129f78baccf6b193304c55eb814404ee270b3df3407bc607149f5745d0f787accef758891eb6030be437d5f3784fcb4bc3e78697b
|
data/.rubocop.yml
CHANGED
data/Apifile
CHANGED
@@ -8,19 +8,18 @@ rest_api do
|
|
8
8
|
basePath "/test"
|
9
9
|
schemes ["https"]
|
10
10
|
paths do
|
11
|
-
|
11
|
+
item "/" do
|
12
12
|
get do
|
13
13
|
consumes ["application/json"]
|
14
14
|
produces ["text/html"]
|
15
15
|
responses do
|
16
|
-
code 200 do
|
16
|
+
code "200" do
|
17
17
|
description "200 response"
|
18
18
|
headers(
|
19
19
|
{"Content-Type"=>{"type"=>"string"}})
|
20
20
|
end
|
21
21
|
end
|
22
22
|
amazon_apigateway_integration do
|
23
|
-
type "mock"
|
24
23
|
responses do
|
25
24
|
default do
|
26
25
|
statusCode 200
|
@@ -34,12 +33,13 @@ rest_api do
|
|
34
33
|
requestTemplates(
|
35
34
|
{"application/json"=>"{\"statusCode\": 200}"})
|
36
35
|
passthroughBehavior "when_no_match"
|
36
|
+
type "mock"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
post do
|
40
40
|
produces ["application/json"]
|
41
41
|
responses do
|
42
|
-
code 200 do
|
42
|
+
code "200" do
|
43
43
|
description "200 response"
|
44
44
|
schema do
|
45
45
|
ref "#/definitions/Empty"
|
@@ -49,7 +49,6 @@ rest_api do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
amazon_apigateway_integration do
|
52
|
-
type "http"
|
53
52
|
responses do
|
54
53
|
default do
|
55
54
|
statusCode 200
|
@@ -60,13 +59,14 @@ rest_api do
|
|
60
59
|
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
61
60
|
passthroughBehavior "when_no_match"
|
62
61
|
httpMethod "POST"
|
62
|
+
type "http"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
options do
|
66
66
|
consumes ["application/json"]
|
67
67
|
produces ["application/json"]
|
68
68
|
responses do
|
69
|
-
code 200 do
|
69
|
+
code "200" do
|
70
70
|
description "200 response"
|
71
71
|
schema do
|
72
72
|
ref "#/definitions/Empty"
|
@@ -78,7 +78,6 @@ rest_api do
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
amazon_apigateway_integration do
|
81
|
-
type "mock"
|
82
81
|
responses do
|
83
82
|
default do
|
84
83
|
statusCode 200
|
@@ -92,18 +91,25 @@ rest_api do
|
|
92
91
|
requestTemplates(
|
93
92
|
{"application/json"=>"{\"statusCode\": 200}"})
|
94
93
|
passthroughBehavior "when_no_match"
|
94
|
+
type "mock"
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
98
|
+
item "/pets" do
|
99
99
|
get do
|
100
100
|
produces ["application/json"]
|
101
|
-
parameters
|
102
|
-
|
103
|
-
|
104
|
-
|
101
|
+
parameters do
|
102
|
+
query "type" do
|
103
|
+
required false
|
104
|
+
type "string"
|
105
|
+
end
|
106
|
+
query "page" do
|
107
|
+
required false
|
108
|
+
type "string"
|
109
|
+
end
|
110
|
+
end
|
105
111
|
responses do
|
106
|
-
code 200 do
|
112
|
+
code "200" do
|
107
113
|
description "200 response"
|
108
114
|
schema do
|
109
115
|
ref "#/definitions/Empty"
|
@@ -113,7 +119,6 @@ rest_api do
|
|
113
119
|
end
|
114
120
|
end
|
115
121
|
amazon_apigateway_integration do
|
116
|
-
type "http"
|
117
122
|
responses do
|
118
123
|
default do
|
119
124
|
statusCode 200
|
@@ -127,12 +132,13 @@ rest_api do
|
|
127
132
|
requestParameters(
|
128
133
|
{"integration.request.querystring.page"=>"method.request.querystring.page",
|
129
134
|
"integration.request.querystring.type"=>"method.request.querystring.type"})
|
135
|
+
type "http"
|
130
136
|
end
|
131
137
|
end
|
132
138
|
post do
|
133
139
|
produces ["application/json"]
|
134
140
|
responses do
|
135
|
-
code 200 do
|
141
|
+
code "200" do
|
136
142
|
description "200 response"
|
137
143
|
schema do
|
138
144
|
ref "#/definitions/Empty"
|
@@ -142,7 +148,6 @@ rest_api do
|
|
142
148
|
end
|
143
149
|
end
|
144
150
|
amazon_apigateway_integration do
|
145
|
-
type "http"
|
146
151
|
responses do
|
147
152
|
default do
|
148
153
|
statusCode 200
|
@@ -153,13 +158,14 @@ rest_api do
|
|
153
158
|
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
154
159
|
passthroughBehavior "when_no_match"
|
155
160
|
httpMethod "POST"
|
161
|
+
type "http"
|
156
162
|
end
|
157
163
|
end
|
158
164
|
options do
|
159
165
|
consumes ["application/json"]
|
160
166
|
produces ["application/json"]
|
161
167
|
responses do
|
162
|
-
code 200 do
|
168
|
+
code "200" do
|
163
169
|
description "200 response"
|
164
170
|
schema do
|
165
171
|
ref "#/definitions/Empty"
|
@@ -171,7 +177,6 @@ rest_api do
|
|
171
177
|
end
|
172
178
|
end
|
173
179
|
amazon_apigateway_integration do
|
174
|
-
type "mock"
|
175
180
|
responses do
|
176
181
|
default do
|
177
182
|
statusCode 200
|
@@ -185,17 +190,21 @@ rest_api do
|
|
185
190
|
requestTemplates(
|
186
191
|
{"application/json"=>"{\"statusCode\": 200}"})
|
187
192
|
passthroughBehavior "when_no_match"
|
193
|
+
type "mock"
|
188
194
|
end
|
189
195
|
end
|
190
196
|
end
|
191
|
-
|
197
|
+
item "/pets/{petId}" do
|
192
198
|
get do
|
193
199
|
produces ["application/json"]
|
194
|
-
parameters
|
195
|
-
|
196
|
-
|
200
|
+
parameters do
|
201
|
+
path "petId" do
|
202
|
+
required true
|
203
|
+
type "string"
|
204
|
+
end
|
205
|
+
end
|
197
206
|
responses do
|
198
|
-
code 200 do
|
207
|
+
code "200" do
|
199
208
|
description "200 response"
|
200
209
|
schema do
|
201
210
|
ref "#/definitions/Empty"
|
@@ -205,7 +214,6 @@ rest_api do
|
|
205
214
|
end
|
206
215
|
end
|
207
216
|
amazon_apigateway_integration do
|
208
|
-
type "http"
|
209
217
|
responses do
|
210
218
|
default do
|
211
219
|
statusCode 200
|
@@ -218,13 +226,14 @@ rest_api do
|
|
218
226
|
httpMethod "GET"
|
219
227
|
requestParameters(
|
220
228
|
{"integration.request.path.petId"=>"method.request.path.petId"})
|
229
|
+
type "http"
|
221
230
|
end
|
222
231
|
end
|
223
232
|
options do
|
224
233
|
consumes ["application/json"]
|
225
234
|
produces ["application/json"]
|
226
235
|
responses do
|
227
|
-
code 200 do
|
236
|
+
code "200" do
|
228
237
|
description "200 response"
|
229
238
|
schema do
|
230
239
|
ref "#/definitions/Empty"
|
@@ -236,7 +245,6 @@ rest_api do
|
|
236
245
|
end
|
237
246
|
end
|
238
247
|
amazon_apigateway_integration do
|
239
|
-
type "mock"
|
240
248
|
responses do
|
241
249
|
default do
|
242
250
|
statusCode 200
|
@@ -250,6 +258,7 @@ rest_api do
|
|
250
258
|
requestTemplates(
|
251
259
|
{"application/json"=>"{\"statusCode\": 200}"})
|
252
260
|
passthroughBehavior "when_no_match"
|
261
|
+
type "mock"
|
253
262
|
end
|
254
263
|
end
|
255
264
|
end
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://badge.fury.io/rb/rapis)
|
4
4
|
[](https://travis-ci.org/marcy-terui/rapis)
|
5
5
|
[](https://coveralls.io/github/marcy-terui/rapis?branch=master)
|
6
|
+
[](https://scrutinizer-ci.com/g/marcy-terui/rapis/?branch=master)
|
6
7
|
|
7
8
|
|
8
9
|
Swagger as Ruby DSL and its deployment tool for Amazon API Gateway
|
@@ -146,9 +147,113 @@ Options:
|
|
146
147
|
# Default: Apifile
|
147
148
|
```
|
148
149
|
|
149
|
-
##
|
150
|
+
## Example
|
150
151
|
|
151
|
-
###
|
152
|
+
### Ruby DSL
|
153
|
+
|
154
|
+
- Apifile
|
155
|
+
|
156
|
+
```ruby
|
157
|
+
rest_api do
|
158
|
+
swagger "2.0"
|
159
|
+
info do
|
160
|
+
version "2016-05-27T17:07:04Z"
|
161
|
+
title "PetStore"
|
162
|
+
end
|
163
|
+
host "p0dvujrb13.execute-api.ap-northeast-1.amazonaws.com"
|
164
|
+
basePath "/test"
|
165
|
+
schemes ["https"]
|
166
|
+
_include 'paths.rb'
|
167
|
+
_include 'definitions.rb'
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
- paths.rb
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
paths do
|
175
|
+
item "/pets/{petId}" do
|
176
|
+
get do
|
177
|
+
produces ["application/json"]
|
178
|
+
parameters do
|
179
|
+
path "petId" do
|
180
|
+
required true
|
181
|
+
type "string"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
responses do
|
185
|
+
code "200" do
|
186
|
+
description "200 response"
|
187
|
+
schema do
|
188
|
+
ref "#/definitions/Empty"
|
189
|
+
end
|
190
|
+
headers(
|
191
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
192
|
+
end
|
193
|
+
end
|
194
|
+
amazon_apigateway_integration do
|
195
|
+
responses do
|
196
|
+
default do
|
197
|
+
statusCode 200
|
198
|
+
responseParameters(
|
199
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
200
|
+
end
|
201
|
+
end
|
202
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{petId}"
|
203
|
+
passthroughBehavior "when_no_match"
|
204
|
+
httpMethod "GET"
|
205
|
+
requestParameters(
|
206
|
+
{"integration.request.path.petId"=>"method.request.path.petId"})
|
207
|
+
type "http"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
options do
|
211
|
+
consumes ["application/json"]
|
212
|
+
produces ["application/json"]
|
213
|
+
responses do
|
214
|
+
code "200" do
|
215
|
+
description "200 response"
|
216
|
+
schema do
|
217
|
+
ref "#/definitions/Empty"
|
218
|
+
end
|
219
|
+
headers(
|
220
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
221
|
+
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
222
|
+
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
223
|
+
end
|
224
|
+
end
|
225
|
+
amazon_apigateway_integration do
|
226
|
+
responses do
|
227
|
+
default do
|
228
|
+
statusCode 200
|
229
|
+
responseParameters(
|
230
|
+
{"method.response.header.Access-Control-Allow-Methods"=>"'GET,OPTIONS'",
|
231
|
+
"method.response.header.Access-Control-Allow-Headers"=>
|
232
|
+
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
233
|
+
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
234
|
+
end
|
235
|
+
end
|
236
|
+
requestTemplates(
|
237
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
238
|
+
passthroughBehavior "when_no_match"
|
239
|
+
type "mock"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
```
|
245
|
+
|
246
|
+
- definitions.rb
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
definitions do
|
250
|
+
Empty do
|
251
|
+
type "object"
|
252
|
+
end
|
253
|
+
end
|
254
|
+
```
|
255
|
+
|
256
|
+
### JSON result
|
152
257
|
|
153
258
|
```json
|
154
259
|
{
|
@@ -163,46 +268,18 @@ Options:
|
|
163
268
|
"https"
|
164
269
|
],
|
165
270
|
"paths": {
|
166
|
-
"/": {
|
271
|
+
"/pets/{petId}": {
|
167
272
|
"get": {
|
168
|
-
"consumes": [
|
169
|
-
"application/json"
|
170
|
-
],
|
171
273
|
"produces": [
|
172
|
-
"
|
274
|
+
"application/json"
|
173
275
|
],
|
174
|
-
"
|
175
|
-
|
176
|
-
"
|
177
|
-
"
|
178
|
-
|
179
|
-
|
180
|
-
}
|
181
|
-
}
|
276
|
+
"parameters": [
|
277
|
+
{
|
278
|
+
"name": "petId",
|
279
|
+
"in": "path",
|
280
|
+
"required": true,
|
281
|
+
"type": "string"
|
182
282
|
}
|
183
|
-
},
|
184
|
-
"x-amazon-apigateway-integration": {
|
185
|
-
"responses": {
|
186
|
-
"default": {
|
187
|
-
"statusCode": "200",
|
188
|
-
"responseParameters": {
|
189
|
-
"method.response.header.Content-Type": "'text/html'"
|
190
|
-
},
|
191
|
-
"responseTemplates": {
|
192
|
-
"text/html": "<html>\n <head>\n <style>\n body {\n color: #333;\n font-family: Sans-serif;\n max-width: 800px;\n margin: auto;\n }\n </style>\n </head>\n <body>\n <h1>Welcome to your Pet Store API</h1>\n <p>\n You have succesfully deployed your first API. You are seeing this HTML page because the <code>GET</code> method to the root resource of your API returns this content as a Mock integration.\n </p>\n <p>\n The Pet Store API contains the <code>/pets</code> and <code>/pets/{petId}</code> resources. By making a <a href=\"/$context.stage/pets/\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets</code> you can retrieve a list of Pets in your API. If you are looking for a specific pet, for example the pet with ID 1, you can make a <a href=\"/$context.stage/pets/1\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets/1</code>.\n </p>\n <p>\n You can use a REST client such as <a href=\"https://www.getpostman.com/\" target=\"_blank\">Postman</a> to test the <code>POST</code> methods in your API to create a new pet. Use the sample body below to send the <code>POST</code> request:\n </p>\n <pre>\n{\n \"type\" : \"cat\",\n \"price\" : 123.11\n}\n </pre>\n </body>\n</html>"
|
193
|
-
}
|
194
|
-
}
|
195
|
-
},
|
196
|
-
"requestTemplates": {
|
197
|
-
"application/json": "{\"statusCode\": 200}"
|
198
|
-
},
|
199
|
-
"passthroughBehavior": "when_no_match",
|
200
|
-
"type": "mock"
|
201
|
-
}
|
202
|
-
},
|
203
|
-
"post": {
|
204
|
-
"produces": [
|
205
|
-
"application/json"
|
206
283
|
],
|
207
284
|
"responses": {
|
208
285
|
"200": {
|
@@ -226,9 +303,12 @@ Options:
|
|
226
303
|
}
|
227
304
|
}
|
228
305
|
},
|
229
|
-
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets",
|
306
|
+
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{petId}",
|
230
307
|
"passthroughBehavior": "when_no_match",
|
231
|
-
"httpMethod": "
|
308
|
+
"httpMethod": "GET",
|
309
|
+
"requestParameters": {
|
310
|
+
"integration.request.path.petId": "method.request.path.petId"
|
311
|
+
},
|
232
312
|
"type": "http"
|
233
313
|
}
|
234
314
|
},
|
@@ -263,7 +343,7 @@ Options:
|
|
263
343
|
"default": {
|
264
344
|
"statusCode": "200",
|
265
345
|
"responseParameters": {
|
266
|
-
"method.response.header.Access-Control-Allow-Methods": "'
|
346
|
+
"method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'",
|
267
347
|
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
268
348
|
"method.response.header.Access-Control-Allow-Origin": "'*'"
|
269
349
|
}
|
@@ -286,118 +366,6 @@ Options:
|
|
286
366
|
}
|
287
367
|
```
|
288
368
|
|
289
|
-
### Ruby DSL
|
290
|
-
|
291
|
-
```ruby
|
292
|
-
rest_api do
|
293
|
-
swagger "2.0"
|
294
|
-
info do
|
295
|
-
version "2016-05-27T17:07:04Z"
|
296
|
-
title "PetStore"
|
297
|
-
end
|
298
|
-
host "p0dvujrb13.execute-api.ap-northeast-1.amazonaws.com"
|
299
|
-
basePath "/test"
|
300
|
-
schemes ["https"]
|
301
|
-
paths do
|
302
|
-
path "/" do
|
303
|
-
get do
|
304
|
-
consumes ["application/json"]
|
305
|
-
produces ["text/html"]
|
306
|
-
responses do
|
307
|
-
code 200 do
|
308
|
-
description "200 response"
|
309
|
-
headers(
|
310
|
-
{"Content-Type"=>{"type"=>"string"}})
|
311
|
-
end
|
312
|
-
end
|
313
|
-
amazon_apigateway_integration do
|
314
|
-
responses do
|
315
|
-
default do
|
316
|
-
statusCode 200
|
317
|
-
responseParameters(
|
318
|
-
{"method.response.header.Content-Type"=>"'text/html'"})
|
319
|
-
responseTemplates(
|
320
|
-
{"text/html"=>
|
321
|
-
"<html>\n <head>\n <style>\n body {\n color: #333;\n font-family: Sans-serif;\n max-width: 800px;\n margin: auto;\n }\n </style>\n </head>\n <body>\n <h1>Welcome to your Pet Store API</h1>\n <p>\n You have succesfully deployed your first API. You are seeing this HTML page because the <code>GET</code> method to the root resource of your API returns this content as a Mock integration.\n </p>\n <p>\n The Pet Store API contains the <code>/pets</code> and <code>/pets/{petId}</code> resources. By making a <a href=\"/$context.stage/pets/\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets</code> you can retrieve a list of Pets in your API. If you are looking for a specific pet, for example the pet with ID 1, you can make a <a href=\"/$context.stage/pets/1\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets/1</code>.\n </p>\n <p>\n You can use a REST client such as <a href=\"https://www.getpostman.com/\" target=\"_blank\">Postman</a> to test the <code>POST</code> methods in your API to create a new pet. Use the sample body below to send the <code>POST</code> request:\n </p>\n <pre>\n{\n \"type\" : \"cat\",\n \"price\" : 123.11\n}\n </pre>\n </body>\n</html>"})
|
322
|
-
end
|
323
|
-
end
|
324
|
-
requestTemplates(
|
325
|
-
{"application/json"=>"{\"statusCode\": 200}"})
|
326
|
-
passthroughBehavior "when_no_match"
|
327
|
-
type "mock"
|
328
|
-
end
|
329
|
-
end
|
330
|
-
post do
|
331
|
-
produces ["application/json"]
|
332
|
-
responses do
|
333
|
-
code 200 do
|
334
|
-
description "200 response"
|
335
|
-
schema do
|
336
|
-
ref "#/definitions/Empty"
|
337
|
-
end
|
338
|
-
headers(
|
339
|
-
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
340
|
-
end
|
341
|
-
end
|
342
|
-
amazon_apigateway_integration do
|
343
|
-
responses do
|
344
|
-
default do
|
345
|
-
statusCode 200
|
346
|
-
responseParameters(
|
347
|
-
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
348
|
-
end
|
349
|
-
end
|
350
|
-
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
351
|
-
passthroughBehavior "when_no_match"
|
352
|
-
httpMethod "POST"
|
353
|
-
type "http"
|
354
|
-
end
|
355
|
-
end
|
356
|
-
options do
|
357
|
-
consumes ["application/json"]
|
358
|
-
produces ["application/json"]
|
359
|
-
responses do
|
360
|
-
code 200 do
|
361
|
-
description "200 response"
|
362
|
-
schema do
|
363
|
-
ref "#/definitions/Empty"
|
364
|
-
end
|
365
|
-
headers(
|
366
|
-
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
367
|
-
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
368
|
-
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
369
|
-
end
|
370
|
-
end
|
371
|
-
amazon_apigateway_integration do
|
372
|
-
responses do
|
373
|
-
default do
|
374
|
-
statusCode 200
|
375
|
-
responseParameters(
|
376
|
-
{"method.response.header.Access-Control-Allow-Methods"=>"'POST,OPTIONS'",
|
377
|
-
"method.response.header.Access-Control-Allow-Headers"=>
|
378
|
-
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
379
|
-
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
380
|
-
end
|
381
|
-
end
|
382
|
-
requestTemplates(
|
383
|
-
{"application/json"=>"{\"statusCode\": 200}"})
|
384
|
-
passthroughBehavior "when_no_match"
|
385
|
-
type "mock"
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
definitions do
|
391
|
-
Empty do
|
392
|
-
type "object"
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
```
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
369
|
## Development
|
402
370
|
|
403
371
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/rapis.rb
CHANGED
data/lib/rapis/converter.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Rapis
|
2
2
|
class Converter
|
3
|
+
include Rapis::TemplateFunctions
|
4
|
+
|
3
5
|
CHANGE_SETS = {
|
4
6
|
'x-amazon-apigateway-integration' => 'amazon_apigateway_integration',
|
5
7
|
'$ref' => 'ref'
|
@@ -50,22 +52,13 @@ EOS
|
|
50
52
|
def to_dsl_key_conv
|
51
53
|
proc do |k|
|
52
54
|
k = k.to_s
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
elsif k =~ /^\d{3}$/
|
62
|
-
proc do |v, nested|
|
63
|
-
if nested
|
64
|
-
"code #{k} #{v}"
|
65
|
-
else
|
66
|
-
"code #{k}, #{v}"
|
67
|
-
end
|
68
|
-
end
|
55
|
+
case k
|
56
|
+
when %r{^\/}
|
57
|
+
item_key_proc k
|
58
|
+
when /^\d{3}$/
|
59
|
+
code_key_proc k
|
60
|
+
when 'parameters', 'api_key'
|
61
|
+
parameters_key_proc k
|
69
62
|
else
|
70
63
|
CHANGE_SETS.each { |f, t| k = k.gsub(f, t) }
|
71
64
|
k
|
@@ -73,6 +66,56 @@ EOS
|
|
73
66
|
end
|
74
67
|
end
|
75
68
|
|
69
|
+
def item_key_proc(k)
|
70
|
+
proc do |v, nested|
|
71
|
+
if nested
|
72
|
+
"item #{k.inspect} #{v}"
|
73
|
+
else
|
74
|
+
"item #{k.inspect}, #{v}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def code_key_proc(k)
|
80
|
+
proc do |v, nested|
|
81
|
+
if nested
|
82
|
+
"code #{k.to_s.inspect} #{v}"
|
83
|
+
else
|
84
|
+
"code #{k.to_s.inspect}, #{v}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def parameters_key_proc(k)
|
90
|
+
proc do |v, _|
|
91
|
+
if v =~ /\n(\s+)/
|
92
|
+
indent = Regexp.last_match(1)
|
93
|
+
v = instance_eval(v)
|
94
|
+
dsl = "#{k} do\n"
|
95
|
+
if v.is_a?(Array)
|
96
|
+
v.each do |param|
|
97
|
+
dsl << param_to_dsl(param, indent)
|
98
|
+
end
|
99
|
+
else
|
100
|
+
dsl << param_to_dsl(v, indent)
|
101
|
+
end
|
102
|
+
dsl << indent[2..-1] + "end\n"
|
103
|
+
else
|
104
|
+
"#{k} #{v}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def param_to_dsl(param, indent)
|
110
|
+
dsl = indent + "#{param['in']} #{param['name'].inspect} do\n"
|
111
|
+
param.each do |pk, pv|
|
112
|
+
next if %w(in name).include?(pk)
|
113
|
+
dsl << indent
|
114
|
+
dsl += pv.is_a?(String) ? " #{pk} #{pv.inspect}\n" : " #{pk} #{pv}\n"
|
115
|
+
end
|
116
|
+
dsl << indent + "end\n"
|
117
|
+
end
|
118
|
+
|
76
119
|
def to_dsl_value_conv
|
77
120
|
proc do |v|
|
78
121
|
if v.is_a?(String) && v =~ /\A(?:0|[1-9]\d*)\Z/
|
@@ -100,7 +143,7 @@ EOS
|
|
100
143
|
def to_h_value_conv
|
101
144
|
proc do |v|
|
102
145
|
case v
|
103
|
-
when Hash, Array
|
146
|
+
when Hash, Array, TrueClass, FalseClass
|
104
147
|
v
|
105
148
|
else
|
106
149
|
v.to_s
|
@@ -121,18 +164,11 @@ EOS
|
|
121
164
|
|
122
165
|
def define_template_func(scope)
|
123
166
|
scope.instance_eval(<<-EOS)
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
def code(key, value = nil, &block)
|
131
|
-
if block
|
132
|
-
value = Dslh::ScopeBlock.nest(binding, 'block', key)
|
133
|
-
end
|
134
|
-
@__hash__[key] = value
|
135
|
-
end
|
167
|
+
#{template_code_func}
|
168
|
+
#{template_item_func}
|
169
|
+
#{template_api_key_func}
|
170
|
+
#{template_params_func}
|
171
|
+
#{template_include_func}
|
136
172
|
EOS
|
137
173
|
end
|
138
174
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module Rapis
|
2
|
+
module TemplateFunctions
|
3
|
+
def template_params
|
4
|
+
%w(query header path formData body)
|
5
|
+
end
|
6
|
+
|
7
|
+
def template_include_func
|
8
|
+
<<-EOS
|
9
|
+
def _include(path, args = {})
|
10
|
+
instance_eval(File.read(path))
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def template_params_func
|
16
|
+
funcs = <<-EOS
|
17
|
+
def _param(name, i, block)
|
18
|
+
@__hash__['parameters'] << {
|
19
|
+
'name' => name,
|
20
|
+
'in' => i
|
21
|
+
}.merge(Dslh::ScopeBlock.nest(binding, 'block', name))
|
22
|
+
end
|
23
|
+
EOS
|
24
|
+
template_params.each do |i|
|
25
|
+
funcs << <<-EOS
|
26
|
+
def #{i}(name, value = nil, &block)
|
27
|
+
_param(name, #{i.inspect}, block)
|
28
|
+
end
|
29
|
+
EOS
|
30
|
+
end
|
31
|
+
<<-EOS
|
32
|
+
def parameters(value = nil, &block)
|
33
|
+
if value.nil?
|
34
|
+
@__hash__['parameters'] = []
|
35
|
+
|
36
|
+
#{funcs}
|
37
|
+
|
38
|
+
if block
|
39
|
+
value = instance_eval(&block)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
@__hash__['parameters'] = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def template_api_key_func
|
49
|
+
funcs = <<-EOS
|
50
|
+
def _api_key(name, i, block)
|
51
|
+
@__hash__['api_key'] = Dslh::ScopeBlock.nest(binding, 'block', name).merge({
|
52
|
+
'name' => name,
|
53
|
+
'in' => i
|
54
|
+
})
|
55
|
+
end
|
56
|
+
EOS
|
57
|
+
template_params.each do |i|
|
58
|
+
funcs << <<-EOS
|
59
|
+
def #{i}(name, value = nil, &block)
|
60
|
+
_api_key(name, #{i.inspect}, block)
|
61
|
+
end
|
62
|
+
EOS
|
63
|
+
end
|
64
|
+
<<-EOS
|
65
|
+
def api_key(value = nil, &block)
|
66
|
+
if value.nil?
|
67
|
+
@__hash__['api_key'] = []
|
68
|
+
|
69
|
+
#{funcs}
|
70
|
+
|
71
|
+
if block
|
72
|
+
value = instance_eval(&block)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
@__hash__['api_key'] = value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
|
81
|
+
def template_item_func
|
82
|
+
<<-EOS
|
83
|
+
def item(key, value = nil, &block)
|
84
|
+
if block
|
85
|
+
value = Dslh::ScopeBlock.nest(binding, 'block', key)
|
86
|
+
end
|
87
|
+
@__hash__[key] = value
|
88
|
+
end
|
89
|
+
EOS
|
90
|
+
end
|
91
|
+
|
92
|
+
def template_code_func
|
93
|
+
<<-EOS
|
94
|
+
def code(key, value = nil, &block)
|
95
|
+
if block
|
96
|
+
value = Dslh::ScopeBlock.nest(binding, 'block', key)
|
97
|
+
end
|
98
|
+
@__hash__[key] = value
|
99
|
+
end
|
100
|
+
EOS
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/rapis/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rapis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masashi Terui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/rapis/converter.rb
|
179
179
|
- lib/rapis/exceptions.rb
|
180
180
|
- lib/rapis/logger.rb
|
181
|
+
- lib/rapis/template_functions.rb
|
181
182
|
- lib/rapis/utils.rb
|
182
183
|
- lib/rapis/version.rb
|
183
184
|
- rapis.gemspec
|