Skip to content

Commit 7b0506f

Browse files
committed
Add more tests for removing various things by expression
1 parent 08becd7 commit 7b0506f

10 files changed

+337
-25
lines changed

test/expected/town-building-description.yaml

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,63 @@ paths:
99
/buildings:
1010
get:
1111
summary: All of the available buildings
12-
operationId: buildingsAll
13-
description: This is the summary of getting the buildings
12+
operationId: buildingsList
13+
description: This is the summary of getting the buildings
1414
responses:
1515
'200':
1616
description: Return all known buildings
1717
content:
1818
application/json:
1919
schema:
20-
type: object
21-
properties:
22-
message:
23-
type: string
24-
example: house
25-
20+
type: array
21+
items:
22+
$ref: '#/components/schemas/Building'
23+
'/buildings/{buildingId}':
24+
get:
25+
summary: Specific building
26+
operationId: buildingById
27+
parameters:
28+
- name: buildingId
29+
in: path
30+
required: true
31+
description: Which building to return
32+
schema:
33+
type: string
34+
responses:
35+
'200':
36+
description: Return a building
37+
content:
38+
application/json:
39+
schema:
40+
$ref: '#/components/schemas/Building'
41+
/locations:
42+
get:
43+
summary: All locations
44+
operationId: locationList
45+
responses:
46+
'200':
47+
description: Returns all locations
48+
content:
49+
application/json:
50+
schema:
51+
type: array
52+
items:
53+
type: object
54+
properties:
55+
location_id:
56+
type: int
57+
example: 44
58+
name:
59+
type: string
60+
example: North Village
61+
components:
62+
schemas:
63+
Building:
64+
type: object
65+
properties:
66+
building:
67+
type: string
68+
example: house
69+
location_id:
70+
type: int
71+
example: 44
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
openapi: 3.1.0
2+
info:
3+
version: 1.0.0
4+
title: Imaginary town
5+
servers:
6+
- url: 'https://example.com'
7+
paths:
8+
/buildings:
9+
get:
10+
summary: All buildings
11+
operationId: buildingsList
12+
responses:
13+
'200':
14+
content:
15+
application/json:
16+
schema:
17+
type: array
18+
items:
19+
$ref: '#/components/schemas/Building'
20+
'/buildings/{buildingId}':
21+
get:
22+
summary: Specific building
23+
operationId: buildingById
24+
parameters:
25+
- name: buildingId
26+
in: path
27+
required: true
28+
schema:
29+
type: string
30+
responses:
31+
'200':
32+
content:
33+
application/json:
34+
schema:
35+
$ref: '#/components/schemas/Building'
36+
/locations:
37+
get:
38+
summary: All locations
39+
operationId: locationList
40+
responses:
41+
'200':
42+
content:
43+
application/json:
44+
schema:
45+
type: array
46+
items:
47+
type: object
48+
properties:
49+
location_id:
50+
type: int
51+
example: 44
52+
name:
53+
type: string
54+
example: North Village
55+
components:
56+
schemas:
57+
Building:
58+
type: object
59+
properties:
60+
building:
61+
type: string
62+
example: house
63+
location_id:
64+
type: int
65+
example: 44

test/expected/town-remove-example.yaml

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,66 @@ info:
44
title: Imaginary town
55
servers:
66
- url: 'https://example.com'
7+
description: Example server
78
paths:
89
/buildings:
910
get:
1011
summary: All buildings
11-
operationId: buildingsAll
12+
operationId: buildingsList
1213
responses:
1314
'200':
15+
description: Return all known buildings
1416
content:
1517
application/json:
1618
schema:
17-
type: object
18-
properties:
19-
message:
20-
type: string
19+
type: array
20+
items:
21+
$ref: '#/components/schemas/Building'
22+
'/buildings/{buildingId}':
23+
get:
24+
summary: Specific building
25+
operationId: buildingById
26+
parameters:
27+
- name: buildingId
28+
in: path
29+
required: true
30+
description: Which building to return
31+
schema:
32+
type: string
33+
responses:
34+
'200':
35+
description: Return a building
36+
content:
37+
application/json:
38+
schema:
39+
$ref: '#/components/schemas/Building'
40+
/locations:
41+
get:
42+
summary: All locations
43+
operationId: locationList
44+
responses:
45+
'200':
46+
description: Returns all locations
47+
content:
48+
application/json:
49+
schema:
50+
type: array
51+
items:
52+
type: object
53+
properties:
54+
location_id:
55+
type: int
56+
example: 44
57+
name:
58+
type: string
59+
example: North Village
60+
components:
61+
schemas:
62+
Building:
63+
type: object
64+
properties:
65+
building:
66+
type: string
67+
location_id:
68+
type: int
69+
example: 44
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
openapi: 3.1.0
2+
info:
3+
version: 1.0.0
4+
title: Imaginary town
5+
servers:
6+
- url: 'https://example.com'
7+
description: Example server
8+
paths:
9+
/buildings:
10+
get:
11+
summary: All buildings
12+
operationId: buildingsList
13+
responses:
14+
'200':
15+
description: Return all known buildings
16+
content:
17+
application/json:
18+
schema:
19+
type: array
20+
items:
21+
$ref: '#/components/schemas/Building'
22+
'/buildings/{buildingId}':
23+
get:
24+
summary: Specific building
25+
operationId: buildingById
26+
parameters:
27+
- name: buildingId
28+
in: path
29+
required: true
30+
description: Which building to return
31+
schema:
32+
type: string
33+
responses:
34+
'200':
35+
description: Return a building
36+
content:
37+
application/json:
38+
schema:
39+
$ref: '#/components/schemas/Building'
40+
/locations:
41+
get:
42+
summary: All locations
43+
operationId: locationList
44+
responses:
45+
'200':
46+
description: Returns all locations
47+
content:
48+
application/json:
49+
schema:
50+
type: array
51+
items:
52+
type: object
53+
properties:
54+
location_id:
55+
type: int
56+
example: 44
57+
components:
58+
schemas:
59+
Building:
60+
type: object
61+
properties:
62+
building:
63+
type: string
64+
example: house
65+
location_id:
66+
type: int
67+
example: 44

test/openapi/town.yaml

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,66 @@ servers:
88
paths:
99
'/buildings':
1010
get:
11-
summary: All buildings
12-
operationId: buildingsAll
11+
summary: All buildings
12+
operationId: buildingsList
1313
responses:
1414
'200':
1515
description: Return all known buildings
1616
content:
1717
application/json:
1818
schema:
19-
type: object
20-
properties:
21-
message:
22-
type: string
23-
example: "house"
19+
type: array
20+
items:
21+
$ref: "#/components/schemas/Building"
2422

23+
'/buildings/{buildingId}':
24+
get:
25+
summary: Specific building
26+
operationId: buildingById
27+
parameters:
28+
- name: buildingId
29+
in: path
30+
required: true
31+
description: Which building to return
32+
schema:
33+
type: string
34+
responses:
35+
'200':
36+
description: Return a building
37+
content:
38+
application/json:
39+
schema:
40+
$ref: "#/components/schemas/Building"
41+
42+
'/locations':
43+
get:
44+
summary: All locations
45+
operationId: locationList
46+
responses:
47+
'200':
48+
description: Returns all locations
49+
content:
50+
application/json:
51+
schema:
52+
type: array
53+
items:
54+
type: object
55+
properties:
56+
location_id:
57+
type: int
58+
example: 44
59+
name:
60+
type: string
61+
example: "North Village"
62+
63+
components:
64+
schemas:
65+
Building:
66+
type: object
67+
properties:
68+
building:
69+
type: string
70+
example: "house"
71+
location_id:
72+
type: int
73+
example: 44

test/overlay.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,26 @@ test('remove an example', () => {
3737
});
3838

3939

40+
test('remove a property', () => {
41+
const openapiFile = "test/openapi/town.yaml";
42+
const overlayFile = "test/overlays/remove-properties.yaml";
43+
const expectedFile = "test/expected/town-remove-properties.yaml";
44+
const expectedOutput = fs.readFileSync(expectedFile, 'utf8');
45+
46+
const result = overlayFiles(openapiFile, overlayFile);
47+
48+
expect(result).toEqual(expectedOutput);
49+
});
50+
51+
test('remove all description fields', () => {
52+
const openapiFile = "test/openapi/town.yaml";
53+
const overlayFile = "test/overlays/remove-descriptions.yaml";
54+
const expectedFile = "test/expected/town-remove-descriptions.yaml";
55+
const expectedOutput = fs.readFileSync(expectedFile, 'utf8');
56+
57+
const result = overlayFiles(openapiFile, overlayFile);
58+
59+
expect(result).toEqual(expectedOutput);
60+
});
61+
62+

test/overlays/building-description.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ info:
55
actions:
66
- target: $.paths['/buildings'].get
77
update:
8-
description: "This is the summary of getting the buildings"
9-
summary: "All of the available buildings"
8+
description: This is the summary of getting the buildings
9+
summary: All of the available buildings
1010

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
overlay: 1.0.0
2+
info:
3+
title: Remove an example
4+
version: 1.0.0
5+
actions:
6+
- target: $..description
7+
remove: true

0 commit comments

Comments
 (0)