Skip to content

Commit 9a3b178

Browse files
committed
feat: OpenAPI Overlay 1.1.0
1 parent c947262 commit 9a3b178

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

test/overlay.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,28 @@ describe('openapi-format CLI overlay tests', () => {
231231
]);
232232
});
233233

234+
it('should spread update arrays into array targets', async () => {
235+
const baseOAS = {
236+
servers: [{url: 'https://api.example.com'}, {url: 'https://api.backup.example.com'}]
237+
};
238+
const overlaySet = {
239+
actions: [
240+
{
241+
target: '$.servers',
242+
update: [{url: 'https://api.eu.example.com'}, {url: 'https://api.us.example.com'}]
243+
}
244+
]
245+
};
246+
247+
const result = await openapiOverlay(baseOAS, {overlaySet});
248+
expect(result.data.servers).toEqual([
249+
{url: 'https://api.example.com'},
250+
{url: 'https://api.backup.example.com'},
251+
{url: 'https://api.eu.example.com'},
252+
{url: 'https://api.us.example.com'}
253+
]);
254+
});
255+
234256
it('should replace primitive values when using update', async () => {
235257
const baseOAS = {info: {title: 'Old title'}};
236258
const overlaySet = {
@@ -290,6 +312,23 @@ describe('openapi-format CLI overlay tests', () => {
290312
]);
291313
});
292314

315+
it('should spread copied arrays into array targets', async () => {
316+
const baseOAS = {
317+
servers: [{url: 'https://api.example.com'}],
318+
serverPool: [{url: 'https://api.eu.example.com'}, {url: 'https://api.us.example.com'}]
319+
};
320+
const overlaySet = {
321+
actions: [{target: '$.servers', copy: true, from: '$.serverPool'}]
322+
};
323+
324+
const result = await openapiOverlay(baseOAS, {overlaySet});
325+
expect(result.data.servers).toEqual([
326+
{url: 'https://api.example.com'},
327+
{url: 'https://api.eu.example.com'},
328+
{url: 'https://api.us.example.com'}
329+
]);
330+
});
331+
293332
it('should replace primitive targets when copying primitive values', async () => {
294333
const baseOAS = {
295334
info: {title: 'Old title', description: 'New title'}

types/openapi-format.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ declare module 'openapi-format' {
103103

104104
export interface OpenAPIOverlayAction {
105105
target: string;
106-
update?: Record<string, unknown>;
106+
update?: unknown;
107107
remove?: boolean;
108108
copy?: boolean;
109109
from?: string;

0 commit comments

Comments
 (0)