@zuplo/cli 6.62.7 → 6.62.9
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.
- package/README.md +36 -4
- package/dist/__tests__/import-openapi-utils.test.js +1 -2
- package/dist/__tests__/import-openapi-utils.test.js.map +1 -1
- package/dist/__tests__/import-openapi.test.js +1 -5
- package/dist/__tests__/import-openapi.test.js.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/cmds/open-api/convert.d.ts +9 -0
- package/dist/cmds/open-api/convert.d.ts.map +1 -0
- package/dist/cmds/open-api/convert.js +66 -0
- package/dist/cmds/open-api/convert.js.map +1 -0
- package/dist/cmds/open-api/index.d.ts +4 -0
- package/dist/cmds/open-api/index.d.ts.map +1 -0
- package/dist/cmds/open-api/index.js +15 -0
- package/dist/cmds/open-api/index.js.map +1 -0
- package/dist/cmds/open-api/merge.d.ts +9 -0
- package/dist/cmds/open-api/merge.d.ts.map +1 -0
- package/dist/cmds/open-api/merge.js +57 -0
- package/dist/cmds/open-api/merge.js.map +1 -0
- package/dist/cmds/open-api/overlay.d.ts +9 -0
- package/dist/cmds/open-api/overlay.d.ts.map +1 -0
- package/dist/cmds/open-api/overlay.js +85 -0
- package/dist/cmds/open-api/overlay.js.map +1 -0
- package/dist/cmds/source/import-openapi.d.ts +1 -0
- package/dist/cmds/source/import-openapi.d.ts.map +1 -1
- package/dist/cmds/source/import-openapi.js +6 -9
- package/dist/cmds/source/import-openapi.js.map +1 -1
- package/dist/cmds/source/migrate.js +1 -1
- package/dist/cmds/source/migrate.js.map +1 -1
- package/dist/common/file-format.d.ts +25 -0
- package/dist/common/file-format.d.ts.map +1 -0
- package/dist/common/file-format.js +72 -0
- package/dist/common/file-format.js.map +1 -0
- package/dist/common/runner.d.ts.map +1 -0
- package/dist/common/runner.js.map +1 -0
- package/dist/common/utils/stringify-config.d.ts.map +1 -0
- package/dist/common/utils/stringify-config.js.map +1 -0
- package/dist/common/utils/stringify-config.test.d.ts.map +1 -0
- package/dist/common/utils/stringify-config.test.js.map +1 -0
- package/dist/open-api/convert/convert-engine.d.ts +26 -0
- package/dist/open-api/convert/convert-engine.d.ts.map +1 -0
- package/dist/open-api/convert/convert-engine.js +20 -0
- package/dist/open-api/convert/convert-engine.js.map +1 -0
- package/dist/open-api/convert/convert-engine.spec.d.ts +2 -0
- package/dist/open-api/convert/convert-engine.spec.d.ts.map +1 -0
- package/dist/open-api/convert/convert-engine.spec.js +268 -0
- package/dist/open-api/convert/convert-engine.spec.js.map +1 -0
- package/dist/open-api/convert/handler.d.ts +9 -0
- package/dist/open-api/convert/handler.d.ts.map +1 -0
- package/dist/open-api/convert/handler.js +54 -0
- package/dist/open-api/convert/handler.js.map +1 -0
- package/dist/open-api/convert/handler.spec.d.ts +2 -0
- package/dist/open-api/convert/handler.spec.d.ts.map +1 -0
- package/dist/open-api/convert/handler.spec.js +291 -0
- package/dist/open-api/convert/handler.spec.js.map +1 -0
- package/dist/open-api/merge/ajv.d.ts.map +1 -0
- package/dist/open-api/merge/ajv.js.map +1 -0
- package/dist/open-api/merge/handler.d.ts +9 -0
- package/dist/open-api/merge/handler.d.ts.map +1 -0
- package/dist/{source/import-openapi → open-api/merge}/handler.js +16 -42
- package/dist/open-api/merge/handler.js.map +1 -0
- package/dist/open-api/merge/handler.spec.d.ts +2 -0
- package/dist/open-api/merge/handler.spec.d.ts.map +1 -0
- package/dist/open-api/merge/handler.spec.js +335 -0
- package/dist/open-api/merge/handler.spec.js.map +1 -0
- package/dist/open-api/merge/interfaces.d.ts.map +1 -0
- package/dist/open-api/merge/interfaces.js.map +1 -0
- package/dist/open-api/merge/merge-engine.d.ts +23 -0
- package/dist/open-api/merge/merge-engine.d.ts.map +1 -0
- package/dist/open-api/merge/merge-engine.js +33 -0
- package/dist/open-api/merge/merge-engine.js.map +1 -0
- package/dist/open-api/merge/merge-engine.spec.d.ts +2 -0
- package/dist/open-api/merge/merge-engine.spec.d.ts.map +1 -0
- package/dist/open-api/merge/merge-engine.spec.js +117 -0
- package/dist/open-api/merge/merge-engine.spec.js.map +1 -0
- package/dist/open-api/merge/utils.d.ts.map +1 -0
- package/dist/open-api/merge/utils.js.map +1 -0
- package/dist/open-api/overlay/handler.d.ts +10 -0
- package/dist/open-api/overlay/handler.d.ts.map +1 -0
- package/dist/open-api/overlay/handler.js +92 -0
- package/dist/open-api/overlay/handler.js.map +1 -0
- package/dist/open-api/overlay/handler.spec.d.ts +2 -0
- package/dist/open-api/overlay/handler.spec.d.ts.map +1 -0
- package/dist/open-api/overlay/handler.spec.js +304 -0
- package/dist/open-api/overlay/handler.spec.js.map +1 -0
- package/dist/open-api/overlay/overlay-engine.d.ts +55 -0
- package/dist/open-api/overlay/overlay-engine.d.ts.map +1 -0
- package/dist/open-api/overlay/overlay-engine.js +280 -0
- package/dist/open-api/overlay/overlay-engine.js.map +1 -0
- package/dist/open-api/overlay/overlay-engine.spec.d.ts +2 -0
- package/dist/open-api/overlay/overlay-engine.spec.d.ts.map +1 -0
- package/dist/open-api/overlay/overlay-engine.spec.js +609 -0
- package/dist/open-api/overlay/overlay-engine.spec.js.map +1 -0
- package/dist/source/migrate/dev-portal/handler.d.ts.map +1 -0
- package/dist/{cmds/source/migrate → source/migrate/dev-portal}/handler.js +53 -4
- package/dist/source/migrate/dev-portal/handler.js.map +1 -0
- package/dist/{cmds/source/migrate → source/migrate/dev-portal}/types.d.ts +12 -1
- package/dist/source/migrate/dev-portal/types.d.ts.map +1 -0
- package/dist/source/migrate/dev-portal/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/dist/cmds/source/migrate/handler.d.ts.map +0 -1
- package/dist/cmds/source/migrate/handler.js.map +0 -1
- package/dist/cmds/source/migrate/runner.d.ts.map +0 -1
- package/dist/cmds/source/migrate/runner.js.map +0 -1
- package/dist/cmds/source/migrate/stringify-config.d.ts.map +0 -1
- package/dist/cmds/source/migrate/stringify-config.js.map +0 -1
- package/dist/cmds/source/migrate/stringify-config.test.d.ts.map +0 -1
- package/dist/cmds/source/migrate/stringify-config.test.js.map +0 -1
- package/dist/cmds/source/migrate/types.d.ts.map +0 -1
- package/dist/cmds/source/migrate/types.js.map +0 -1
- package/dist/source/import-openapi/ajv.d.ts.map +0 -1
- package/dist/source/import-openapi/ajv.js.map +0 -1
- package/dist/source/import-openapi/handler.d.ts +0 -13
- package/dist/source/import-openapi/handler.d.ts.map +0 -1
- package/dist/source/import-openapi/handler.js.map +0 -1
- package/dist/source/import-openapi/interfaces.d.ts.map +0 -1
- package/dist/source/import-openapi/interfaces.js.map +0 -1
- package/dist/source/import-openapi/utils.d.ts.map +0 -1
- package/dist/source/import-openapi/utils.js.map +0 -1
- /package/dist/{cmds/source/migrate → common}/runner.d.ts +0 -0
- /package/dist/{cmds/source/migrate → common}/runner.js +0 -0
- /package/dist/{cmds/source/migrate → common/utils}/stringify-config.d.ts +0 -0
- /package/dist/{cmds/source/migrate → common/utils}/stringify-config.js +0 -0
- /package/dist/{cmds/source/migrate → common/utils}/stringify-config.test.d.ts +0 -0
- /package/dist/{cmds/source/migrate → common/utils}/stringify-config.test.js +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/ajv.d.ts +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/ajv.js +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/interfaces.d.ts +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/interfaces.js +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/utils.d.ts +0 -0
- /package/dist/{source/import-openapi → open-api/merge}/utils.js +0 -0
- /package/dist/{cmds/source/migrate → source/migrate/dev-portal}/handler.d.ts +0 -0
- /package/dist/{cmds/source/migrate → source/migrate/dev-portal}/types.js +0 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { describe, it } from "node:test";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { applyOverlay, applyAction, deepClone, deepMerge, checkCondition, setValueAtPath, extractPathOrder, reorderOperationProperties, } 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
|
+
assert.strictEqual(doc.items[0].name, "First Item");
|
|
127
|
+
});
|
|
128
|
+
it("should handle mixed dot and bracket notation", () => {
|
|
129
|
+
const doc = {};
|
|
130
|
+
setValueAtPath(doc, "$.components.schemas['User'].properties.id", {
|
|
131
|
+
type: "string",
|
|
132
|
+
});
|
|
133
|
+
assert.deepStrictEqual(doc, {
|
|
134
|
+
components: {
|
|
135
|
+
schemas: {
|
|
136
|
+
User: {
|
|
137
|
+
properties: {
|
|
138
|
+
id: { type: "string" },
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
describe("applyAction - update operations", () => {
|
|
147
|
+
it("should update root level properties", () => {
|
|
148
|
+
const doc = { info: { title: "Old Title" } };
|
|
149
|
+
const action = {
|
|
150
|
+
target: "$",
|
|
151
|
+
update: { info: { version: "1.0.0" } },
|
|
152
|
+
};
|
|
153
|
+
const result = applyAction(doc, action);
|
|
154
|
+
assert.strictEqual(result.applied, true);
|
|
155
|
+
assert.strictEqual(result.count, 1);
|
|
156
|
+
assert.deepStrictEqual(doc.info, {
|
|
157
|
+
title: "Old Title",
|
|
158
|
+
version: "1.0.0",
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
it("should update existing nested property", () => {
|
|
162
|
+
const doc = {
|
|
163
|
+
paths: {
|
|
164
|
+
"/users": {
|
|
165
|
+
get: { summary: "Old summary" },
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
const action = {
|
|
170
|
+
target: "$.paths['/users'].get",
|
|
171
|
+
update: { summary: "New summary", description: "Get all users" },
|
|
172
|
+
};
|
|
173
|
+
const result = applyAction(doc, action);
|
|
174
|
+
assert.strictEqual(result.applied, true);
|
|
175
|
+
assert.strictEqual(result.count, 1);
|
|
176
|
+
assert.strictEqual(doc.paths["/users"].get.summary, "New summary");
|
|
177
|
+
assert.strictEqual(doc.paths["/users"].get.description, "Get all users");
|
|
178
|
+
});
|
|
179
|
+
it("should create new property if it doesn't exist", () => {
|
|
180
|
+
const doc = { paths: {} };
|
|
181
|
+
const action = {
|
|
182
|
+
target: "$.paths['/users']",
|
|
183
|
+
update: { get: { summary: "Get users" } },
|
|
184
|
+
};
|
|
185
|
+
const result = applyAction(doc, action);
|
|
186
|
+
assert.strictEqual(result.applied, true);
|
|
187
|
+
assert.strictEqual(result.count, 1);
|
|
188
|
+
assert.deepStrictEqual(doc.paths["/users"], {
|
|
189
|
+
get: { summary: "Get users" },
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
it("should update multiple nodes with wildcard", () => {
|
|
193
|
+
const doc = {
|
|
194
|
+
paths: {
|
|
195
|
+
"/users": { get: { tags: [] } },
|
|
196
|
+
"/posts": { get: { tags: [] } },
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
const action = {
|
|
200
|
+
target: "$.paths.*.get",
|
|
201
|
+
update: { tags: ["public"] },
|
|
202
|
+
};
|
|
203
|
+
const result = applyAction(doc, action);
|
|
204
|
+
assert.strictEqual(result.applied, true);
|
|
205
|
+
assert.strictEqual(result.count, 2);
|
|
206
|
+
assert.deepStrictEqual(doc.paths["/users"].get.tags, ["public"]);
|
|
207
|
+
assert.deepStrictEqual(doc.paths["/posts"].get.tags, ["public"]);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
describe("applyAction - remove operations", () => {
|
|
211
|
+
it("should remove a property from object", () => {
|
|
212
|
+
const doc = {
|
|
213
|
+
paths: {
|
|
214
|
+
"/users": { get: {}, delete: {} },
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
const action = {
|
|
218
|
+
target: "$.paths['/users'].delete",
|
|
219
|
+
remove: true,
|
|
220
|
+
};
|
|
221
|
+
const result = applyAction(doc, action);
|
|
222
|
+
assert.strictEqual(result.applied, true);
|
|
223
|
+
assert.strictEqual(result.count, 1);
|
|
224
|
+
assert.strictEqual("delete" in doc.paths["/users"], false);
|
|
225
|
+
assert.ok("get" in doc.paths["/users"]);
|
|
226
|
+
});
|
|
227
|
+
it("should remove multiple properties with wildcard", () => {
|
|
228
|
+
const doc = {
|
|
229
|
+
paths: {
|
|
230
|
+
"/users": { get: {}, delete: {} },
|
|
231
|
+
"/posts": { get: {}, delete: {} },
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
const action = {
|
|
235
|
+
target: "$.paths.*.delete",
|
|
236
|
+
remove: true,
|
|
237
|
+
};
|
|
238
|
+
const result = applyAction(doc, action);
|
|
239
|
+
assert.strictEqual(result.applied, true);
|
|
240
|
+
assert.strictEqual(result.count, 2);
|
|
241
|
+
assert.strictEqual("delete" in doc.paths["/users"], false);
|
|
242
|
+
assert.strictEqual("delete" in doc.paths["/posts"], false);
|
|
243
|
+
});
|
|
244
|
+
it("should conditionally remove empty objects", () => {
|
|
245
|
+
const doc = {
|
|
246
|
+
paths: {
|
|
247
|
+
"/users": { get: {} },
|
|
248
|
+
"/posts": {},
|
|
249
|
+
"/comments": { get: {} },
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
const action = {
|
|
253
|
+
target: "$.paths.*",
|
|
254
|
+
remove: { empty: true },
|
|
255
|
+
};
|
|
256
|
+
const result = applyAction(doc, action);
|
|
257
|
+
assert.strictEqual(result.applied, true);
|
|
258
|
+
assert.strictEqual(result.count, 1);
|
|
259
|
+
assert.ok("/users" in doc.paths);
|
|
260
|
+
assert.strictEqual("/posts" in doc.paths, false);
|
|
261
|
+
assert.ok("/comments" in doc.paths);
|
|
262
|
+
});
|
|
263
|
+
it("should conditionally remove when property is missing", () => {
|
|
264
|
+
const doc = {
|
|
265
|
+
paths: {
|
|
266
|
+
"/users": { get: { "x-internal": true } },
|
|
267
|
+
"/posts": { get: {} },
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
const action = {
|
|
271
|
+
target: "$.paths.*",
|
|
272
|
+
remove: { missing: "get.x-internal" },
|
|
273
|
+
};
|
|
274
|
+
const result = applyAction(doc, action);
|
|
275
|
+
assert.strictEqual(result.applied, true);
|
|
276
|
+
assert.strictEqual(result.count, 1);
|
|
277
|
+
assert.ok("/users" in doc.paths);
|
|
278
|
+
assert.strictEqual("/posts" in doc.paths, false);
|
|
279
|
+
});
|
|
280
|
+
it("should return false if target not found", () => {
|
|
281
|
+
const doc = { paths: {} };
|
|
282
|
+
const action = {
|
|
283
|
+
target: "$.paths['/users']",
|
|
284
|
+
remove: true,
|
|
285
|
+
};
|
|
286
|
+
const result = applyAction(doc, action);
|
|
287
|
+
assert.strictEqual(result.applied, false);
|
|
288
|
+
assert.strictEqual(result.count, 0);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
describe("extractPathOrder", () => {
|
|
292
|
+
it("should extract path order from overlay actions", () => {
|
|
293
|
+
const overlay = {
|
|
294
|
+
overlay: "1.0.0",
|
|
295
|
+
info: { title: "Test", version: "1.0.0" },
|
|
296
|
+
actions: [
|
|
297
|
+
{ target: "$.paths['/users'].get", update: {} },
|
|
298
|
+
{ target: "$.paths['/posts'].get", update: {} },
|
|
299
|
+
{ target: "$.paths['/users'].post", update: {} },
|
|
300
|
+
{ target: "$.info", update: {} },
|
|
301
|
+
],
|
|
302
|
+
};
|
|
303
|
+
const order = extractPathOrder(overlay);
|
|
304
|
+
assert.deepStrictEqual(order, ["/users", "/posts"]);
|
|
305
|
+
});
|
|
306
|
+
it("should return empty array if no path actions", () => {
|
|
307
|
+
const overlay = {
|
|
308
|
+
overlay: "1.0.0",
|
|
309
|
+
info: { title: "Test", version: "1.0.0" },
|
|
310
|
+
actions: [{ target: "$.info", update: {} }],
|
|
311
|
+
};
|
|
312
|
+
const order = extractPathOrder(overlay);
|
|
313
|
+
assert.deepStrictEqual(order, []);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe("reorderOperationProperties", () => {
|
|
317
|
+
it("should reorder operation properties with priority keys first", () => {
|
|
318
|
+
const operation = {
|
|
319
|
+
responses: {},
|
|
320
|
+
parameters: [],
|
|
321
|
+
operationId: "getUsers",
|
|
322
|
+
description: "Get all users",
|
|
323
|
+
summary: "Get users",
|
|
324
|
+
};
|
|
325
|
+
const result = reorderOperationProperties(operation);
|
|
326
|
+
const keys = Object.keys(result);
|
|
327
|
+
assert.strictEqual(keys[0], "summary");
|
|
328
|
+
assert.strictEqual(keys[1], "description");
|
|
329
|
+
assert.strictEqual(keys[2], "operationId");
|
|
330
|
+
assert.strictEqual(keys[3], "responses");
|
|
331
|
+
assert.strictEqual(keys[4], "parameters");
|
|
332
|
+
});
|
|
333
|
+
it("should handle missing priority keys", () => {
|
|
334
|
+
const operation = {
|
|
335
|
+
responses: {},
|
|
336
|
+
operationId: "getUsers",
|
|
337
|
+
};
|
|
338
|
+
const result = reorderOperationProperties(operation);
|
|
339
|
+
const keys = Object.keys(result);
|
|
340
|
+
assert.strictEqual(keys[0], "operationId");
|
|
341
|
+
assert.strictEqual(keys[1], "responses");
|
|
342
|
+
});
|
|
343
|
+
});
|
|
344
|
+
describe("applyOverlay - full integration", () => {
|
|
345
|
+
it("should apply a complete overlay document", () => {
|
|
346
|
+
const openapi = {
|
|
347
|
+
openapi: "3.1.0",
|
|
348
|
+
info: {
|
|
349
|
+
title: "Original API",
|
|
350
|
+
version: "1.0.0",
|
|
351
|
+
},
|
|
352
|
+
paths: {
|
|
353
|
+
"/users": {
|
|
354
|
+
get: {
|
|
355
|
+
summary: "Get users",
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
const overlay = {
|
|
361
|
+
overlay: "1.0.0",
|
|
362
|
+
info: {
|
|
363
|
+
title: "My Overlay",
|
|
364
|
+
version: "1.0.0",
|
|
365
|
+
},
|
|
366
|
+
actions: [
|
|
367
|
+
{
|
|
368
|
+
target: "$.info",
|
|
369
|
+
description: "Update API info",
|
|
370
|
+
update: {
|
|
371
|
+
title: "Updated API",
|
|
372
|
+
description: "An updated API",
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
target: "$.paths['/users'].get",
|
|
377
|
+
description: "Add operation ID",
|
|
378
|
+
update: {
|
|
379
|
+
operationId: "getUsers",
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
};
|
|
384
|
+
const { result, stats } = applyOverlay(openapi, overlay);
|
|
385
|
+
assert.strictEqual(stats.applied, 2);
|
|
386
|
+
assert.strictEqual(stats.skipped, 0);
|
|
387
|
+
assert.strictEqual(stats.totalNodes, 2);
|
|
388
|
+
assert.strictEqual(result.info.title, "Updated API");
|
|
389
|
+
assert.strictEqual(result.info.description, "An updated API");
|
|
390
|
+
assert.strictEqual(result.info.version, "1.0.0");
|
|
391
|
+
assert.strictEqual(result.paths["/users"].get.operationId, "getUsers");
|
|
392
|
+
});
|
|
393
|
+
it("should handle overlay with remove actions", () => {
|
|
394
|
+
const openapi = {
|
|
395
|
+
openapi: "3.1.0",
|
|
396
|
+
info: { title: "API" },
|
|
397
|
+
paths: {
|
|
398
|
+
"/users": { get: {}, delete: {} },
|
|
399
|
+
"/internal": { get: {} },
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
const overlay = {
|
|
403
|
+
overlay: "1.0.0",
|
|
404
|
+
info: { title: "Overlay", version: "1.0.0" },
|
|
405
|
+
actions: [
|
|
406
|
+
{
|
|
407
|
+
target: "$.paths.*.delete",
|
|
408
|
+
description: "Remove all delete operations",
|
|
409
|
+
remove: true,
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
target: "$.paths['/internal']",
|
|
413
|
+
description: "Remove internal path",
|
|
414
|
+
remove: true,
|
|
415
|
+
},
|
|
416
|
+
],
|
|
417
|
+
};
|
|
418
|
+
const { result, stats } = applyOverlay(openapi, overlay);
|
|
419
|
+
assert.strictEqual(stats.applied, 2);
|
|
420
|
+
assert.strictEqual(stats.totalNodes, 2);
|
|
421
|
+
assert.strictEqual("delete" in result.paths["/users"], false);
|
|
422
|
+
assert.strictEqual("/internal" in result.paths, false);
|
|
423
|
+
assert.ok("/users" in result.paths);
|
|
424
|
+
});
|
|
425
|
+
it("should throw error for invalid overlay format", () => {
|
|
426
|
+
const openapi = { openapi: "3.1.0" };
|
|
427
|
+
const invalidOverlay = {
|
|
428
|
+
info: { title: "Invalid" },
|
|
429
|
+
};
|
|
430
|
+
assert.throws(() => applyOverlay(openapi, invalidOverlay), /Invalid overlay format/);
|
|
431
|
+
});
|
|
432
|
+
it("should handle empty actions array", () => {
|
|
433
|
+
const openapi = {
|
|
434
|
+
openapi: "3.1.0",
|
|
435
|
+
info: { title: "API" },
|
|
436
|
+
};
|
|
437
|
+
const overlay = {
|
|
438
|
+
overlay: "1.0.0",
|
|
439
|
+
info: { title: "Empty Overlay", version: "1.0.0" },
|
|
440
|
+
actions: [],
|
|
441
|
+
};
|
|
442
|
+
const { result, stats } = applyOverlay(openapi, overlay);
|
|
443
|
+
assert.strictEqual(stats.applied, 0);
|
|
444
|
+
assert.strictEqual(stats.skipped, 0);
|
|
445
|
+
assert.deepStrictEqual(result.info, openapi.info);
|
|
446
|
+
});
|
|
447
|
+
it("should apply overlay with wildcards and conditions", () => {
|
|
448
|
+
const openapi = {
|
|
449
|
+
openapi: "3.1.0",
|
|
450
|
+
paths: {
|
|
451
|
+
"/users": {
|
|
452
|
+
get: { "x-internal": true, tags: [] },
|
|
453
|
+
post: { tags: [] },
|
|
454
|
+
},
|
|
455
|
+
"/posts": { get: { tags: [] } },
|
|
456
|
+
"/internal": { get: { "x-internal": true, tags: [] } },
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
const overlay = {
|
|
460
|
+
overlay: "1.0.0",
|
|
461
|
+
info: { title: "Conditional Overlay", version: "1.0.0" },
|
|
462
|
+
actions: [
|
|
463
|
+
{
|
|
464
|
+
target: "$.paths.*.*.tags",
|
|
465
|
+
description: "Add default tag",
|
|
466
|
+
update: ["public"],
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
target: "$.paths.*",
|
|
470
|
+
description: "Remove paths without x-internal",
|
|
471
|
+
remove: { missing: "get.x-internal" },
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
};
|
|
475
|
+
const { result, stats } = applyOverlay(openapi, overlay);
|
|
476
|
+
assert.strictEqual(stats.applied, 2);
|
|
477
|
+
assert.ok("/users" in result.paths);
|
|
478
|
+
assert.ok("/internal" in result.paths);
|
|
479
|
+
assert.strictEqual("/posts" in result.paths, false);
|
|
480
|
+
});
|
|
481
|
+
it("should preserve document structure and order", () => {
|
|
482
|
+
const openapi = {
|
|
483
|
+
openapi: "3.1.0",
|
|
484
|
+
info: { title: "API", version: "1.0.0" },
|
|
485
|
+
servers: [{ url: "https://api.example.com" }],
|
|
486
|
+
paths: {},
|
|
487
|
+
};
|
|
488
|
+
const overlay = {
|
|
489
|
+
overlay: "1.0.0",
|
|
490
|
+
info: { title: "Overlay", version: "1.0.0" },
|
|
491
|
+
actions: [
|
|
492
|
+
{
|
|
493
|
+
target: "$.info",
|
|
494
|
+
update: { description: "Added description" },
|
|
495
|
+
},
|
|
496
|
+
],
|
|
497
|
+
};
|
|
498
|
+
const { result } = applyOverlay(openapi, overlay);
|
|
499
|
+
const keys = Object.keys(result);
|
|
500
|
+
assert.strictEqual(keys[0], "openapi");
|
|
501
|
+
assert.strictEqual(keys[1], "info");
|
|
502
|
+
assert.ok(keys.includes("servers"));
|
|
503
|
+
assert.ok(keys.includes("paths"));
|
|
504
|
+
assert.strictEqual(result.info.description, "Added description");
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
describe("Complex overlay scenarios", () => {
|
|
508
|
+
it("should handle deep nested updates", () => {
|
|
509
|
+
const openapi = {
|
|
510
|
+
components: {
|
|
511
|
+
schemas: {
|
|
512
|
+
User: {
|
|
513
|
+
type: "object",
|
|
514
|
+
properties: {
|
|
515
|
+
id: { type: "string" },
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
},
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
const overlay = {
|
|
522
|
+
overlay: "1.0.0",
|
|
523
|
+
info: { title: "Schema Overlay", version: "1.0.0" },
|
|
524
|
+
actions: [
|
|
525
|
+
{
|
|
526
|
+
target: "$.components.schemas.User.properties",
|
|
527
|
+
update: {
|
|
528
|
+
name: { type: "string" },
|
|
529
|
+
email: { type: "string", format: "email" },
|
|
530
|
+
},
|
|
531
|
+
},
|
|
532
|
+
],
|
|
533
|
+
};
|
|
534
|
+
const { result } = applyOverlay(openapi, overlay);
|
|
535
|
+
assert.ok(result.components.schemas.User.properties.id);
|
|
536
|
+
assert.ok(result.components.schemas.User.properties.name);
|
|
537
|
+
assert.ok(result.components.schemas.User.properties.email);
|
|
538
|
+
assert.strictEqual(result.components.schemas.User.properties.email.format, "email");
|
|
539
|
+
});
|
|
540
|
+
it("should handle array element removal", () => {
|
|
541
|
+
const openapi = {
|
|
542
|
+
servers: [
|
|
543
|
+
{ url: "https://prod.example.com", description: "Production" },
|
|
544
|
+
{ url: "https://staging.example.com", description: "Staging" },
|
|
545
|
+
{ url: "https://dev.example.com", description: "Development" },
|
|
546
|
+
],
|
|
547
|
+
};
|
|
548
|
+
const overlay = {
|
|
549
|
+
overlay: "1.0.0",
|
|
550
|
+
info: { title: "Server Overlay", version: "1.0.0" },
|
|
551
|
+
actions: [
|
|
552
|
+
{
|
|
553
|
+
target: "$.servers[?(@.description=='Development')]",
|
|
554
|
+
remove: true,
|
|
555
|
+
},
|
|
556
|
+
],
|
|
557
|
+
};
|
|
558
|
+
const { result } = applyOverlay(openapi, overlay);
|
|
559
|
+
assert.strictEqual(result.servers.length, 2);
|
|
560
|
+
assert.strictEqual(result.servers[0].description, "Production");
|
|
561
|
+
assert.strictEqual(result.servers[1].description, "Staging");
|
|
562
|
+
});
|
|
563
|
+
it("should handle parameter merging correctly", () => {
|
|
564
|
+
const openapi = {
|
|
565
|
+
paths: {
|
|
566
|
+
"/users/{id}": {
|
|
567
|
+
parameters: [
|
|
568
|
+
{ name: "id", in: "path", required: true },
|
|
569
|
+
{ name: "fields", in: "query" },
|
|
570
|
+
],
|
|
571
|
+
get: {},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
};
|
|
575
|
+
const overlay = {
|
|
576
|
+
overlay: "1.0.0",
|
|
577
|
+
info: { title: "Parameter Overlay", version: "1.0.0" },
|
|
578
|
+
actions: [
|
|
579
|
+
{
|
|
580
|
+
target: "$.paths['/users/{id}'].parameters",
|
|
581
|
+
update: [
|
|
582
|
+
{
|
|
583
|
+
name: "id",
|
|
584
|
+
in: "path",
|
|
585
|
+
description: "User ID",
|
|
586
|
+
schema: { type: "string" },
|
|
587
|
+
},
|
|
588
|
+
{ name: "include", in: "query", description: "Include related" },
|
|
589
|
+
],
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
};
|
|
593
|
+
const { result } = applyOverlay(openapi, overlay);
|
|
594
|
+
const params = result.paths["/users/{id}"].parameters;
|
|
595
|
+
assert.strictEqual(params.length, 3);
|
|
596
|
+
const idParam = params.find((p) => p.name === "id");
|
|
597
|
+
assert.ok(idParam);
|
|
598
|
+
assert.strictEqual(idParam.required, true);
|
|
599
|
+
assert.strictEqual(idParam.description, "User ID");
|
|
600
|
+
assert.deepStrictEqual(idParam.schema, { type: "string" });
|
|
601
|
+
const fieldsParam = params.find((p) => p.name === "fields");
|
|
602
|
+
assert.ok(fieldsParam);
|
|
603
|
+
const includeParam = params.find((p) => p.name === "include");
|
|
604
|
+
assert.ok(includeParam);
|
|
605
|
+
assert.strictEqual(includeParam.description, "Include related");
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
});
|
|
609
|
+
//# sourceMappingURL=overlay-engine.spec.js.map
|