Skip to content

Commit 017aab0

Browse files
committed
tests: add example overlay targetting objects with field condition
This commit adds a case where the overlay is targetting objects with a condition on the object (here objects where `x-beta: true` is set).
1 parent 88f6167 commit 017aab0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

examples/valid/openapi.v3.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@
124124
"description": "Sentence about ping and pong",
125125
"example": "And that's how ping-pong ball is bumped",
126126
"type": "string"
127+
},
128+
"ping": {
129+
"type": "string",
130+
"x-beta": true
127131
}
128132
}
129133
},

examples/valid/overlay.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ actions:
2525
description: Remove all other servers so we can add our own.
2626
remove: true
2727

28+
- target: '$..[?(@["x-beta"]==true)]'
29+
description: Remove all beta operations
30+
remove: true
31+
2832
- target: '$.servers'
2933
description: Pop our server into the empty server array.
3034
update:

test/commands/overlay.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ describe('overlay subcommand', () => {
1515
.it('computes the merged API document with the given overlay', ({ stdout }) => {
1616
const newDefinition = JSON.parse(stdout);
1717

18+
// Target on info description
1819
expect(newDefinition.info.description).to.match(
1920
/Protect Earth's Tree Tracker API/,
2021
);
22+
// Target on info contact information
2123
expect(newDefinition.info.contact.email).to.equal('help@protect.earth');
24+
// Target on all servers
2225
expect(newDefinition.servers.length).to.equal(1);
2326
expect(newDefinition.servers[0].description).to.equal('Production');
27+
// Target on nodes which have "x-beta":true field
28+
expect(newDefinition.components.schemas.Pong.properties).to.have.all.keys('pong');
2429
});
2530
});
2631
});

0 commit comments

Comments
 (0)