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,18 @@
1
+ title 'POST Endpoint with Lambda Integration'
2
+ version '1.2.3'
3
+ description <<-EOS
4
+ This example demonstrates how to specify a POST endpoint for the path `/pets` which integrates with a AWS Lambda
5
+ function `create_pet` as downstream service.
6
+
7
+ ## Configuration
8
+
9
+ * The request accepts a header `Accept-Language` which is passed through as `$.meta.accept_language` to the Lambda
10
+ function.
11
+ * The request accepts a request body; its value `$.pet.name` is passed through to the Lambda function.
12
+ * The endpoint responds with a `201` if the Lambda function invocation succeeds and passes through `$.location` as
13
+ `Location` header from the Lambda function response to the client.
14
+ * The endpoint responds with a `500` if the Lambda function invocation fails.
15
+ EOS
16
+
17
+ host 'api.example.com'
18
+ schemes 'https'
@@ -0,0 +1,89 @@
1
+ swagger: "2.0"
2
+ info:
3
+ version: "1.2.3"
4
+ title: "POST Endpoint with Lambda Integration"
5
+ description: |
6
+ This example demonstrates how to specify a POST endpoint for the path `/pets` which integrates with a AWS Lambda
7
+ function `create_pet` as downstream service.
8
+
9
+ ## Configuration
10
+
11
+ * The request accepts a header `Accept-Language` which is passed through as `$.meta.accept_language` to the Lambda
12
+ function.
13
+ * The request accepts a request body; its value `$.pet.name` is passed through to the Lambda function.
14
+ * The endpoint responds with a `201` if the Lambda function invocation succeeds and passes through `$.location` as
15
+ `Location` header from the Lambda function response to the client.
16
+ * The endpoint responds with a `500` if the Lambda function invocation fails.
17
+ host: "api.example.com"
18
+ schemes:
19
+ - "https"
20
+ paths:
21
+ /pets:
22
+ post:
23
+ consumes:
24
+ - "application/json"
25
+ produces:
26
+ - "application/json"
27
+ parameters:
28
+ - name: "Accept-Language"
29
+ in: "header"
30
+ required: false
31
+ type: "string"
32
+ - in: "body"
33
+ name: "body"
34
+ required: true
35
+ schema:
36
+ type: "object"
37
+ properties:
38
+ pet:
39
+ type: "object"
40
+ properties:
41
+ name:
42
+ type: "string"
43
+ responses:
44
+ '201':
45
+ description: "201 response"
46
+ schema:
47
+ type: "object"
48
+ headers:
49
+ Location:
50
+ type: "string"
51
+ '500':
52
+ description: "500 response"
53
+ schema:
54
+ type: "object"
55
+ properties:
56
+ message:
57
+ type: "string"
58
+ x-amazon-apigateway-integration:
59
+ responses:
60
+ default:
61
+ statusCode: "201"
62
+ responseParameters:
63
+ method.response.header.Location: "integration.response.body.location"
64
+ responseTemplates:
65
+ application/json: |
66
+ {}
67
+ \n|.*:
68
+ statusCode: "500"
69
+ responseTemplates:
70
+ application/json: |
71
+ {
72
+ "message": "Something went wrong!"
73
+ }
74
+ requestTemplates:
75
+ application/json: |
76
+ #set( $inputRoot = $input.path('$') )
77
+ {
78
+ "pet": {
79
+ "name": $input.json('$.pet.name')
80
+ }
81
+ "meta": {
82
+ "accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
83
+ }
84
+ }
85
+ uri: "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:123456789012:function:create_pet/invocations"
86
+ passthroughBehavior: "WHEN_NO_TEMPLATES"
87
+ httpMethod: "POST"
88
+ contentHandling: "CONVERT_TO_TEXT"
89
+ type: "aws"
@@ -0,0 +1,11 @@
1
+ POST '/pets' do
2
+ header 'Accept-Language'
3
+
4
+ LAMBDA 'arn:aws:lambda:eu-west-1:123456789012:function:create_pet'
5
+
6
+ RESPONSE 201 do
7
+ header 'Location', integration: { response: { body: 'location' } }
8
+ end
9
+
10
+ RESPONSE 500, /\n|.*/
11
+ end
@@ -0,0 +1,9 @@
1
+ #set( $inputRoot = $input.path('$') )
2
+ {
3
+ "pet": {
4
+ "name": $input.json('$.pet.name')
5
+ }
6
+ "meta": {
7
+ "accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
8
+ }
9
+ }
@@ -0,0 +1,7 @@
1
+ type: "object"
2
+ properties:
3
+ pet:
4
+ type: "object"
5
+ properties:
6
+ name:
7
+ type: "string"
@@ -0,0 +1 @@
1
+ type: "object"
@@ -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,193 @@
1
+ # POST Endpoint with Lambda Integration and CORS Support
2
+
3
+ This example is based on [`lambda_post`](../lambda_post), but in addition, it generates the `OPTIONS` endpoint for
4
+ CORS support via the `cors: true` configuration.
5
+
6
+ ## Given
7
+
8
+ * [`index.rb`](index.rb) (skipped for readability)
9
+
10
+ * [`pets/post.rb`](pets/post.rb)
11
+
12
+ ```rb
13
+ POST '/pets', cors: true do
14
+ header 'Accept-Language'
15
+
16
+ LAMBDA 'arn:aws:lambda:eu-west-1:123456789012:function:create_pet'
17
+
18
+ RESPONSE 201 do
19
+ header 'Location', integration: { response: { body: 'location' } }
20
+ end
21
+
22
+ RESPONSE 500, /\n|.*/
23
+ end
24
+ ```
25
+
26
+ * [`pets/request/body.vtl`](pets/request/body.vtl)
27
+
28
+ ```vtl
29
+ #set( $inputRoot = $input.path('$') )
30
+ {
31
+ "pet": {
32
+ "name": $input.json('$.pet.name')
33
+ }
34
+ "meta": {
35
+ "accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
36
+ }
37
+ }
38
+ ```
39
+
40
+ * [`pets/request/body.yml`](pets/request/body.yml)
41
+
42
+ ```yml
43
+ type: "object"
44
+ properties:
45
+ pet:
46
+ type: "object"
47
+ properties:
48
+ name:
49
+ type: "string"
50
+ ```
51
+
52
+ * [`pets/response/201.vtl`](pets/response/201.vtl)
53
+
54
+ ```vtl
55
+ {}
56
+ ```
57
+
58
+ * [`pets/response/201.yml`](pets/response/201.yml)
59
+
60
+ ```yml
61
+ type: "object"
62
+ ```
63
+
64
+ * [`pets/response/500.vtl`](pets/response/500.vtl)
65
+
66
+ ```vtl
67
+ {
68
+ "message": "Something went wrong!"
69
+ }
70
+ ```
71
+
72
+ * [`pets/response/500.yml`](pets/response/500.yml)
73
+
74
+ ```yml
75
+ type: "object"
76
+ properties:
77
+ message:
78
+ type: "string"
79
+ ```
80
+
81
+ ## Generates
82
+
83
+ * [`index.yml`](index.yml)
84
+
85
+ ```yml
86
+ swagger: "2.0"
87
+ info:
88
+ version: "1.2.3"
89
+ title: "POST Endpoint with Lambda Integration and CORS Support"
90
+ description: |
91
+ This example is based on [`lambda_post`](../lambda_post), but in addition, it generates the `OPTIONS` endpoint for
92
+ CORS support via the `cors: true` configuration.
93
+ host: "api.example.com"
94
+ schemes:
95
+ - "https"
96
+ paths:
97
+ /pets:
98
+ post:
99
+ consumes:
100
+ - "application/json"
101
+ produces:
102
+ - "application/json"
103
+ parameters:
104
+ - name: "Accept-Language"
105
+ in: "header"
106
+ required: false
107
+ type: "string"
108
+ - in: "body"
109
+ name: "body"
110
+ required: true
111
+ schema:
112
+ type: "object"
113
+ properties:
114
+ pet:
115
+ type: "object"
116
+ properties:
117
+ name:
118
+ type: "string"
119
+ responses:
120
+ '201':
121
+ description: "201 response"
122
+ schema:
123
+ type: "object"
124
+ headers:
125
+ Location:
126
+ type: "string"
127
+ '500':
128
+ description: "500 response"
129
+ schema:
130
+ type: "object"
131
+ properties:
132
+ message:
133
+ type: "string"
134
+ x-amazon-apigateway-integration:
135
+ responses:
136
+ default:
137
+ statusCode: "201"
138
+ responseParameters:
139
+ method.response.header.Location: "integration.response.body.location"
140
+ responseTemplates:
141
+ application/json: |
142
+ {}
143
+ \n|.*:
144
+ statusCode: "500"
145
+ responseTemplates:
146
+ application/json: |
147
+ {
148
+ "message": "Something went wrong!"
149
+ }
150
+ requestTemplates:
151
+ application/json: |
152
+ #set( $inputRoot = $input.path('$') )
153
+ {
154
+ "pet": {
155
+ "name": $input.json('$.pet.name')
156
+ }
157
+ "meta": {
158
+ "accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
159
+ }
160
+ }
161
+ uri: "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:123456789012:function:create_pet/invocations"
162
+ passthroughBehavior: "WHEN_NO_TEMPLATES"
163
+ httpMethod: "POST"
164
+ contentHandling: "CONVERT_TO_TEXT"
165
+ type: "aws"
166
+ options:
167
+ responses:
168
+ '200':
169
+ description: "200 response"
170
+ headers:
171
+ Access-Control-Allow-Origin:
172
+ type: "string"
173
+ Access-Control-Allow-Methods:
174
+ type: "string"
175
+ Access-Control-Allow-Headers:
176
+ type: "string"
177
+ x-amazon-apigateway-integration:
178
+ responses:
179
+ default:
180
+ statusCode: "200"
181
+ responseParameters:
182
+ method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
183
+ method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
184
+ method.response.header.Access-Control-Allow-Origin: "'*'"
185
+ requestTemplates:
186
+ application/json: |
187
+ {
188
+ "statusCode": 200
189
+ }
190
+ passthroughBehavior: "WHEN_NO_TEMPLATES"
191
+ type: "mock"
192
+ ```
193
+
@@ -0,0 +1,9 @@
1
+ title 'POST Endpoint with Lambda Integration and CORS Support'
2
+ version '1.2.3'
3
+ description <<-EOS
4
+ This example is based on [`lambda_post`](../lambda_post), but in addition, it generates the `OPTIONS` endpoint for
5
+ CORS support via the `cors: true` configuration.
6
+ EOS
7
+
8
+ host 'api.example.com'
9
+ schemes 'https'
@@ -0,0 +1,106 @@
1
+ swagger: "2.0"
2
+ info:
3
+ version: "1.2.3"
4
+ title: "POST Endpoint with Lambda Integration and CORS Support"
5
+ description: |
6
+ This example is based on [`lambda_post`](../lambda_post), but in addition, it generates the `OPTIONS` endpoint for
7
+ CORS support via the `cors: true` configuration.
8
+ host: "api.example.com"
9
+ schemes:
10
+ - "https"
11
+ paths:
12
+ /pets:
13
+ post:
14
+ consumes:
15
+ - "application/json"
16
+ produces:
17
+ - "application/json"
18
+ parameters:
19
+ - name: "Accept-Language"
20
+ in: "header"
21
+ required: false
22
+ type: "string"
23
+ - in: "body"
24
+ name: "body"
25
+ required: true
26
+ schema:
27
+ type: "object"
28
+ properties:
29
+ pet:
30
+ type: "object"
31
+ properties:
32
+ name:
33
+ type: "string"
34
+ responses:
35
+ '201':
36
+ description: "201 response"
37
+ schema:
38
+ type: "object"
39
+ headers:
40
+ Location:
41
+ type: "string"
42
+ '500':
43
+ description: "500 response"
44
+ schema:
45
+ type: "object"
46
+ properties:
47
+ message:
48
+ type: "string"
49
+ x-amazon-apigateway-integration:
50
+ responses:
51
+ default:
52
+ statusCode: "201"
53
+ responseParameters:
54
+ method.response.header.Location: "integration.response.body.location"
55
+ responseTemplates:
56
+ application/json: |
57
+ {}
58
+ \n|.*:
59
+ statusCode: "500"
60
+ responseTemplates:
61
+ application/json: |
62
+ {
63
+ "message": "Something went wrong!"
64
+ }
65
+ requestTemplates:
66
+ application/json: |
67
+ #set( $inputRoot = $input.path('$') )
68
+ {
69
+ "pet": {
70
+ "name": $input.json('$.pet.name')
71
+ }
72
+ "meta": {
73
+ "accept_language": "${util.escapeJavaScript($input.params('Accept-Language')).replaceAll("\\'","'")}"
74
+ }
75
+ }
76
+ uri: "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:123456789012:function:create_pet/invocations"
77
+ passthroughBehavior: "WHEN_NO_TEMPLATES"
78
+ httpMethod: "POST"
79
+ contentHandling: "CONVERT_TO_TEXT"
80
+ type: "aws"
81
+ options:
82
+ responses:
83
+ '200':
84
+ description: "200 response"
85
+ headers:
86
+ Access-Control-Allow-Origin:
87
+ type: "string"
88
+ Access-Control-Allow-Methods:
89
+ type: "string"
90
+ Access-Control-Allow-Headers:
91
+ type: "string"
92
+ x-amazon-apigateway-integration:
93
+ responses:
94
+ default:
95
+ statusCode: "200"
96
+ responseParameters:
97
+ method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'"
98
+ method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
99
+ method.response.header.Access-Control-Allow-Origin: "'*'"
100
+ requestTemplates:
101
+ application/json: |
102
+ {
103
+ "statusCode": 200
104
+ }
105
+ passthroughBehavior: "WHEN_NO_TEMPLATES"
106
+ type: "mock"