api_gateway_dsl 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 +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/.simplecov +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +40 -0
- data/Rakefile +4 -0
- data/api_gateway_dsl.gemspec +30 -0
- data/bin/api_gateway_dsl +32 -0
- data/lib/api_gateway_dsl.rb +26 -0
- data/lib/api_gateway_dsl/context.rb +13 -0
- data/lib/api_gateway_dsl/document.rb +41 -0
- data/lib/api_gateway_dsl/dsl/document_node.rb +46 -0
- data/lib/api_gateway_dsl/dsl/integration_node.rb +32 -0
- data/lib/api_gateway_dsl/dsl/operation_node.rb +66 -0
- data/lib/api_gateway_dsl/dsl/response_node.rb +24 -0
- data/lib/api_gateway_dsl/integration.rb +47 -0
- data/lib/api_gateway_dsl/integration/collection.rb +7 -0
- data/lib/api_gateway_dsl/integration/http.rb +26 -0
- data/lib/api_gateway_dsl/integration/http_proxy.rb +29 -0
- data/lib/api_gateway_dsl/integration/lambda.rb +38 -0
- data/lib/api_gateway_dsl/integration/mock.rb +33 -0
- data/lib/api_gateway_dsl/mapping.rb +68 -0
- data/lib/api_gateway_dsl/mapping/collection.rb +15 -0
- data/lib/api_gateway_dsl/operation.rb +70 -0
- data/lib/api_gateway_dsl/operation/collection.rb +62 -0
- data/lib/api_gateway_dsl/parameter.rb +24 -0
- data/lib/api_gateway_dsl/parameter/body.rb +21 -0
- data/lib/api_gateway_dsl/parameter/collection.rb +7 -0
- data/lib/api_gateway_dsl/parameter/header.rb +13 -0
- data/lib/api_gateway_dsl/parameter/path.rb +14 -0
- data/lib/api_gateway_dsl/parameter/query.rb +13 -0
- data/lib/api_gateway_dsl/parameter/simple.rb +23 -0
- data/lib/api_gateway_dsl/response.rb +53 -0
- data/lib/api_gateway_dsl/response/collection.rb +19 -0
- data/lib/api_gateway_dsl/response_header.rb +19 -0
- data/lib/api_gateway_dsl/response_header/collection.rb +11 -0
- data/lib/api_gateway_dsl/response_integration.rb +30 -0
- data/lib/api_gateway_dsl/response_integration/collection.rb +11 -0
- data/lib/api_gateway_dsl/template.rb +48 -0
- data/lib/api_gateway_dsl/template/collection.rb +32 -0
- data/lib/api_gateway_dsl/version.rb +5 -0
- data/spec/api_gateway_dsl/document_spec.rb +20 -0
- data/spec/fixtures/greedy_http_proxy/README.md +69 -0
- data/spec/fixtures/greedy_http_proxy/index.rb +13 -0
- data/spec/fixtures/greedy_http_proxy/index.yml +35 -0
- data/spec/fixtures/greedy_http_proxy/pets/proxy.rb +9 -0
- data/spec/fixtures/http_get/README.md +150 -0
- data/spec/fixtures/http_get/index.rb +17 -0
- data/spec/fixtures/http_get/index.yml +74 -0
- data/spec/fixtures/http_get/pets/get.rb +15 -0
- data/spec/fixtures/http_get/pets/response/200.vtl +1 -0
- data/spec/fixtures/http_get/pets/response/200.yml +4 -0
- data/spec/fixtures/http_get/pets/response/500.vtl +3 -0
- data/spec/fixtures/http_get/pets/response/500.yml +4 -0
- data/spec/fixtures/lambda_post/README.md +185 -0
- data/spec/fixtures/lambda_post/index.rb +18 -0
- data/spec/fixtures/lambda_post/index.yml +89 -0
- data/spec/fixtures/lambda_post/pets/post.rb +11 -0
- data/spec/fixtures/lambda_post/pets/request/body.vtl +9 -0
- data/spec/fixtures/lambda_post/pets/request/body.yml +7 -0
- data/spec/fixtures/lambda_post/pets/response/201.vtl +1 -0
- data/spec/fixtures/lambda_post/pets/response/201.yml +1 -0
- data/spec/fixtures/lambda_post/pets/response/500.vtl +3 -0
- data/spec/fixtures/lambda_post/pets/response/500.yml +4 -0
- data/spec/fixtures/lambda_post_with_cors/README.md +193 -0
- data/spec/fixtures/lambda_post_with_cors/index.rb +9 -0
- data/spec/fixtures/lambda_post_with_cors/index.yml +106 -0
- data/spec/fixtures/lambda_post_with_cors/pets/post.rb +11 -0
- data/spec/fixtures/lambda_post_with_cors/pets/request/body.vtl +9 -0
- data/spec/fixtures/lambda_post_with_cors/pets/request/body.yml +7 -0
- data/spec/fixtures/lambda_post_with_cors/pets/response/201.vtl +1 -0
- data/spec/fixtures/lambda_post_with_cors/pets/response/201.yml +1 -0
- data/spec/fixtures/lambda_post_with_cors/pets/response/500.vtl +3 -0
- data/spec/fixtures/lambda_post_with_cors/pets/response/500.yml +4 -0
- data/spec/fixtures/markdown.rb +73 -0
- data/spec/fixtures/mock_options/README.md +80 -0
- data/spec/fixtures/mock_options/index.rb +15 -0
- data/spec/fixtures/mock_options/index.yml +44 -0
- data/spec/fixtures/mock_options/pets/options.rb +9 -0
- data/spec/spec_helper.rb +5 -0
- metadata +265 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
# GET Endpoint with HTTP Integration
|
2
|
+
|
3
|
+
This example demonstrates how to specify a GET endpoint for the path `/pets` which integrates with an HTTP
|
4
|
+
downstream service at `https://petstore.example.com`.
|
5
|
+
|
6
|
+
## Configuration
|
7
|
+
|
8
|
+
* The request accepts a query string parameter `q` and a header `Accept-Language` which are passed through to the
|
9
|
+
downstream service.
|
10
|
+
* The endpoint responds with a `200` if the downstream service responds with a `200` and passes through the response
|
11
|
+
header `Content-Language` from the downstream service to the client.
|
12
|
+
* The endpoint responds with a `500` otherwise.
|
13
|
+
|
14
|
+
## Given
|
15
|
+
|
16
|
+
* [`index.rb`](index.rb) (skipped for readability)
|
17
|
+
|
18
|
+
* [`pets/get.rb`](pets/get.rb)
|
19
|
+
|
20
|
+
```rb
|
21
|
+
GET '/pets' do
|
22
|
+
query 'q'
|
23
|
+
header 'Accept-Language'
|
24
|
+
|
25
|
+
HTTP_GET 'https://petstore.example.com' do
|
26
|
+
query 'q'
|
27
|
+
header 'Accept-Language'
|
28
|
+
end
|
29
|
+
|
30
|
+
RESPONSE 200, /^200$/ do
|
31
|
+
header 'Content-Language'
|
32
|
+
end
|
33
|
+
|
34
|
+
RESPONSE 500
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
* [`pets/response/200.vtl`](pets/response/200.vtl)
|
39
|
+
|
40
|
+
```vtl
|
41
|
+
$input.path('$')
|
42
|
+
```
|
43
|
+
|
44
|
+
* [`pets/response/200.yml`](pets/response/200.yml)
|
45
|
+
|
46
|
+
```yml
|
47
|
+
type: "array"
|
48
|
+
items:
|
49
|
+
type: "object"
|
50
|
+
properties: {}
|
51
|
+
```
|
52
|
+
|
53
|
+
* [`pets/response/500.vtl`](pets/response/500.vtl)
|
54
|
+
|
55
|
+
```vtl
|
56
|
+
{
|
57
|
+
"message": "Something went wrong!"
|
58
|
+
}
|
59
|
+
```
|
60
|
+
|
61
|
+
* [`pets/response/500.yml`](pets/response/500.yml)
|
62
|
+
|
63
|
+
```yml
|
64
|
+
type: "object"
|
65
|
+
properties:
|
66
|
+
message:
|
67
|
+
type: "string"
|
68
|
+
```
|
69
|
+
|
70
|
+
## Generates
|
71
|
+
|
72
|
+
* [`index.yml`](index.yml)
|
73
|
+
|
74
|
+
```yml
|
75
|
+
swagger: "2.0"
|
76
|
+
info:
|
77
|
+
version: "1.2.3"
|
78
|
+
title: "GET Endpoint with HTTP Integration"
|
79
|
+
description: |
|
80
|
+
This example demonstrates how to specify a GET endpoint for the path `/pets` which integrates with an HTTP
|
81
|
+
downstream service at `https://petstore.example.com`.
|
82
|
+
|
83
|
+
## Configuration
|
84
|
+
|
85
|
+
* The request accepts a query string parameter `q` and a header `Accept-Language` which are passed through to the
|
86
|
+
downstream service.
|
87
|
+
* The endpoint responds with a `200` if the downstream service responds with a `200` and passes through the response
|
88
|
+
header `Content-Language` from the downstream service to the client.
|
89
|
+
* The endpoint responds with a `500` otherwise.
|
90
|
+
host: "api.example.com"
|
91
|
+
schemes:
|
92
|
+
- "https"
|
93
|
+
paths:
|
94
|
+
/pets:
|
95
|
+
get:
|
96
|
+
produces:
|
97
|
+
- "application/json"
|
98
|
+
parameters:
|
99
|
+
- name: "q"
|
100
|
+
in: "query"
|
101
|
+
required: false
|
102
|
+
type: "string"
|
103
|
+
- name: "Accept-Language"
|
104
|
+
in: "header"
|
105
|
+
required: false
|
106
|
+
type: "string"
|
107
|
+
responses:
|
108
|
+
'200':
|
109
|
+
description: "200 response"
|
110
|
+
schema:
|
111
|
+
type: "array"
|
112
|
+
items:
|
113
|
+
type: "object"
|
114
|
+
properties: {}
|
115
|
+
headers:
|
116
|
+
Content-Language:
|
117
|
+
type: "string"
|
118
|
+
'500':
|
119
|
+
description: "500 response"
|
120
|
+
schema:
|
121
|
+
type: "object"
|
122
|
+
properties:
|
123
|
+
message:
|
124
|
+
type: "string"
|
125
|
+
x-amazon-apigateway-integration:
|
126
|
+
responses:
|
127
|
+
default:
|
128
|
+
statusCode: "500"
|
129
|
+
responseTemplates:
|
130
|
+
application/json: |
|
131
|
+
{
|
132
|
+
"message": "Something went wrong!"
|
133
|
+
}
|
134
|
+
^200$:
|
135
|
+
statusCode: "200"
|
136
|
+
responseParameters:
|
137
|
+
method.response.header.Content-Language: "integration.response.header.Content-Language"
|
138
|
+
responseTemplates:
|
139
|
+
application/json: |
|
140
|
+
$input.path('$')
|
141
|
+
requestParameters:
|
142
|
+
integration.request.querystring.q: "method.request.querystring.q"
|
143
|
+
integration.request.header.Accept-Language: "method.request.header.Accept-Language"
|
144
|
+
uri: "https://petstore.example.com"
|
145
|
+
passthroughBehavior: "WHEN_NO_TEMPLATES"
|
146
|
+
httpMethod: "GET"
|
147
|
+
contentHandling: "CONVERT_TO_TEXT"
|
148
|
+
type: "http"
|
149
|
+
```
|
150
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
title 'GET Endpoint with HTTP Integration'
|
2
|
+
version '1.2.3'
|
3
|
+
description <<-EOS
|
4
|
+
This example demonstrates how to specify a GET endpoint for the path `/pets` which integrates with an HTTP
|
5
|
+
downstream service at `https://petstore.example.com`.
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
* The request accepts a query string parameter `q` and a header `Accept-Language` which are passed through to the
|
10
|
+
downstream service.
|
11
|
+
* The endpoint responds with a `200` if the downstream service responds with a `200` and passes through the response
|
12
|
+
header `Content-Language` from the downstream service to the client.
|
13
|
+
* The endpoint responds with a `500` otherwise.
|
14
|
+
EOS
|
15
|
+
|
16
|
+
host 'api.example.com'
|
17
|
+
schemes 'https'
|
@@ -0,0 +1,74 @@
|
|
1
|
+
swagger: "2.0"
|
2
|
+
info:
|
3
|
+
version: "1.2.3"
|
4
|
+
title: "GET Endpoint with HTTP Integration"
|
5
|
+
description: |
|
6
|
+
This example demonstrates how to specify a GET endpoint for the path `/pets` which integrates with an HTTP
|
7
|
+
downstream service at `https://petstore.example.com`.
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
* The request accepts a query string parameter `q` and a header `Accept-Language` which are passed through to the
|
12
|
+
downstream service.
|
13
|
+
* The endpoint responds with a `200` if the downstream service responds with a `200` and passes through the response
|
14
|
+
header `Content-Language` from the downstream service to the client.
|
15
|
+
* The endpoint responds with a `500` otherwise.
|
16
|
+
host: "api.example.com"
|
17
|
+
schemes:
|
18
|
+
- "https"
|
19
|
+
paths:
|
20
|
+
/pets:
|
21
|
+
get:
|
22
|
+
produces:
|
23
|
+
- "application/json"
|
24
|
+
parameters:
|
25
|
+
- name: "q"
|
26
|
+
in: "query"
|
27
|
+
required: false
|
28
|
+
type: "string"
|
29
|
+
- name: "Accept-Language"
|
30
|
+
in: "header"
|
31
|
+
required: false
|
32
|
+
type: "string"
|
33
|
+
responses:
|
34
|
+
'200':
|
35
|
+
description: "200 response"
|
36
|
+
schema:
|
37
|
+
type: "array"
|
38
|
+
items:
|
39
|
+
type: "object"
|
40
|
+
properties: {}
|
41
|
+
headers:
|
42
|
+
Content-Language:
|
43
|
+
type: "string"
|
44
|
+
'500':
|
45
|
+
description: "500 response"
|
46
|
+
schema:
|
47
|
+
type: "object"
|
48
|
+
properties:
|
49
|
+
message:
|
50
|
+
type: "string"
|
51
|
+
x-amazon-apigateway-integration:
|
52
|
+
responses:
|
53
|
+
default:
|
54
|
+
statusCode: "500"
|
55
|
+
responseTemplates:
|
56
|
+
application/json: |
|
57
|
+
{
|
58
|
+
"message": "Something went wrong!"
|
59
|
+
}
|
60
|
+
^200$:
|
61
|
+
statusCode: "200"
|
62
|
+
responseParameters:
|
63
|
+
method.response.header.Content-Language: "integration.response.header.Content-Language"
|
64
|
+
responseTemplates:
|
65
|
+
application/json: |
|
66
|
+
$input.path('$')
|
67
|
+
requestParameters:
|
68
|
+
integration.request.querystring.q: "method.request.querystring.q"
|
69
|
+
integration.request.header.Accept-Language: "method.request.header.Accept-Language"
|
70
|
+
uri: "https://petstore.example.com"
|
71
|
+
passthroughBehavior: "WHEN_NO_TEMPLATES"
|
72
|
+
httpMethod: "GET"
|
73
|
+
contentHandling: "CONVERT_TO_TEXT"
|
74
|
+
type: "http"
|
@@ -0,0 +1 @@
|
|
1
|
+
$input.path('$')
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# POST Endpoint with Lambda Integration
|
2
|
+
|
3
|
+
This example demonstrates how to specify a POST endpoint for the path `/pets` which integrates with a AWS Lambda
|
4
|
+
function `create_pet` as downstream service.
|
5
|
+
|
6
|
+
## Configuration
|
7
|
+
|
8
|
+
* The request accepts a header `Accept-Language` which is passed through as `$.meta.accept_language` to the Lambda
|
9
|
+
function.
|
10
|
+
* The request accepts a request body; its value `$.pet.name` is passed through to the Lambda function.
|
11
|
+
* The endpoint responds with a `201` if the Lambda function invocation succeeds and passes through `$.location` as
|
12
|
+
`Location` header from the Lambda function response to the client.
|
13
|
+
* The endpoint responds with a `500` if the Lambda function invocation fails.
|
14
|
+
|
15
|
+
## Given
|
16
|
+
|
17
|
+
* [`index.rb`](index.rb) (skipped for readability)
|
18
|
+
|
19
|
+
* [`pets/post.rb`](pets/post.rb)
|
20
|
+
|
21
|
+
```rb
|
22
|
+
POST '/pets' do
|
23
|
+
header 'Accept-Language'
|
24
|
+
|
25
|
+
LAMBDA 'arn:aws:lambda:eu-west-1:123456789012:function:create_pet'
|
26
|
+
|
27
|
+
RESPONSE 201 do
|
28
|
+
header 'Location', integration: { response: { body: 'location' } }
|
29
|
+
end
|
30
|
+
|
31
|
+
RESPONSE 500, /\n|.*/
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
* [`pets/request/body.vtl`](pets/request/body.vtl)
|
36
|
+
|
37
|
+
```vtl
|
38
|
+
#set( $inputRoot = $input.path('$') )
|
39
|
+
{
|
40
|
+
"pet": {
|
41
|
+
"name": $input.json('$.pet.name')
|
42
|
+
}
|
43
|
+
"meta": {
|
44
|
+
"accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
* [`pets/request/body.yml`](pets/request/body.yml)
|
50
|
+
|
51
|
+
```yml
|
52
|
+
type: "object"
|
53
|
+
properties:
|
54
|
+
pet:
|
55
|
+
type: "object"
|
56
|
+
properties:
|
57
|
+
name:
|
58
|
+
type: "string"
|
59
|
+
```
|
60
|
+
|
61
|
+
* [`pets/response/201.vtl`](pets/response/201.vtl)
|
62
|
+
|
63
|
+
```vtl
|
64
|
+
{}
|
65
|
+
```
|
66
|
+
|
67
|
+
* [`pets/response/201.yml`](pets/response/201.yml)
|
68
|
+
|
69
|
+
```yml
|
70
|
+
type: "object"
|
71
|
+
```
|
72
|
+
|
73
|
+
* [`pets/response/500.vtl`](pets/response/500.vtl)
|
74
|
+
|
75
|
+
```vtl
|
76
|
+
{
|
77
|
+
"message": "Something went wrong!"
|
78
|
+
}
|
79
|
+
```
|
80
|
+
|
81
|
+
* [`pets/response/500.yml`](pets/response/500.yml)
|
82
|
+
|
83
|
+
```yml
|
84
|
+
type: "object"
|
85
|
+
properties:
|
86
|
+
message:
|
87
|
+
type: "string"
|
88
|
+
```
|
89
|
+
|
90
|
+
## Generates
|
91
|
+
|
92
|
+
* [`index.yml`](index.yml)
|
93
|
+
|
94
|
+
```yml
|
95
|
+
swagger: "2.0"
|
96
|
+
info:
|
97
|
+
version: "1.2.3"
|
98
|
+
title: "POST Endpoint with Lambda Integration"
|
99
|
+
description: |
|
100
|
+
This example demonstrates how to specify a POST endpoint for the path `/pets` which integrates with a AWS Lambda
|
101
|
+
function `create_pet` as downstream service.
|
102
|
+
|
103
|
+
## Configuration
|
104
|
+
|
105
|
+
* The request accepts a header `Accept-Language` which is passed through as `$.meta.accept_language` to the Lambda
|
106
|
+
function.
|
107
|
+
* The request accepts a request body; its value `$.pet.name` is passed through to the Lambda function.
|
108
|
+
* The endpoint responds with a `201` if the Lambda function invocation succeeds and passes through `$.location` as
|
109
|
+
`Location` header from the Lambda function response to the client.
|
110
|
+
* The endpoint responds with a `500` if the Lambda function invocation fails.
|
111
|
+
host: "api.example.com"
|
112
|
+
schemes:
|
113
|
+
- "https"
|
114
|
+
paths:
|
115
|
+
/pets:
|
116
|
+
post:
|
117
|
+
consumes:
|
118
|
+
- "application/json"
|
119
|
+
produces:
|
120
|
+
- "application/json"
|
121
|
+
parameters:
|
122
|
+
- name: "Accept-Language"
|
123
|
+
in: "header"
|
124
|
+
required: false
|
125
|
+
type: "string"
|
126
|
+
- in: "body"
|
127
|
+
name: "body"
|
128
|
+
required: true
|
129
|
+
schema:
|
130
|
+
type: "object"
|
131
|
+
properties:
|
132
|
+
pet:
|
133
|
+
type: "object"
|
134
|
+
properties:
|
135
|
+
name:
|
136
|
+
type: "string"
|
137
|
+
responses:
|
138
|
+
'201':
|
139
|
+
description: "201 response"
|
140
|
+
schema:
|
141
|
+
type: "object"
|
142
|
+
headers:
|
143
|
+
Location:
|
144
|
+
type: "string"
|
145
|
+
'500':
|
146
|
+
description: "500 response"
|
147
|
+
schema:
|
148
|
+
type: "object"
|
149
|
+
properties:
|
150
|
+
message:
|
151
|
+
type: "string"
|
152
|
+
x-amazon-apigateway-integration:
|
153
|
+
responses:
|
154
|
+
default:
|
155
|
+
statusCode: "201"
|
156
|
+
responseParameters:
|
157
|
+
method.response.header.Location: "integration.response.body.location"
|
158
|
+
responseTemplates:
|
159
|
+
application/json: |
|
160
|
+
{}
|
161
|
+
\n|.*:
|
162
|
+
statusCode: "500"
|
163
|
+
responseTemplates:
|
164
|
+
application/json: |
|
165
|
+
{
|
166
|
+
"message": "Something went wrong!"
|
167
|
+
}
|
168
|
+
requestTemplates:
|
169
|
+
application/json: |
|
170
|
+
#set( $inputRoot = $input.path('$') )
|
171
|
+
{
|
172
|
+
"pet": {
|
173
|
+
"name": $input.json('$.pet.name')
|
174
|
+
}
|
175
|
+
"meta": {
|
176
|
+
"accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
|
177
|
+
}
|
178
|
+
}
|
179
|
+
uri: "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:123456789012:function:create_pet/invocations"
|
180
|
+
passthroughBehavior: "WHEN_NO_TEMPLATES"
|
181
|
+
httpMethod: "POST"
|
182
|
+
contentHandling: "CONVERT_TO_TEXT"
|
183
|
+
type: "aws"
|
184
|
+
```
|
185
|
+
|