Skip to content

Commit a5ceecf

Browse files
authored
Merge pull request #13 from lornajane/fix-remove-stops-after-one
Make sure to catch all targeted items in the remove
2 parents 6141268 + b6cceb6 commit a5ceecf

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

src/overlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function applyOverlayToOpenAPI(spec, overlay) {
99
// Is it a remove?
1010
if (a.hasOwnProperty('remove')) {
1111
while(true) {
12-
var path = jsonpath.paths(spec, a.target, 1)
12+
var path = jsonpath.paths(spec, a.target)
1313
if (path.length == 0) {
1414
break
1515
}

test/expected/remove-responses.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Responses
4+
version: 1.0.0
5+
paths:
6+
/foo:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
/bar:
12+
post:
13+
responses:
14+
'201':
15+
description: Created
16+
/baa:
17+
post:
18+
responses:
19+
'201':
20+
description: Shouted

test/openapi/responses.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Responses
4+
version: 1.0.0
5+
paths:
6+
/foo:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
'500':
12+
description: oops
13+
/bar:
14+
post:
15+
responses:
16+
'201':
17+
description: Created
18+
'500':
19+
description: oops
20+
default:
21+
description: something
22+
/baa:
23+
post:
24+
responses:
25+
'201':
26+
description: Shouted
27+
'500':
28+
description: oops
29+
default:
30+
description: something

test/overlay.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,14 @@ test('overlay document with empty actions is a nop', () => {
114114
expect(result).toEqual(expectedOutput);
115115
});
116116

117+
test('remove all matching responses', () => {
118+
const openapiFile = "test/openapi/responses.yaml";
119+
const overlayFile = "test/overlays/remove-responses.yaml";
120+
const expectedFile = "test/expected/remove-responses.yaml";
121+
const expectedOutput = fs.readFileSync(expectedFile, 'utf8');
122+
123+
const result = overlayFiles(openapiFile, overlayFile);
124+
125+
expect(result).toEqual(expectedOutput);
126+
});
127+

test/overlays/remove-responses.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Response code removal test
4+
version: 1.0.0
5+
6+
extends: response-codes.yaml
7+
8+
actions:
9+
- target: $.paths..responses['500']
10+
remove: true
11+
12+
- target: $.paths..responses['default']
13+
remove: true

0 commit comments

Comments
 (0)