api_gateway_dsl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +20 -0
  5. data/.ruby-version +1 -0
  6. data/.simplecov +2 -0
  7. data/.travis.yml +2 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE +21 -0
  10. data/README.md +40 -0
  11. data/Rakefile +4 -0
  12. data/api_gateway_dsl.gemspec +30 -0
  13. data/bin/api_gateway_dsl +32 -0
  14. data/lib/api_gateway_dsl.rb +26 -0
  15. data/lib/api_gateway_dsl/context.rb +13 -0
  16. data/lib/api_gateway_dsl/document.rb +41 -0
  17. data/lib/api_gateway_dsl/dsl/document_node.rb +46 -0
  18. data/lib/api_gateway_dsl/dsl/integration_node.rb +32 -0
  19. data/lib/api_gateway_dsl/dsl/operation_node.rb +66 -0
  20. data/lib/api_gateway_dsl/dsl/response_node.rb +24 -0
  21. data/lib/api_gateway_dsl/integration.rb +47 -0
  22. data/lib/api_gateway_dsl/integration/collection.rb +7 -0
  23. data/lib/api_gateway_dsl/integration/http.rb +26 -0
  24. data/lib/api_gateway_dsl/integration/http_proxy.rb +29 -0
  25. data/lib/api_gateway_dsl/integration/lambda.rb +38 -0
  26. data/lib/api_gateway_dsl/integration/mock.rb +33 -0
  27. data/lib/api_gateway_dsl/mapping.rb +68 -0
  28. data/lib/api_gateway_dsl/mapping/collection.rb +15 -0
  29. data/lib/api_gateway_dsl/operation.rb +70 -0
  30. data/lib/api_gateway_dsl/operation/collection.rb +62 -0
  31. data/lib/api_gateway_dsl/parameter.rb +24 -0
  32. data/lib/api_gateway_dsl/parameter/body.rb +21 -0
  33. data/lib/api_gateway_dsl/parameter/collection.rb +7 -0
  34. data/lib/api_gateway_dsl/parameter/header.rb +13 -0
  35. data/lib/api_gateway_dsl/parameter/path.rb +14 -0
  36. data/lib/api_gateway_dsl/parameter/query.rb +13 -0
  37. data/lib/api_gateway_dsl/parameter/simple.rb +23 -0
  38. data/lib/api_gateway_dsl/response.rb +53 -0
  39. data/lib/api_gateway_dsl/response/collection.rb +19 -0
  40. data/lib/api_gateway_dsl/response_header.rb +19 -0
  41. data/lib/api_gateway_dsl/response_header/collection.rb +11 -0
  42. data/lib/api_gateway_dsl/response_integration.rb +30 -0
  43. data/lib/api_gateway_dsl/response_integration/collection.rb +11 -0
  44. data/lib/api_gateway_dsl/template.rb +48 -0
  45. data/lib/api_gateway_dsl/template/collection.rb +32 -0
  46. data/lib/api_gateway_dsl/version.rb +5 -0
  47. data/spec/api_gateway_dsl/document_spec.rb +20 -0
  48. data/spec/fixtures/greedy_http_proxy/README.md +69 -0
  49. data/spec/fixtures/greedy_http_proxy/index.rb +13 -0
  50. data/spec/fixtures/greedy_http_proxy/index.yml +35 -0
  51. data/spec/fixtures/greedy_http_proxy/pets/proxy.rb +9 -0
  52. data/spec/fixtures/http_get/README.md +150 -0
  53. data/spec/fixtures/http_get/index.rb +17 -0
  54. data/spec/fixtures/http_get/index.yml +74 -0
  55. data/spec/fixtures/http_get/pets/get.rb +15 -0
  56. data/spec/fixtures/http_get/pets/response/200.vtl +1 -0
  57. data/spec/fixtures/http_get/pets/response/200.yml +4 -0
  58. data/spec/fixtures/http_get/pets/response/500.vtl +3 -0
  59. data/spec/fixtures/http_get/pets/response/500.yml +4 -0
  60. data/spec/fixtures/lambda_post/README.md +185 -0
  61. data/spec/fixtures/lambda_post/index.rb +18 -0
  62. data/spec/fixtures/lambda_post/index.yml +89 -0
  63. data/spec/fixtures/lambda_post/pets/post.rb +11 -0
  64. data/spec/fixtures/lambda_post/pets/request/body.vtl +9 -0
  65. data/spec/fixtures/lambda_post/pets/request/body.yml +7 -0
  66. data/spec/fixtures/lambda_post/pets/response/201.vtl +1 -0
  67. data/spec/fixtures/lambda_post/pets/response/201.yml +1 -0
  68. data/spec/fixtures/lambda_post/pets/response/500.vtl +3 -0
  69. data/spec/fixtures/lambda_post/pets/response/500.yml +4 -0
  70. data/spec/fixtures/lambda_post_with_cors/README.md +193 -0
  71. data/spec/fixtures/lambda_post_with_cors/index.rb +9 -0
  72. data/spec/fixtures/lambda_post_with_cors/index.yml +106 -0
  73. data/spec/fixtures/lambda_post_with_cors/pets/post.rb +11 -0
  74. data/spec/fixtures/lambda_post_with_cors/pets/request/body.vtl +9 -0
  75. data/spec/fixtures/lambda_post_with_cors/pets/request/body.yml +7 -0
  76. data/spec/fixtures/lambda_post_with_cors/pets/response/201.vtl +1 -0
  77. data/spec/fixtures/lambda_post_with_cors/pets/response/201.yml +1 -0
  78. data/spec/fixtures/lambda_post_with_cors/pets/response/500.vtl +3 -0
  79. data/spec/fixtures/lambda_post_with_cors/pets/response/500.yml +4 -0
  80. data/spec/fixtures/markdown.rb +73 -0
  81. data/spec/fixtures/mock_options/README.md +80 -0
  82. data/spec/fixtures/mock_options/index.rb +15 -0
  83. data/spec/fixtures/mock_options/index.yml +44 -0
  84. data/spec/fixtures/mock_options/pets/options.rb +9 -0
  85. data/spec/spec_helper.rb +5 -0
  86. metadata +265 -0
@@ -0,0 +1,9 @@
1
+ ANY '/pets/{proxy+}' do
2
+ path 'proxy'
3
+ header 'Accept-Language'
4
+
5
+ HTTP_PROXY_ANY 'https://petstore.example.com/{proxy}' do
6
+ path 'proxy'
7
+ header 'Accept-Language'
8
+ end
9
+ end
@@ -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,15 @@
1
+ GET '/pets' do
2
+ query 'q'
3
+ header 'Accept-Language'
4
+
5
+ HTTP_GET 'https://petstore.example.com' do
6
+ query 'q'
7
+ header 'Accept-Language'
8
+ end
9
+
10
+ RESPONSE 200, /^200$/ do
11
+ header 'Content-Language'
12
+ end
13
+
14
+ RESPONSE 500
15
+ end
@@ -0,0 +1 @@
1
+ $input.path('$')
@@ -0,0 +1,4 @@
1
+ type: "array"
2
+ items:
3
+ type: "object"
4
+ properties: {}
@@ -0,0 +1,3 @@
1
+ {
2
+ "message": "Something went wrong!"
3
+ }
@@ -0,0 +1,4 @@
1
+ type: "object"
2
+ properties:
3
+ message:
4
+ type: "string"
@@ -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
+