Skip to content

Commit 3f4b94d

Browse files
Nathaniel HutchinsMynockSpit
authored andcommitted
update catalog-updater to convert any method to all other undefined methods (closes awslabs#101)
1 parent 09ea37d commit 3f4b94d

File tree

6 files changed

+365
-1
lines changed

6 files changed

+365
-1
lines changed

lambdas/catalog-updater/__tests__/catalog-updater-test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,80 @@ describe('usagePlanToCatalogObject', () => {
220220
})
221221
})
222222

223+
describe('copyAnyMethod', () => {
224+
test('correctly copies ANY methods to other methods in swagger documents', async () => {
225+
const fileBody = JSON.parse(fs.readFileSync(path.join(__dirname, '/swagger-ANY-method.json'), 'utf8'))
226+
const anyMethod = fileBody.paths["/"]["x-amazon-apigateway-any-method"]
227+
const catalogObject = index.copyAnyMethod(fileBody)
228+
229+
expect(catalogObject.paths["/"]).toEqual({
230+
get: anyMethod,
231+
post: anyMethod,
232+
put: anyMethod,
233+
delete: anyMethod,
234+
patch: anyMethod,
235+
head: anyMethod,
236+
options: anyMethod
237+
})
238+
})
239+
240+
test('does NOT replace already existant methods with ANY in swagger documents', async () => {
241+
const fileBody = JSON.parse(fs.readFileSync(path.join(__dirname, '/swagger-ANY+GET-methods.json'), 'utf8'))
242+
const getMethod = fileBody.paths["/"]["get"]
243+
const anyMethod = fileBody.paths["/"]["x-amazon-apigateway-any-method"]
244+
const catalogObject = index.copyAnyMethod(fileBody)
245+
246+
expect(catalogObject.paths["/"]).toEqual({
247+
// don't replace get
248+
get: getMethod,
249+
250+
// add everything else
251+
post: anyMethod,
252+
put: anyMethod,
253+
delete: anyMethod,
254+
patch: anyMethod,
255+
head: anyMethod,
256+
options: anyMethod
257+
})
258+
})
259+
260+
test('correctly copies ANY methods to other methods in oas3 documents', async () => {
261+
const fileBody = JSON.parse(fs.readFileSync(path.join(__dirname, '/oas3-ANY-method.json'), 'utf8'))
262+
const anyMethod = fileBody.paths["/"]["x-amazon-apigateway-any-method"]
263+
const catalogObject = index.copyAnyMethod(fileBody)
264+
265+
expect(catalogObject.paths["/"]).toEqual({
266+
get: anyMethod,
267+
post: anyMethod,
268+
put: anyMethod,
269+
delete: anyMethod,
270+
patch: anyMethod,
271+
head: anyMethod,
272+
options: anyMethod
273+
})
274+
})
275+
276+
test('does NOT replace already existant methods with ANY in oas3 documents', async () => {
277+
const fileBody = JSON.parse(fs.readFileSync(path.join(__dirname, '/oas3-ANY+GET-methods.json'), 'utf8'))
278+
const getMethod = fileBody.paths["/"]["get"]
279+
const anyMethod = fileBody.paths["/"]["x-amazon-apigateway-any-method"]
280+
const catalogObject = index.copyAnyMethod(fileBody)
281+
282+
expect(catalogObject.paths["/"]).toEqual({
283+
// don't replace get
284+
get: getMethod,
285+
286+
// add everything else
287+
post: anyMethod,
288+
put: anyMethod,
289+
delete: anyMethod,
290+
patch: anyMethod,
291+
head: anyMethod,
292+
options: anyMethod
293+
})
294+
})
295+
})
296+
223297
describe('handler', () => {
224298
test('should fetch from S3 and upload to S3 when run', async () => {
225299
// this is a very abstract test
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "ANY Method",
5+
"version": "2018-12-10T21:32:12Z"
6+
},
7+
"servers": [
8+
{
9+
"url": "https://w7ge8ias0f.execute-api.us-east-1.amazonaws.com/{basePath}",
10+
"variables": {
11+
"basePath": {
12+
"default": "/ANY"
13+
}
14+
}
15+
}
16+
],
17+
"paths": {
18+
"/": {
19+
"get": {
20+
"responses": {
21+
"200": {
22+
"description": "200 response",
23+
"content": {
24+
"application/json": {
25+
"schema": {
26+
"$ref": "#/components/schemas/Empty"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"x-amazon-apigateway-integration": {
33+
"responses": {
34+
"default": {
35+
"statusCode": "200",
36+
"responseTemplates": {
37+
"application/json": "{ message: \"Different Response\" }"
38+
}
39+
}
40+
},
41+
"requestTemplates": {
42+
"application/json": "{\"statusCode\": 200}"
43+
},
44+
"passthroughBehavior": "when_no_match",
45+
"type": "mock"
46+
}
47+
},
48+
"x-amazon-apigateway-any-method": {
49+
"responses": {
50+
"200": {
51+
"description": "200 response",
52+
"content": {
53+
"application/json": {
54+
"schema": {
55+
"$ref": "#/components/schemas/Empty"
56+
}
57+
}
58+
}
59+
}
60+
},
61+
"x-amazon-apigateway-integration": {
62+
"responses": {
63+
"default": {
64+
"statusCode": "200"
65+
}
66+
},
67+
"requestTemplates": {
68+
"application/json": "{\"statusCode\": 200}"
69+
},
70+
"passthroughBehavior": "when_no_match",
71+
"type": "mock"
72+
}
73+
}
74+
}
75+
},
76+
"components": {
77+
"schemas": {
78+
"Empty": {
79+
"title": "Empty Schema",
80+
"type": "object"
81+
}
82+
}
83+
}
84+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "ANY Method",
5+
"version": "2018-12-10T20:51:47Z"
6+
},
7+
"servers": [
8+
{
9+
"url": "https://w7ge8ias0f.execute-api.us-east-1.amazonaws.com/{basePath}",
10+
"variables": {
11+
"basePath": {
12+
"default": "/ANY"
13+
}
14+
}
15+
}
16+
],
17+
"paths": {
18+
"/": {
19+
"x-amazon-apigateway-any-method": {
20+
"responses": {
21+
"200": {
22+
"description": "200 response",
23+
"content": {
24+
"application/json": {
25+
"schema": {
26+
"$ref": "#/components/schemas/Empty"
27+
}
28+
}
29+
}
30+
}
31+
},
32+
"x-amazon-apigateway-integration": {
33+
"responses": {
34+
"default": {
35+
"statusCode": "200"
36+
}
37+
},
38+
"requestTemplates": {
39+
"application/json": "{\"statusCode\": 200}"
40+
},
41+
"passthroughBehavior": "when_no_match",
42+
"type": "mock"
43+
}
44+
}
45+
}
46+
},
47+
"components": {
48+
"schemas": {
49+
"Empty": {
50+
"title": "Empty Schema",
51+
"type": "object"
52+
}
53+
}
54+
}
55+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "2018-12-10T21:32:12Z",
5+
"title": "ANY Method"
6+
},
7+
"host": "w7ge8ias0f.execute-api.us-east-1.amazonaws.com",
8+
"basePath": "/ANY",
9+
"schemes": [
10+
"https"
11+
],
12+
"paths": {
13+
"/": {
14+
"get": {
15+
"consumes": [
16+
"application/json"
17+
],
18+
"produces": [
19+
"application/json"
20+
],
21+
"responses": {
22+
"200": {
23+
"description": "200 response",
24+
"schema": {
25+
"$ref": "#/definitions/Empty"
26+
}
27+
}
28+
},
29+
"x-amazon-apigateway-integration": {
30+
"responses": {
31+
"default": {
32+
"statusCode": "200",
33+
"responseTemplates": {
34+
"application/json": "{ message: \"Different Response\" }"
35+
}
36+
}
37+
},
38+
"requestTemplates": {
39+
"application/json": "{\"statusCode\": 200}"
40+
},
41+
"passthroughBehavior": "when_no_match",
42+
"type": "mock"
43+
}
44+
},
45+
"x-amazon-apigateway-any-method": {
46+
"consumes": [
47+
"application/json"
48+
],
49+
"produces": [
50+
"application/json"
51+
],
52+
"responses": {
53+
"200": {
54+
"description": "200 response",
55+
"schema": {
56+
"$ref": "#/definitions/Empty"
57+
}
58+
}
59+
},
60+
"x-amazon-apigateway-integration": {
61+
"responses": {
62+
"default": {
63+
"statusCode": "200"
64+
}
65+
},
66+
"requestTemplates": {
67+
"application/json": "{\"statusCode\": 200}"
68+
},
69+
"passthroughBehavior": "when_no_match",
70+
"type": "mock"
71+
}
72+
}
73+
}
74+
},
75+
"definitions": {
76+
"Empty": {
77+
"type": "object",
78+
"title": "Empty Schema"
79+
}
80+
}
81+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "2018-12-10T20:51:47Z",
5+
"title": "ANY Method"
6+
},
7+
"host": "w7ge8ias0f.execute-api.us-east-1.amazonaws.com",
8+
"basePath": "/ANY",
9+
"schemes": [
10+
"https"
11+
],
12+
"paths": {
13+
"/": {
14+
"x-amazon-apigateway-any-method": {
15+
"consumes": [
16+
"application/json"
17+
],
18+
"produces": [
19+
"application/json"
20+
],
21+
"responses": {
22+
"200": {
23+
"description": "200 response",
24+
"schema": {
25+
"$ref": "#/definitions/Empty"
26+
}
27+
}
28+
},
29+
"x-amazon-apigateway-integration": {
30+
"responses": {
31+
"default": {
32+
"statusCode": "200"
33+
}
34+
},
35+
"requestTemplates": {
36+
"application/json": "{\"statusCode\": 200}"
37+
},
38+
"passthroughBehavior": "when_no_match",
39+
"type": "mock"
40+
}
41+
}
42+
}
43+
},
44+
"definitions": {
45+
"Empty": {
46+
"type": "object",
47+
"title": "Empty Schema"
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)