rapis 0.1.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Apifile +262 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +408 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rapis +8 -0
- data/lib/rapis.rb +7 -0
- data/lib/rapis/actions.rb +102 -0
- data/lib/rapis/cli.rb +64 -0
- data/lib/rapis/client.rb +58 -0
- data/lib/rapis/converter.rb +124 -0
- data/lib/rapis/logger.rb +86 -0
- data/lib/rapis/utils.rb +38 -0
- data/lib/rapis/version.rb +3 -0
- data/rapis.gemspec +31 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba0204f8bd9c638122135f36d8b20615babf16c4
|
4
|
+
data.tar.gz: 24479a1fc8d7add31b313e8554986a1f9ca74a1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57562605e7c4e6ccd0ed2a4257ea2d3f43702eda0ddd375107a2e3cad52e81d89c5efadb6ef5a7fba27725640a7c89f4b2f0775c627f8d62da11821763ffa02a
|
7
|
+
data.tar.gz: 0d7536aef3fa961b79519c57dd25961d898ad013a7406569c2ca9beb29cf4df66f050739cbdd1fb9b918512936ff77101be2fd469322f0e818a68872c13645f4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Apifile
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
rest_api do
|
2
|
+
swagger "2.0"
|
3
|
+
info do
|
4
|
+
version "2016-05-27T17:07:04Z"
|
5
|
+
title "PetStore"
|
6
|
+
end
|
7
|
+
host "p0dvujrb13.execute-api.ap-northeast-1.amazonaws.com"
|
8
|
+
basePath "/test"
|
9
|
+
schemes ["https"]
|
10
|
+
paths do
|
11
|
+
path "/" do
|
12
|
+
get do
|
13
|
+
consumes ["application/json"]
|
14
|
+
produces ["text/html"]
|
15
|
+
responses do
|
16
|
+
code 200 do
|
17
|
+
description "200 response"
|
18
|
+
headers(
|
19
|
+
{"Content-Type"=>{"type"=>"string"}})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
amazon_apigateway_integration do
|
23
|
+
type "mock"
|
24
|
+
responses do
|
25
|
+
default do
|
26
|
+
statusCode 200
|
27
|
+
responseParameters(
|
28
|
+
{"method.response.header.Content-Type"=>"'text/html'"})
|
29
|
+
responseTemplates(
|
30
|
+
{"text/html"=>
|
31
|
+
"<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>"})
|
32
|
+
end
|
33
|
+
end
|
34
|
+
requestTemplates(
|
35
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
36
|
+
passthroughBehavior "when_no_match"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
post do
|
40
|
+
produces ["application/json"]
|
41
|
+
responses do
|
42
|
+
code 200 do
|
43
|
+
description "200 response"
|
44
|
+
schema do
|
45
|
+
ref "#/definitions/Empty"
|
46
|
+
end
|
47
|
+
headers(
|
48
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
amazon_apigateway_integration do
|
52
|
+
type "http"
|
53
|
+
responses do
|
54
|
+
default do
|
55
|
+
statusCode 200
|
56
|
+
responseParameters(
|
57
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
58
|
+
end
|
59
|
+
end
|
60
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
61
|
+
passthroughBehavior "when_no_match"
|
62
|
+
httpMethod "POST"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
options do
|
66
|
+
consumes ["application/json"]
|
67
|
+
produces ["application/json"]
|
68
|
+
responses do
|
69
|
+
code 200 do
|
70
|
+
description "200 response"
|
71
|
+
schema do
|
72
|
+
ref "#/definitions/Empty"
|
73
|
+
end
|
74
|
+
headers(
|
75
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
76
|
+
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
77
|
+
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
amazon_apigateway_integration do
|
81
|
+
type "mock"
|
82
|
+
responses do
|
83
|
+
default do
|
84
|
+
statusCode 200
|
85
|
+
responseParameters(
|
86
|
+
{"method.response.header.Access-Control-Allow-Methods"=>"'POST,OPTIONS'",
|
87
|
+
"method.response.header.Access-Control-Allow-Headers"=>
|
88
|
+
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
89
|
+
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
90
|
+
end
|
91
|
+
end
|
92
|
+
requestTemplates(
|
93
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
94
|
+
passthroughBehavior "when_no_match"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
path "/pets" do
|
99
|
+
get do
|
100
|
+
produces ["application/json"]
|
101
|
+
parameters [
|
102
|
+
{"name"=>"type", "in"=>"query", "required"=>false, "type"=>"string"},
|
103
|
+
{"name"=>"page", "in"=>"query", "required"=>false, "type"=>"string"}
|
104
|
+
]
|
105
|
+
responses do
|
106
|
+
code 200 do
|
107
|
+
description "200 response"
|
108
|
+
schema do
|
109
|
+
ref "#/definitions/Empty"
|
110
|
+
end
|
111
|
+
headers(
|
112
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
113
|
+
end
|
114
|
+
end
|
115
|
+
amazon_apigateway_integration do
|
116
|
+
type "http"
|
117
|
+
responses do
|
118
|
+
default do
|
119
|
+
statusCode 200
|
120
|
+
responseParameters(
|
121
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
122
|
+
end
|
123
|
+
end
|
124
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
125
|
+
passthroughBehavior "when_no_match"
|
126
|
+
httpMethod "GET"
|
127
|
+
requestParameters(
|
128
|
+
{"integration.request.querystring.page"=>"method.request.querystring.page",
|
129
|
+
"integration.request.querystring.type"=>"method.request.querystring.type"})
|
130
|
+
end
|
131
|
+
end
|
132
|
+
post do
|
133
|
+
produces ["application/json"]
|
134
|
+
responses do
|
135
|
+
code 200 do
|
136
|
+
description "200 response"
|
137
|
+
schema do
|
138
|
+
ref "#/definitions/Empty"
|
139
|
+
end
|
140
|
+
headers(
|
141
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
amazon_apigateway_integration do
|
145
|
+
type "http"
|
146
|
+
responses do
|
147
|
+
default do
|
148
|
+
statusCode 200
|
149
|
+
responseParameters(
|
150
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
154
|
+
passthroughBehavior "when_no_match"
|
155
|
+
httpMethod "POST"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
options do
|
159
|
+
consumes ["application/json"]
|
160
|
+
produces ["application/json"]
|
161
|
+
responses do
|
162
|
+
code 200 do
|
163
|
+
description "200 response"
|
164
|
+
schema do
|
165
|
+
ref "#/definitions/Empty"
|
166
|
+
end
|
167
|
+
headers(
|
168
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
169
|
+
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
170
|
+
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
171
|
+
end
|
172
|
+
end
|
173
|
+
amazon_apigateway_integration do
|
174
|
+
type "mock"
|
175
|
+
responses do
|
176
|
+
default do
|
177
|
+
statusCode 200
|
178
|
+
responseParameters(
|
179
|
+
{"method.response.header.Access-Control-Allow-Methods"=>"'POST,GET,OPTIONS'",
|
180
|
+
"method.response.header.Access-Control-Allow-Headers"=>
|
181
|
+
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
182
|
+
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
183
|
+
end
|
184
|
+
end
|
185
|
+
requestTemplates(
|
186
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
187
|
+
passthroughBehavior "when_no_match"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
path "/pets/{petId}" do
|
192
|
+
get do
|
193
|
+
produces ["application/json"]
|
194
|
+
parameters [
|
195
|
+
{"name"=>"petId", "in"=>"path", "required"=>true, "type"=>"string"}
|
196
|
+
]
|
197
|
+
responses do
|
198
|
+
code 200 do
|
199
|
+
description "200 response"
|
200
|
+
schema do
|
201
|
+
ref "#/definitions/Empty"
|
202
|
+
end
|
203
|
+
headers(
|
204
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
205
|
+
end
|
206
|
+
end
|
207
|
+
amazon_apigateway_integration do
|
208
|
+
type "http"
|
209
|
+
responses do
|
210
|
+
default do
|
211
|
+
statusCode 200
|
212
|
+
responseParameters(
|
213
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
214
|
+
end
|
215
|
+
end
|
216
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{petId}"
|
217
|
+
passthroughBehavior "when_no_match"
|
218
|
+
httpMethod "GET"
|
219
|
+
requestParameters(
|
220
|
+
{"integration.request.path.petId"=>"method.request.path.petId"})
|
221
|
+
end
|
222
|
+
end
|
223
|
+
options do
|
224
|
+
consumes ["application/json"]
|
225
|
+
produces ["application/json"]
|
226
|
+
responses do
|
227
|
+
code 200 do
|
228
|
+
description "200 response"
|
229
|
+
schema do
|
230
|
+
ref "#/definitions/Empty"
|
231
|
+
end
|
232
|
+
headers(
|
233
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
234
|
+
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
235
|
+
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
236
|
+
end
|
237
|
+
end
|
238
|
+
amazon_apigateway_integration do
|
239
|
+
type "mock"
|
240
|
+
responses do
|
241
|
+
default do
|
242
|
+
statusCode 200
|
243
|
+
responseParameters(
|
244
|
+
{"method.response.header.Access-Control-Allow-Methods"=>"'GET,OPTIONS'",
|
245
|
+
"method.response.header.Access-Control-Allow-Headers"=>
|
246
|
+
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
247
|
+
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
248
|
+
end
|
249
|
+
end
|
250
|
+
requestTemplates(
|
251
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
252
|
+
passthroughBehavior "when_no_match"
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
definitions do
|
258
|
+
Empty do
|
259
|
+
type "object"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Masashi Terui
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,408 @@
|
|
1
|
+
# Rapis
|
2
|
+
|
3
|
+
Swagger as Ruby DSL and its deployment tool for Amazon API Gateway
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rapis'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rapis
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```sh
|
24
|
+
Commands:
|
25
|
+
rapis apply -r, --rest-api=REST_API # Apply the REST API configuration
|
26
|
+
rapis convert -F, --format=FORMAT # Convert the REST API configuration to the specified format
|
27
|
+
rapis create # Create REST API
|
28
|
+
rapis deploy -r, --rest-api=REST_API -s, --stage=STAGE # Deploy the current REST API configuration to the stage
|
29
|
+
rapis diff -r, --rest-api=REST_API -s, --stage=STAGE # Diff the local configuration and the remote configuration
|
30
|
+
rapis export -r, --rest-api=REST_API -s, --stage=STAGE # Export the configuration as Ruby DSL
|
31
|
+
rapis help [COMMAND] # Describe available commands or one specific command
|
32
|
+
rapis list # List the REST APIs and the stages
|
33
|
+
|
34
|
+
Options:
|
35
|
+
-f, [--file=FILE] # Configuration file
|
36
|
+
# Default: Apifile
|
37
|
+
```
|
38
|
+
|
39
|
+
## Commands
|
40
|
+
|
41
|
+
### create
|
42
|
+
Create REST API
|
43
|
+
|
44
|
+
```sh
|
45
|
+
Usage:
|
46
|
+
rapis create
|
47
|
+
|
48
|
+
Options:
|
49
|
+
-d, [--description=DESCRIPTION] # Description
|
50
|
+
-f, [--file=FILE] # Configuration file
|
51
|
+
# Default: Apifile
|
52
|
+
```
|
53
|
+
|
54
|
+
### apply
|
55
|
+
Apply the REST API configuration
|
56
|
+
|
57
|
+
```sh
|
58
|
+
Usage:
|
59
|
+
rapis apply -r, --rest-api=REST_API
|
60
|
+
|
61
|
+
Options:
|
62
|
+
-r, --rest-api=REST_API # The id of the REST API
|
63
|
+
-f, [--file=FILE] # Configuration file
|
64
|
+
# Default: Apifile
|
65
|
+
```
|
66
|
+
|
67
|
+
### convert
|
68
|
+
Convert the REST API configuration to the specified format
|
69
|
+
|
70
|
+
```sh
|
71
|
+
Usage:
|
72
|
+
rapis convert -F, --format=FORMAT
|
73
|
+
|
74
|
+
Options:
|
75
|
+
-F, --format=FORMAT # Output format # accepts json, yaml
|
76
|
+
-o, [--output=OUTPUT] # Output path
|
77
|
+
-f, [--file=FILE] # Configuration file
|
78
|
+
# Default: Apifile
|
79
|
+
|
80
|
+
```
|
81
|
+
|
82
|
+
### deploy
|
83
|
+
Deploy the current REST API configuration to the stage
|
84
|
+
|
85
|
+
```sh
|
86
|
+
Usage:
|
87
|
+
rapis deploy -r, --rest-api=REST_API -s, --stage=STAGE
|
88
|
+
|
89
|
+
Options:
|
90
|
+
-r, --rest-api=REST_API # The id of the REST API
|
91
|
+
-s, --stage=STAGE # The name of the stage
|
92
|
+
-d, [--description=DESCRIPTION] # The description for the deployment
|
93
|
+
-D, [--stage-description=STAGE_DESCRIPTION] # The description of the stage
|
94
|
+
-c, [--cache=CACHE] # Size of the cache cluster # accepts 0.5, 1.6, 6.1, 13.5, 28.4, 58.2, 118, 237
|
95
|
+
# Default: 0.0
|
96
|
+
-v, [--variables=key:value] # A map that defines the stage variables
|
97
|
+
-f, [--file=FILE] # Configuration file
|
98
|
+
# Default: Apifile
|
99
|
+
```
|
100
|
+
|
101
|
+
### export
|
102
|
+
Export the configuration as Ruby DSL
|
103
|
+
|
104
|
+
```sh
|
105
|
+
Usage:
|
106
|
+
rapis export -r, --rest-api=REST_API -s, --stage=STAGE
|
107
|
+
|
108
|
+
Options:
|
109
|
+
-r, --rest-api=REST_API # The id of the REST API
|
110
|
+
-s, --stage=STAGE # The name of the stage
|
111
|
+
-w, [--write], [--no-write] # Write the configuration to the file
|
112
|
+
-f, [--file=FILE] # Configuration file
|
113
|
+
# Default: Apifile
|
114
|
+
```
|
115
|
+
|
116
|
+
### List
|
117
|
+
List the REST APIs and the stages
|
118
|
+
|
119
|
+
```sh
|
120
|
+
Usage:
|
121
|
+
rapis list
|
122
|
+
|
123
|
+
Options:
|
124
|
+
-V, [--verbose], [--no-verbose] # Verbose mode
|
125
|
+
-f, [--file=FILE] # Configuration file
|
126
|
+
# Default: Apifile
|
127
|
+
```
|
128
|
+
|
129
|
+
### diff
|
130
|
+
Diff the local configuration and the remote configuration
|
131
|
+
|
132
|
+
```sh
|
133
|
+
Usage:
|
134
|
+
rapis diff -r, --rest-api=REST_API -s, --stage=STAGE
|
135
|
+
|
136
|
+
Options:
|
137
|
+
-r, --rest-api=REST_API # The id of the REST API
|
138
|
+
-s, --stage=STAGE # The name of the stage
|
139
|
+
-f, [--file=FILE] # Configuration file
|
140
|
+
# Default: Apifile
|
141
|
+
```
|
142
|
+
|
143
|
+
## Sample
|
144
|
+
|
145
|
+
### JSON
|
146
|
+
|
147
|
+
```json
|
148
|
+
{
|
149
|
+
"swagger": "2.0",
|
150
|
+
"info": {
|
151
|
+
"version": "2016-05-27T17:07:04Z",
|
152
|
+
"title": "PetStore"
|
153
|
+
},
|
154
|
+
"host": "p0dvujrb13.execute-api.ap-northeast-1.amazonaws.com",
|
155
|
+
"basePath": "/test",
|
156
|
+
"schemes": [
|
157
|
+
"https"
|
158
|
+
],
|
159
|
+
"paths": {
|
160
|
+
"/": {
|
161
|
+
"get": {
|
162
|
+
"consumes": [
|
163
|
+
"application/json"
|
164
|
+
],
|
165
|
+
"produces": [
|
166
|
+
"text/html"
|
167
|
+
],
|
168
|
+
"responses": {
|
169
|
+
"200": {
|
170
|
+
"description": "200 response",
|
171
|
+
"headers": {
|
172
|
+
"Content-Type": {
|
173
|
+
"type": "string"
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
},
|
178
|
+
"x-amazon-apigateway-integration": {
|
179
|
+
"responses": {
|
180
|
+
"default": {
|
181
|
+
"statusCode": "200",
|
182
|
+
"responseParameters": {
|
183
|
+
"method.response.header.Content-Type": "'text/html'"
|
184
|
+
},
|
185
|
+
"responseTemplates": {
|
186
|
+
"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>"
|
187
|
+
}
|
188
|
+
}
|
189
|
+
},
|
190
|
+
"requestTemplates": {
|
191
|
+
"application/json": "{\"statusCode\": 200}"
|
192
|
+
},
|
193
|
+
"passthroughBehavior": "when_no_match",
|
194
|
+
"type": "mock"
|
195
|
+
}
|
196
|
+
},
|
197
|
+
"post": {
|
198
|
+
"produces": [
|
199
|
+
"application/json"
|
200
|
+
],
|
201
|
+
"responses": {
|
202
|
+
"200": {
|
203
|
+
"description": "200 response",
|
204
|
+
"schema": {
|
205
|
+
"$ref": "#/definitions/Empty"
|
206
|
+
},
|
207
|
+
"headers": {
|
208
|
+
"Access-Control-Allow-Origin": {
|
209
|
+
"type": "string"
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
},
|
214
|
+
"x-amazon-apigateway-integration": {
|
215
|
+
"responses": {
|
216
|
+
"default": {
|
217
|
+
"statusCode": "200",
|
218
|
+
"responseParameters": {
|
219
|
+
"method.response.header.Access-Control-Allow-Origin": "'*'"
|
220
|
+
}
|
221
|
+
}
|
222
|
+
},
|
223
|
+
"uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets",
|
224
|
+
"passthroughBehavior": "when_no_match",
|
225
|
+
"httpMethod": "POST",
|
226
|
+
"type": "http"
|
227
|
+
}
|
228
|
+
},
|
229
|
+
"options": {
|
230
|
+
"consumes": [
|
231
|
+
"application/json"
|
232
|
+
],
|
233
|
+
"produces": [
|
234
|
+
"application/json"
|
235
|
+
],
|
236
|
+
"responses": {
|
237
|
+
"200": {
|
238
|
+
"description": "200 response",
|
239
|
+
"schema": {
|
240
|
+
"$ref": "#/definitions/Empty"
|
241
|
+
},
|
242
|
+
"headers": {
|
243
|
+
"Access-Control-Allow-Origin": {
|
244
|
+
"type": "string"
|
245
|
+
},
|
246
|
+
"Access-Control-Allow-Methods": {
|
247
|
+
"type": "string"
|
248
|
+
},
|
249
|
+
"Access-Control-Allow-Headers": {
|
250
|
+
"type": "string"
|
251
|
+
}
|
252
|
+
}
|
253
|
+
}
|
254
|
+
},
|
255
|
+
"x-amazon-apigateway-integration": {
|
256
|
+
"responses": {
|
257
|
+
"default": {
|
258
|
+
"statusCode": "200",
|
259
|
+
"responseParameters": {
|
260
|
+
"method.response.header.Access-Control-Allow-Methods": "'POST,OPTIONS'",
|
261
|
+
"method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
262
|
+
"method.response.header.Access-Control-Allow-Origin": "'*'"
|
263
|
+
}
|
264
|
+
}
|
265
|
+
},
|
266
|
+
"requestTemplates": {
|
267
|
+
"application/json": "{\"statusCode\": 200}"
|
268
|
+
},
|
269
|
+
"passthroughBehavior": "when_no_match",
|
270
|
+
"type": "mock"
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}
|
274
|
+
},
|
275
|
+
"definitions": {
|
276
|
+
"Empty": {
|
277
|
+
"type": "object"
|
278
|
+
}
|
279
|
+
}
|
280
|
+
}
|
281
|
+
```
|
282
|
+
|
283
|
+
### Ruby DSL
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
rest_api do
|
287
|
+
swagger "2.0"
|
288
|
+
info do
|
289
|
+
version "2016-05-27T17:07:04Z"
|
290
|
+
title "PetStore"
|
291
|
+
end
|
292
|
+
host "p0dvujrb13.execute-api.ap-northeast-1.amazonaws.com"
|
293
|
+
basePath "/test"
|
294
|
+
schemes ["https"]
|
295
|
+
paths do
|
296
|
+
path "/" do
|
297
|
+
get do
|
298
|
+
consumes ["application/json"]
|
299
|
+
produces ["text/html"]
|
300
|
+
responses do
|
301
|
+
code 200 do
|
302
|
+
description "200 response"
|
303
|
+
headers(
|
304
|
+
{"Content-Type"=>{"type"=>"string"}})
|
305
|
+
end
|
306
|
+
end
|
307
|
+
amazon_apigateway_integration do
|
308
|
+
responses do
|
309
|
+
default do
|
310
|
+
statusCode 200
|
311
|
+
responseParameters(
|
312
|
+
{"method.response.header.Content-Type"=>"'text/html'"})
|
313
|
+
responseTemplates(
|
314
|
+
{"text/html"=>
|
315
|
+
"<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>"})
|
316
|
+
end
|
317
|
+
end
|
318
|
+
requestTemplates(
|
319
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
320
|
+
passthroughBehavior "when_no_match"
|
321
|
+
type "mock"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
post do
|
325
|
+
produces ["application/json"]
|
326
|
+
responses do
|
327
|
+
code 200 do
|
328
|
+
description "200 response"
|
329
|
+
schema do
|
330
|
+
ref "#/definitions/Empty"
|
331
|
+
end
|
332
|
+
headers(
|
333
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"}})
|
334
|
+
end
|
335
|
+
end
|
336
|
+
amazon_apigateway_integration do
|
337
|
+
responses do
|
338
|
+
default do
|
339
|
+
statusCode 200
|
340
|
+
responseParameters(
|
341
|
+
{"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
342
|
+
end
|
343
|
+
end
|
344
|
+
uri "http://petstore-demo-endpoint.execute-api.com/petstore/pets"
|
345
|
+
passthroughBehavior "when_no_match"
|
346
|
+
httpMethod "POST"
|
347
|
+
type "http"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
options do
|
351
|
+
consumes ["application/json"]
|
352
|
+
produces ["application/json"]
|
353
|
+
responses do
|
354
|
+
code 200 do
|
355
|
+
description "200 response"
|
356
|
+
schema do
|
357
|
+
ref "#/definitions/Empty"
|
358
|
+
end
|
359
|
+
headers(
|
360
|
+
{"Access-Control-Allow-Origin"=>{"type"=>"string"},
|
361
|
+
"Access-Control-Allow-Methods"=>{"type"=>"string"},
|
362
|
+
"Access-Control-Allow-Headers"=>{"type"=>"string"}})
|
363
|
+
end
|
364
|
+
end
|
365
|
+
amazon_apigateway_integration do
|
366
|
+
responses do
|
367
|
+
default do
|
368
|
+
statusCode 200
|
369
|
+
responseParameters(
|
370
|
+
{"method.response.header.Access-Control-Allow-Methods"=>"'POST,OPTIONS'",
|
371
|
+
"method.response.header.Access-Control-Allow-Headers"=>
|
372
|
+
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
|
373
|
+
"method.response.header.Access-Control-Allow-Origin"=>"'*'"})
|
374
|
+
end
|
375
|
+
end
|
376
|
+
requestTemplates(
|
377
|
+
{"application/json"=>"{\"statusCode\": 200}"})
|
378
|
+
passthroughBehavior "when_no_match"
|
379
|
+
type "mock"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
definitions do
|
385
|
+
Empty do
|
386
|
+
type "object"
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
```
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
## Development
|
396
|
+
|
397
|
+
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.
|
398
|
+
|
399
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
400
|
+
|
401
|
+
## Contributing
|
402
|
+
|
403
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/marcy-terui/rapis.
|
404
|
+
|
405
|
+
|
406
|
+
## License
|
407
|
+
|
408
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|