@zuplo/cli 6.65.8 → 6.66.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/__tests__/import-openapi.test.js +90 -1
  2. package/dist/__tests__/import-openapi.test.js.map +1 -1
  3. package/dist/open-api/convert/handler.js +2 -2
  4. package/dist/open-api/convert/handler.js.map +1 -1
  5. package/dist/open-api/merge/handler.d.ts +1 -1
  6. package/dist/open-api/merge/handler.d.ts.map +1 -1
  7. package/dist/open-api/merge/handler.js +4 -5
  8. package/dist/open-api/merge/handler.js.map +1 -1
  9. package/dist/open-api/overlay/handler.js +1 -2
  10. package/dist/open-api/overlay/handler.js.map +1 -1
  11. package/dist/tsconfig.tsbuildinfo +1 -1
  12. package/package.json +4 -4
  13. package/dist/__tests__/import-openapi-utils.test.d.ts +0 -2
  14. package/dist/__tests__/import-openapi-utils.test.d.ts.map +0 -1
  15. package/dist/__tests__/import-openapi-utils.test.js +0 -125
  16. package/dist/__tests__/import-openapi-utils.test.js.map +0 -1
  17. package/dist/__tests__/oas-test-data.d.ts +0 -98
  18. package/dist/__tests__/oas-test-data.d.ts.map +0 -1
  19. package/dist/__tests__/oas-test-data.js +0 -114
  20. package/dist/__tests__/oas-test-data.js.map +0 -1
  21. package/dist/common/file-format.d.ts +0 -25
  22. package/dist/common/file-format.d.ts.map +0 -1
  23. package/dist/common/file-format.js +0 -72
  24. package/dist/common/file-format.js.map +0 -1
  25. package/dist/common/open-api/constants.d.ts +0 -13
  26. package/dist/common/open-api/constants.d.ts.map +0 -1
  27. package/dist/common/open-api/constants.js +0 -16
  28. package/dist/common/open-api/constants.js.map +0 -1
  29. package/dist/common/open-api/index.d.ts +0 -3
  30. package/dist/common/open-api/index.d.ts.map +0 -1
  31. package/dist/common/open-api/index.js +0 -3
  32. package/dist/common/open-api/index.js.map +0 -1
  33. package/dist/common/open-api/validation.d.ts +0 -297
  34. package/dist/common/open-api/validation.d.ts.map +0 -1
  35. package/dist/common/open-api/validation.js +0 -88
  36. package/dist/common/open-api/validation.js.map +0 -1
  37. package/dist/open-api/convert/convert-engine.d.ts +0 -26
  38. package/dist/open-api/convert/convert-engine.d.ts.map +0 -1
  39. package/dist/open-api/convert/convert-engine.js +0 -20
  40. package/dist/open-api/convert/convert-engine.js.map +0 -1
  41. package/dist/open-api/convert/convert-engine.spec.d.ts +0 -2
  42. package/dist/open-api/convert/convert-engine.spec.d.ts.map +0 -1
  43. package/dist/open-api/convert/convert-engine.spec.js +0 -268
  44. package/dist/open-api/convert/convert-engine.spec.js.map +0 -1
  45. package/dist/open-api/merge/ajv.d.ts +0 -34
  46. package/dist/open-api/merge/ajv.d.ts.map +0 -1
  47. package/dist/open-api/merge/ajv.js +0 -2
  48. package/dist/open-api/merge/ajv.js.map +0 -1
  49. package/dist/open-api/merge/interfaces.d.ts +0 -72
  50. package/dist/open-api/merge/interfaces.d.ts.map +0 -1
  51. package/dist/open-api/merge/interfaces.js +0 -5
  52. package/dist/open-api/merge/interfaces.js.map +0 -1
  53. package/dist/open-api/merge/merge-engine.d.ts +0 -20
  54. package/dist/open-api/merge/merge-engine.d.ts.map +0 -1
  55. package/dist/open-api/merge/merge-engine.js +0 -34
  56. package/dist/open-api/merge/merge-engine.js.map +0 -1
  57. package/dist/open-api/merge/merge-engine.spec.d.ts +0 -2
  58. package/dist/open-api/merge/merge-engine.spec.d.ts.map +0 -1
  59. package/dist/open-api/merge/merge-engine.spec.js +0 -117
  60. package/dist/open-api/merge/merge-engine.spec.js.map +0 -1
  61. package/dist/open-api/merge/utils.d.ts +0 -11
  62. package/dist/open-api/merge/utils.d.ts.map +0 -1
  63. package/dist/open-api/merge/utils.js +0 -33
  64. package/dist/open-api/merge/utils.js.map +0 -1
  65. package/dist/open-api/overlay/overlay-engine.d.ts +0 -45
  66. package/dist/open-api/overlay/overlay-engine.d.ts.map +0 -1
  67. package/dist/open-api/overlay/overlay-engine.js +0 -309
  68. package/dist/open-api/overlay/overlay-engine.js.map +0 -1
  69. package/dist/open-api/overlay/overlay-engine.spec.d.ts +0 -2
  70. package/dist/open-api/overlay/overlay-engine.spec.d.ts.map +0 -1
  71. package/dist/open-api/overlay/overlay-engine.spec.js +0 -687
  72. package/dist/open-api/overlay/overlay-engine.spec.js.map +0 -1
@@ -1,687 +0,0 @@
1
- import assert from "node:assert";
2
- import { describe, it } from "node:test";
3
- import { applyAction, applyOverlay, checkCondition, deepClone, deepMerge, extractPathOrder, reorderOperationProperties, setValueAtPath, } from "./overlay-engine.js";
4
- describe("OpenAPI Overlay Engine", () => {
5
- describe("deepClone", () => {
6
- it("should deep clone an object", () => {
7
- const original = { a: 1, b: { c: 2 } };
8
- const cloned = deepClone(original);
9
- assert.deepStrictEqual(cloned, original);
10
- assert.notStrictEqual(cloned, original);
11
- assert.notStrictEqual(cloned.b, original.b);
12
- });
13
- it("should deep clone an array", () => {
14
- const original = [1, 2, { a: 3 }];
15
- const cloned = deepClone(original);
16
- assert.deepStrictEqual(cloned, original);
17
- assert.notStrictEqual(cloned, original);
18
- assert.notStrictEqual(cloned[2], original[2]);
19
- });
20
- });
21
- describe("deepMerge", () => {
22
- it("should merge two objects", () => {
23
- const target = { a: 1, b: 2 };
24
- const source = { b: 3, c: 4 };
25
- const result = deepMerge(target, source);
26
- assert.deepStrictEqual(result, { a: 1, b: 3, c: 4 });
27
- });
28
- it("should merge nested objects", () => {
29
- const target = { a: { b: 1, c: 2 } };
30
- const source = { a: { c: 3, d: 4 } };
31
- const result = deepMerge(target, source);
32
- assert.deepStrictEqual(result, { a: { b: 1, c: 3, d: 4 } });
33
- });
34
- it("should concatenate arrays by default", () => {
35
- const target = { arr: [1, 2] };
36
- const source = { arr: [3, 4] };
37
- const result = deepMerge(target, source);
38
- assert.deepStrictEqual(result, { arr: [1, 2, 3, 4] });
39
- });
40
- it("should merge OpenAPI parameters by name and in", () => {
41
- const target = {
42
- parameters: [
43
- { name: "id", in: "path", required: true },
44
- { name: "filter", in: "query" },
45
- ],
46
- };
47
- const source = {
48
- parameters: [
49
- { name: "id", in: "path", description: "The ID" },
50
- { name: "sort", in: "query" },
51
- ],
52
- };
53
- const result = deepMerge(target, source);
54
- assert.deepStrictEqual(result, {
55
- parameters: [
56
- { name: "id", in: "path", required: true, description: "The ID" },
57
- { name: "filter", in: "query" },
58
- { name: "sort", in: "query" },
59
- ],
60
- });
61
- });
62
- it("should replace target with source if types differ", () => {
63
- const target = { a: [1, 2] };
64
- const source = { a: "string" };
65
- const result = deepMerge(target, source);
66
- assert.deepStrictEqual(result, { a: "string" });
67
- });
68
- });
69
- describe("checkCondition", () => {
70
- it("should return true for empty object when empty condition is true", () => {
71
- assert.strictEqual(checkCondition({}, { empty: true }), true);
72
- });
73
- it("should return false for non-empty object when empty condition is true", () => {
74
- assert.strictEqual(checkCondition({ a: 1 }, { empty: true }), false);
75
- });
76
- it("should return true for empty array when empty condition is true", () => {
77
- assert.strictEqual(checkCondition([], { empty: true }), true);
78
- });
79
- it("should return false for non-empty array when empty condition is true", () => {
80
- assert.strictEqual(checkCondition([1], { empty: true }), false);
81
- });
82
- it("should return true when property is missing", () => {
83
- const obj = { a: { b: 1 } };
84
- assert.strictEqual(checkCondition(obj, { missing: "a.c" }), true);
85
- });
86
- it("should return false when property exists", () => {
87
- const obj = { a: { b: 1 } };
88
- assert.strictEqual(checkCondition(obj, { missing: "a.b" }), false);
89
- });
90
- });
91
- describe("setValueAtPath", () => {
92
- it("should set value at simple path", () => {
93
- const doc = {};
94
- setValueAtPath(doc, "$.info.title", "My API");
95
- assert.deepStrictEqual(doc, { info: { title: "My API" } });
96
- });
97
- it("should set value at bracket notation path", () => {
98
- const doc = {};
99
- setValueAtPath(doc, "$.paths['/users'].get", { summary: "Get users" });
100
- assert.deepStrictEqual(doc, {
101
- paths: { "/users": { get: { summary: "Get users" } } },
102
- });
103
- });
104
- it("should create nested paths as needed", () => {
105
- const doc = {};
106
- setValueAtPath(doc, "$.a.b.c.d", "value");
107
- assert.deepStrictEqual(doc, { a: { b: { c: { d: "value" } } } });
108
- });
109
- it("should handle double-quoted bracket notation", () => {
110
- const doc = {};
111
- setValueAtPath(doc, '$.paths["/users"].get', { summary: "Get users" });
112
- assert.deepStrictEqual(doc, {
113
- paths: { "/users": { get: { summary: "Get users" } } },
114
- });
115
- });
116
- it("should handle unquoted bracket notation", () => {
117
- const doc = {};
118
- setValueAtPath(doc, "$.paths[users].get", { summary: "Get users" });
119
- assert.deepStrictEqual(doc, {
120
- paths: { users: { get: { summary: "Get users" } } },
121
- });
122
- });
123
- it("should handle numeric indices", () => {
124
- const doc = { items: [{}, {}] };
125
- setValueAtPath(doc, "$.items[0].name", "First Item");
126
- const item = doc.items[0];
127
- assert.strictEqual(item.name, "First Item");
128
- });
129
- it("should handle mixed dot and bracket notation", () => {
130
- const doc = {};
131
- setValueAtPath(doc, "$.components.schemas['User'].properties.id", {
132
- type: "string",
133
- });
134
- assert.deepStrictEqual(doc, {
135
- components: {
136
- schemas: {
137
- User: {
138
- properties: {
139
- id: { type: "string" },
140
- },
141
- },
142
- },
143
- },
144
- });
145
- });
146
- });
147
- describe("applyAction - update operations", () => {
148
- it("should update root level properties", () => {
149
- const doc = { info: { title: "Old Title" } };
150
- const action = {
151
- target: "$",
152
- update: { info: { version: "1.0.0" } },
153
- };
154
- const result = applyAction(doc, action);
155
- assert.strictEqual(result.applied, true);
156
- assert.strictEqual(result.count, 1);
157
- assert.deepStrictEqual(doc.info, {
158
- title: "Old Title",
159
- version: "1.0.0",
160
- });
161
- });
162
- it("should update existing nested property", () => {
163
- const doc = {
164
- paths: {
165
- "/users": {
166
- get: { summary: "Old summary" },
167
- },
168
- },
169
- };
170
- const action = {
171
- target: "$.paths['/users'].get",
172
- update: { summary: "New summary", description: "Get all users" },
173
- };
174
- const result = applyAction(doc, action);
175
- assert.strictEqual(result.applied, true);
176
- assert.strictEqual(result.count, 1);
177
- const getOperation = doc.paths["/users"].get;
178
- assert.strictEqual(getOperation.summary, "New summary");
179
- assert.strictEqual(getOperation.description, "Get all users");
180
- });
181
- it("should create new property if it doesn't exist", () => {
182
- const doc = { paths: {} };
183
- const action = {
184
- target: "$.paths['/users']",
185
- update: { get: { summary: "Get users" } },
186
- };
187
- const result = applyAction(doc, action);
188
- assert.strictEqual(result.applied, true);
189
- assert.strictEqual(result.count, 1);
190
- const paths = doc.paths;
191
- assert.deepStrictEqual(paths["/users"], {
192
- get: { summary: "Get users" },
193
- });
194
- });
195
- it("should update multiple nodes with wildcard", () => {
196
- const doc = {
197
- paths: {
198
- "/users": { get: { tags: [] } },
199
- "/posts": { get: { tags: [] } },
200
- },
201
- };
202
- const action = {
203
- target: "$.paths.*.get",
204
- update: { tags: ["public"] },
205
- };
206
- const result = applyAction(doc, action);
207
- assert.strictEqual(result.applied, true);
208
- assert.strictEqual(result.count, 2);
209
- assert.deepStrictEqual(doc.paths["/users"].get.tags, ["public"]);
210
- assert.deepStrictEqual(doc.paths["/posts"].get.tags, ["public"]);
211
- });
212
- });
213
- describe("applyAction - remove operations", () => {
214
- it("should remove a property from object", () => {
215
- const doc = {
216
- paths: {
217
- "/users": { get: {}, delete: {} },
218
- },
219
- };
220
- const action = {
221
- target: "$.paths['/users'].delete",
222
- remove: true,
223
- };
224
- const result = applyAction(doc, action);
225
- assert.strictEqual(result.applied, true);
226
- assert.strictEqual(result.count, 1);
227
- assert.strictEqual("delete" in doc.paths["/users"], false);
228
- assert.ok("get" in doc.paths["/users"]);
229
- });
230
- it("should remove multiple properties with wildcard", () => {
231
- const doc = {
232
- paths: {
233
- "/users": { get: {}, delete: {} },
234
- "/posts": { get: {}, delete: {} },
235
- },
236
- };
237
- const action = {
238
- target: "$.paths.*.delete",
239
- remove: true,
240
- };
241
- const result = applyAction(doc, action);
242
- assert.strictEqual(result.applied, true);
243
- assert.strictEqual(result.count, 2);
244
- assert.strictEqual("delete" in doc.paths["/users"], false);
245
- assert.strictEqual("delete" in doc.paths["/posts"], false);
246
- });
247
- it("should conditionally remove empty objects", () => {
248
- const doc = {
249
- paths: {
250
- "/users": { get: {} },
251
- "/posts": {},
252
- "/comments": { get: {} },
253
- },
254
- };
255
- const action = {
256
- target: "$.paths.*",
257
- remove: { empty: true },
258
- };
259
- const result = applyAction(doc, action);
260
- assert.strictEqual(result.applied, true);
261
- assert.strictEqual(result.count, 1);
262
- assert.ok("/users" in doc.paths);
263
- assert.strictEqual("/posts" in doc.paths, false);
264
- assert.ok("/comments" in doc.paths);
265
- });
266
- it("should conditionally remove when property is missing", () => {
267
- const doc = {
268
- paths: {
269
- "/users": { get: { "x-internal": true } },
270
- "/posts": { get: {} },
271
- },
272
- };
273
- const action = {
274
- target: "$.paths.*",
275
- remove: { missing: "get.x-internal" },
276
- };
277
- const result = applyAction(doc, action);
278
- assert.strictEqual(result.applied, true);
279
- assert.strictEqual(result.count, 1);
280
- assert.ok("/users" in doc.paths);
281
- assert.strictEqual("/posts" in doc.paths, false);
282
- });
283
- it("should return false if target not found", () => {
284
- const doc = { paths: {} };
285
- const action = {
286
- target: "$.paths['/users']",
287
- remove: true,
288
- };
289
- const result = applyAction(doc, action);
290
- assert.strictEqual(result.applied, false);
291
- assert.strictEqual(result.count, 0);
292
- });
293
- });
294
- describe("extractPathOrder", () => {
295
- it("should extract path order from overlay actions", () => {
296
- const overlay = {
297
- overlay: "1.0.0",
298
- info: { title: "Test", version: "1.0.0" },
299
- actions: [
300
- { target: "$.paths['/users'].get", update: {} },
301
- { target: "$.paths['/posts'].get", update: {} },
302
- { target: "$.paths['/users'].post", update: {} },
303
- { target: "$.info", update: {} },
304
- ],
305
- };
306
- const order = extractPathOrder(overlay);
307
- assert.deepStrictEqual(order, ["/users", "/posts"]);
308
- });
309
- it("should return empty array if no path actions", () => {
310
- const overlay = {
311
- overlay: "1.0.0",
312
- info: { title: "Test", version: "1.0.0" },
313
- actions: [{ target: "$.info", update: {} }],
314
- };
315
- const order = extractPathOrder(overlay);
316
- assert.deepStrictEqual(order, []);
317
- });
318
- });
319
- describe("reorderOperationProperties", () => {
320
- it("should reorder operation properties with priority keys first", () => {
321
- const operation = {
322
- responses: {},
323
- parameters: [],
324
- operationId: "getUsers",
325
- description: "Get all users",
326
- summary: "Get users",
327
- };
328
- const result = reorderOperationProperties(operation);
329
- const keys = Object.keys(result);
330
- assert.strictEqual(keys[0], "summary");
331
- assert.strictEqual(keys[1], "description");
332
- assert.strictEqual(keys[2], "operationId");
333
- assert.strictEqual(keys[3], "responses");
334
- assert.strictEqual(keys[4], "parameters");
335
- });
336
- it("should handle missing priority keys", () => {
337
- const operation = {
338
- responses: {},
339
- operationId: "getUsers",
340
- };
341
- const result = reorderOperationProperties(operation);
342
- const keys = Object.keys(result);
343
- assert.strictEqual(keys[0], "operationId");
344
- assert.strictEqual(keys[1], "responses");
345
- });
346
- });
347
- describe("applyOverlay - full integration", () => {
348
- it("should apply a complete overlay document", () => {
349
- const openapi = {
350
- openapi: "3.1.0",
351
- info: {
352
- title: "Original API",
353
- version: "1.0.0",
354
- },
355
- paths: {
356
- "/users": {
357
- get: {
358
- summary: "Get users",
359
- },
360
- },
361
- },
362
- };
363
- const overlay = {
364
- overlay: "1.0.0",
365
- info: {
366
- title: "My Overlay",
367
- version: "1.0.0",
368
- },
369
- actions: [
370
- {
371
- target: "$.info",
372
- description: "Update API info",
373
- update: {
374
- title: "Updated API",
375
- description: "An updated API",
376
- },
377
- },
378
- {
379
- target: "$.paths['/users'].get",
380
- description: "Add operation ID",
381
- update: {
382
- operationId: "getUsers",
383
- },
384
- },
385
- ],
386
- };
387
- const { result, stats } = applyOverlay(openapi, overlay);
388
- assert.strictEqual(stats.applied, 2);
389
- assert.strictEqual(stats.skipped, 0);
390
- assert.strictEqual(stats.totalNodes, 2);
391
- const info = result.info;
392
- assert.strictEqual(info.title, "Updated API");
393
- assert.strictEqual(info.description, "An updated API");
394
- assert.strictEqual(info.version, "1.0.0");
395
- const paths = result.paths;
396
- const usersPath = paths["/users"];
397
- const getOperation = usersPath.get;
398
- assert.strictEqual(getOperation.operationId, "getUsers");
399
- });
400
- it("should handle overlay with remove actions", () => {
401
- const openapi = {
402
- openapi: "3.1.0",
403
- info: { title: "API" },
404
- paths: {
405
- "/users": { get: {}, delete: {} },
406
- "/internal": { get: {} },
407
- },
408
- };
409
- const overlay = {
410
- overlay: "1.0.0",
411
- info: { title: "Overlay", version: "1.0.0" },
412
- actions: [
413
- {
414
- target: "$.paths.*.delete",
415
- description: "Remove all delete operations",
416
- remove: true,
417
- },
418
- {
419
- target: "$.paths['/internal']",
420
- description: "Remove internal path",
421
- remove: true,
422
- },
423
- ],
424
- };
425
- const { result, stats } = applyOverlay(openapi, overlay);
426
- assert.strictEqual(stats.applied, 2);
427
- assert.strictEqual(stats.totalNodes, 2);
428
- const paths = result.paths;
429
- const usersPath = paths["/users"];
430
- assert.strictEqual("delete" in usersPath, false);
431
- assert.strictEqual("/internal" in paths, false);
432
- assert.ok("/users" in paths);
433
- });
434
- it("should throw error for invalid overlay format", () => {
435
- const openapi = {
436
- openapi: "3.1.0",
437
- info: { title: "Test", version: "1.0.0" },
438
- };
439
- const invalidOverlay = {
440
- info: { title: "Invalid" },
441
- };
442
- assert.throws(() => applyOverlay(openapi, invalidOverlay), /Invalid OpenAPI Overlay document/);
443
- });
444
- it("should throw actionable error for overlay with invalid action", () => {
445
- const openapi = {
446
- openapi: "3.1.0",
447
- info: { title: "Test", version: "1.0.0" },
448
- };
449
- const invalidOverlay = {
450
- overlay: "1.0.0",
451
- info: { title: "Test", version: "1.0.0" },
452
- actions: [
453
- {
454
- target: "$.paths",
455
- },
456
- ],
457
- };
458
- let errorMessage = "";
459
- try {
460
- applyOverlay(openapi, invalidOverlay);
461
- }
462
- catch (error) {
463
- errorMessage = error.message;
464
- }
465
- assert.ok(errorMessage.includes("Action must specify exactly one of 'update' or 'remove'"), `Expected actionable error message, got: ${errorMessage}`);
466
- });
467
- it("should work with incomplete OpenAPI documents", () => {
468
- const incompleteOpenapi = {
469
- paths: {},
470
- };
471
- const overlay = {
472
- overlay: "1.0.0",
473
- info: { title: "Test", version: "1.0.0" },
474
- actions: [{ target: "$.paths", update: { "/test": { get: {} } } }],
475
- };
476
- const { result } = applyOverlay(incompleteOpenapi, overlay);
477
- const paths = result.paths;
478
- assert.ok("/test" in paths);
479
- });
480
- it("should reject completely invalid OpenAPI document (not an object)", () => {
481
- const notAnObject = "this is a string";
482
- const overlay = {
483
- overlay: "1.0.0",
484
- info: { title: "Test", version: "1.0.0" },
485
- actions: [{ target: "$.paths", update: { "/test": {} } }],
486
- };
487
- let errorMessage = "";
488
- try {
489
- applyOverlay(notAnObject, overlay);
490
- }
491
- catch (error) {
492
- errorMessage = error.message;
493
- }
494
- assert.ok(errorMessage.includes("must be a valid JSON or YAML object"), `Expected error about document not being an object, got: ${errorMessage}`);
495
- });
496
- it("should reject empty actions array", () => {
497
- const openapi = {
498
- openapi: "3.1.0",
499
- info: { title: "API", version: "1.0.0" },
500
- };
501
- const invalidOverlay = {
502
- overlay: "1.0.0",
503
- info: { title: "Empty Overlay", version: "1.0.0" },
504
- actions: [],
505
- };
506
- let errorMessage = "";
507
- try {
508
- applyOverlay(openapi, invalidOverlay);
509
- }
510
- catch (error) {
511
- errorMessage = error.message;
512
- }
513
- assert.ok(errorMessage.includes("Overlay must contain at least one action"), `Expected validation error for empty actions, got: ${errorMessage}`);
514
- });
515
- it("should apply overlay with wildcards and conditions", () => {
516
- const openapi = {
517
- openapi: "3.1.0",
518
- paths: {
519
- "/users": {
520
- get: { "x-internal": true, tags: [] },
521
- post: { tags: [] },
522
- },
523
- "/posts": { get: { tags: [] } },
524
- "/internal": { get: { "x-internal": true, tags: [] } },
525
- },
526
- };
527
- const overlay = {
528
- overlay: "1.0.0",
529
- info: { title: "Conditional Overlay", version: "1.0.0" },
530
- actions: [
531
- {
532
- target: "$.paths.*.*.tags",
533
- description: "Add default tag",
534
- update: ["public"],
535
- },
536
- {
537
- target: "$.paths.*",
538
- description: "Remove paths without x-internal",
539
- remove: { missing: "get.x-internal" },
540
- },
541
- ],
542
- };
543
- const { result, stats } = applyOverlay(openapi, overlay);
544
- assert.strictEqual(stats.applied, 2);
545
- const paths = result.paths;
546
- assert.ok("/users" in paths);
547
- assert.ok("/internal" in paths);
548
- assert.strictEqual("/posts" in paths, false);
549
- });
550
- it("should preserve document structure and order", () => {
551
- const openapi = {
552
- openapi: "3.1.0",
553
- info: { title: "API", version: "1.0.0" },
554
- servers: [{ url: "https://api.example.com" }],
555
- paths: {},
556
- };
557
- const overlay = {
558
- overlay: "1.0.0",
559
- info: { title: "Overlay", version: "1.0.0" },
560
- actions: [
561
- {
562
- target: "$.info",
563
- update: { description: "Added description" },
564
- },
565
- ],
566
- };
567
- const { result } = applyOverlay(openapi, overlay);
568
- const keys = Object.keys(result);
569
- assert.strictEqual(keys[0], "openapi");
570
- assert.strictEqual(keys[1], "info");
571
- assert.ok(keys.includes("servers"));
572
- assert.ok(keys.includes("paths"));
573
- const info = result.info;
574
- assert.strictEqual(info.description, "Added description");
575
- });
576
- });
577
- describe("Complex overlay scenarios", () => {
578
- it("should handle deep nested updates", () => {
579
- const openapi = {
580
- components: {
581
- schemas: {
582
- User: {
583
- type: "object",
584
- properties: {
585
- id: { type: "string" },
586
- },
587
- },
588
- },
589
- },
590
- };
591
- const overlay = {
592
- overlay: "1.0.0",
593
- info: { title: "Schema Overlay", version: "1.0.0" },
594
- actions: [
595
- {
596
- target: "$.components.schemas.User.properties",
597
- update: {
598
- name: { type: "string" },
599
- email: { type: "string", format: "email" },
600
- },
601
- },
602
- ],
603
- };
604
- const { result } = applyOverlay(openapi, overlay);
605
- const components = result.components;
606
- const schemas = components.schemas;
607
- const userSchema = schemas.User;
608
- const properties = userSchema.properties;
609
- assert.ok(properties.id);
610
- assert.ok(properties.name);
611
- assert.ok(properties.email);
612
- const emailProperty = properties.email;
613
- assert.strictEqual(emailProperty.format, "email");
614
- });
615
- it("should handle array element removal", () => {
616
- const openapi = {
617
- servers: [
618
- { url: "https://prod.example.com", description: "Production" },
619
- { url: "https://staging.example.com", description: "Staging" },
620
- { url: "https://dev.example.com", description: "Development" },
621
- ],
622
- };
623
- const overlay = {
624
- overlay: "1.0.0",
625
- info: { title: "Server Overlay", version: "1.0.0" },
626
- actions: [
627
- {
628
- target: "$.servers[?(@.description=='Development')]",
629
- remove: true,
630
- },
631
- ],
632
- };
633
- const { result } = applyOverlay(openapi, overlay);
634
- const servers = result.servers;
635
- assert.strictEqual(servers.length, 2);
636
- assert.strictEqual(servers[0].description, "Production");
637
- assert.strictEqual(servers[1].description, "Staging");
638
- });
639
- it("should handle parameter merging correctly", () => {
640
- const openapi = {
641
- paths: {
642
- "/users/{id}": {
643
- parameters: [
644
- { name: "id", in: "path", required: true },
645
- { name: "fields", in: "query" },
646
- ],
647
- get: {},
648
- },
649
- },
650
- };
651
- const overlay = {
652
- overlay: "1.0.0",
653
- info: { title: "Parameter Overlay", version: "1.0.0" },
654
- actions: [
655
- {
656
- target: "$.paths['/users/{id}'].parameters",
657
- update: [
658
- {
659
- name: "id",
660
- in: "path",
661
- description: "User ID",
662
- schema: { type: "string" },
663
- },
664
- { name: "include", in: "query", description: "Include related" },
665
- ],
666
- },
667
- ],
668
- };
669
- const { result } = applyOverlay(openapi, overlay);
670
- const paths = result.paths;
671
- const usersPath = paths["/users/{id}"];
672
- const params = usersPath.parameters;
673
- assert.strictEqual(params.length, 3);
674
- const idParam = params.find((p) => p.name === "id");
675
- assert.ok(idParam);
676
- assert.strictEqual(idParam.required, true);
677
- assert.strictEqual(idParam.description, "User ID");
678
- assert.deepStrictEqual(idParam.schema, { type: "string" });
679
- const fieldsParam = params.find((p) => p.name === "fields");
680
- assert.ok(fieldsParam);
681
- const includeParam = params.find((p) => p.name === "include");
682
- assert.ok(includeParam);
683
- assert.strictEqual(includeParam.description, "Include related");
684
- });
685
- });
686
- });
687
- //# sourceMappingURL=overlay-engine.spec.js.map