zudoku 0.40.0 → 0.40.1
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/dist/config/validators/BuildSchema.d.ts +1 -0
- package/dist/config/validators/BuildSchema.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removeExtensions.d.ts +3 -2
- package/dist/lib/plugins/openapi/processors/removeExtensions.js +1 -1
- package/dist/lib/plugins/openapi/processors/removeExtensions.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removeExtensions.test.js +26 -6
- package/dist/lib/plugins/openapi/processors/removeExtensions.test.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removeParameters.d.ts +3 -1
- package/dist/lib/plugins/openapi/processors/removeParameters.js +1 -1
- package/dist/lib/plugins/openapi/processors/removeParameters.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removeParameters.test.js +53 -25
- package/dist/lib/plugins/openapi/processors/removeParameters.test.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removePaths.d.ts +3 -1
- package/dist/lib/plugins/openapi/processors/removePaths.js +1 -1
- package/dist/lib/plugins/openapi/processors/removePaths.js.map +1 -1
- package/dist/lib/plugins/openapi/processors/removePaths.test.js +75 -35
- package/dist/lib/plugins/openapi/processors/removePaths.test.js.map +1 -1
- package/dist/vite/plugin-api.js +3 -9
- package/dist/vite/plugin-api.js.map +1 -1
- package/dist/zuplo/enrich-with-zuplo.d.ts +3 -3
- package/dist/zuplo/enrich-with-zuplo.js +18 -17
- package/dist/zuplo/enrich-with-zuplo.js.map +1 -1
- package/dist/zuplo/with-zuplo-processors.d.ts +2 -2
- package/dist/zuplo/with-zuplo-processors.js +3 -3
- package/dist/zuplo/with-zuplo-processors.js.map +1 -1
- package/lib/processors/removeExtensions.js +1 -1
- package/lib/processors/removeExtensions.js.map +1 -1
- package/lib/processors/removeParameters.js +1 -1
- package/lib/processors/removeParameters.js.map +1 -1
- package/lib/processors/removePaths.js +1 -1
- package/lib/processors/removePaths.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/plugins/openapi/processors/removeExtensions.test.ts +29 -9
- package/src/lib/plugins/openapi/processors/removeExtensions.ts +5 -3
- package/src/lib/plugins/openapi/processors/removeParameters.test.ts +67 -33
- package/src/lib/plugins/openapi/processors/removeParameters.ts +5 -3
- package/src/lib/plugins/openapi/processors/removePaths.test.ts +85 -44
- package/src/lib/plugins/openapi/processors/removePaths.ts +5 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { OpenAPIDocument } from "../../../oas/parser/index.js";
|
|
2
3
|
import { removePaths } from "./removePaths.js";
|
|
3
4
|
|
|
4
5
|
const baseDoc = {
|
|
@@ -15,7 +16,7 @@ const baseDoc = {
|
|
|
15
16
|
get: { summary: "Another example" },
|
|
16
17
|
},
|
|
17
18
|
},
|
|
18
|
-
};
|
|
19
|
+
} as unknown as OpenAPIDocument;
|
|
19
20
|
|
|
20
21
|
describe("removePaths", () => {
|
|
21
22
|
it("removes paths specified in the paths option", () => {
|
|
@@ -23,11 +24,15 @@ describe("removePaths", () => {
|
|
|
23
24
|
paths: {
|
|
24
25
|
"/remove-me": true,
|
|
25
26
|
},
|
|
26
|
-
})(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
})({
|
|
28
|
+
schema: baseDoc,
|
|
29
|
+
file: "/file.json",
|
|
30
|
+
dereference: async (id) => id,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(processed.paths?.["/remove-me"]).toBeUndefined();
|
|
34
|
+
expect(processed.paths?.["/example"]).toBeDefined();
|
|
35
|
+
expect(processed.paths?.["/another"]).toBeDefined();
|
|
31
36
|
});
|
|
32
37
|
|
|
33
38
|
it("removes specific methods in the paths option", () => {
|
|
@@ -35,11 +40,15 @@ describe("removePaths", () => {
|
|
|
35
40
|
paths: {
|
|
36
41
|
"/example": ["get"],
|
|
37
42
|
},
|
|
38
|
-
})(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
})({
|
|
44
|
+
schema: baseDoc,
|
|
45
|
+
file: "/file.json",
|
|
46
|
+
dereference: async (id) => id,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(processed.paths?.["/example"]?.get).toBeUndefined();
|
|
50
|
+
expect(processed.paths?.["/example"]?.post).toBeDefined();
|
|
51
|
+
expect(processed.paths?.["/remove-me"]).toBeDefined();
|
|
43
52
|
});
|
|
44
53
|
|
|
45
54
|
it("removes paths and methods using paths and shouldRemove together", () => {
|
|
@@ -48,50 +57,70 @@ describe("removePaths", () => {
|
|
|
48
57
|
"/example": ["post"],
|
|
49
58
|
},
|
|
50
59
|
shouldRemove: ({ path }) => path.startsWith("/remove"),
|
|
51
|
-
})(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
})({
|
|
61
|
+
schema: baseDoc,
|
|
62
|
+
file: "/file.json",
|
|
63
|
+
dereference: async (id) => id,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(processed.paths?.["/remove-me"]).toBeUndefined();
|
|
67
|
+
expect(processed.paths?.["/example"]?.get).toBeDefined();
|
|
68
|
+
expect(processed.paths?.["/example"]?.post).toBeUndefined();
|
|
69
|
+
expect(processed.paths?.["/another"]).toBeDefined();
|
|
57
70
|
});
|
|
58
71
|
|
|
59
72
|
it("removes paths based on shouldRemove callback", () => {
|
|
60
73
|
const processed = removePaths({
|
|
61
74
|
shouldRemove: ({ path }) => path.startsWith("/remove"),
|
|
62
|
-
})(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
})({
|
|
76
|
+
schema: baseDoc,
|
|
77
|
+
file: "/file.json",
|
|
78
|
+
dereference: async (id) => id,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(processed.paths?.["/remove-me"]).toBeUndefined();
|
|
82
|
+
expect(processed.paths?.["/example"]).toBeDefined();
|
|
83
|
+
expect(processed.paths?.["/another"]).toBeDefined();
|
|
67
84
|
});
|
|
68
85
|
|
|
69
86
|
it("removes methods based on shouldRemove callback", () => {
|
|
70
87
|
const processed = removePaths({
|
|
71
88
|
shouldRemove: ({ method }) => method === "post",
|
|
72
|
-
})(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
})({
|
|
90
|
+
schema: baseDoc,
|
|
91
|
+
file: "/file.json",
|
|
92
|
+
dereference: async (id) => id,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(processed.paths?.["/example"]?.post).toBeUndefined();
|
|
96
|
+
expect(processed.paths?.["/example"]?.get).toBeDefined();
|
|
97
|
+
expect(processed.paths?.["/remove-me"]).toBeDefined();
|
|
77
98
|
});
|
|
78
99
|
|
|
79
100
|
it("removes both paths and methods based on shouldRemove callback", () => {
|
|
80
101
|
const processed = removePaths({
|
|
81
102
|
shouldRemove: ({ path, method }) =>
|
|
82
103
|
path.startsWith("/remove") || method === "post",
|
|
83
|
-
})(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
})({
|
|
105
|
+
schema: baseDoc,
|
|
106
|
+
file: "/file.json",
|
|
107
|
+
dereference: async (id) => id,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(processed.paths?.["/remove-me"]).toBeUndefined();
|
|
111
|
+
expect(processed.paths?.["/example"]?.post).toBeUndefined();
|
|
112
|
+
expect(processed.paths?.["/example"]?.get).toBeDefined();
|
|
113
|
+
expect(processed.paths?.["/another"]).toBeDefined();
|
|
89
114
|
});
|
|
90
115
|
|
|
91
116
|
it("does nothing if shouldRemove always returns false", () => {
|
|
92
117
|
const processed = removePaths({
|
|
93
118
|
shouldRemove: () => false,
|
|
94
|
-
})(
|
|
119
|
+
})({
|
|
120
|
+
schema: baseDoc,
|
|
121
|
+
file: "/file.json",
|
|
122
|
+
dereference: async (id) => id,
|
|
123
|
+
});
|
|
95
124
|
|
|
96
125
|
expect(processed).toEqual(baseDoc);
|
|
97
126
|
});
|
|
@@ -99,7 +128,11 @@ describe("removePaths", () => {
|
|
|
99
128
|
it("removes everything if shouldRemove always returns true", () => {
|
|
100
129
|
const processed = removePaths({
|
|
101
130
|
shouldRemove: () => true,
|
|
102
|
-
})(
|
|
131
|
+
})({
|
|
132
|
+
schema: baseDoc,
|
|
133
|
+
file: "/file.json",
|
|
134
|
+
dereference: async (id) => id,
|
|
135
|
+
});
|
|
103
136
|
|
|
104
137
|
expect(processed.paths).toEqual({});
|
|
105
138
|
});
|
|
@@ -108,19 +141,27 @@ describe("removePaths", () => {
|
|
|
108
141
|
const processed = removePaths({
|
|
109
142
|
shouldRemove: ({ path, method }) =>
|
|
110
143
|
method === true && path === "/remove-me",
|
|
111
|
-
})(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
144
|
+
})({
|
|
145
|
+
schema: baseDoc,
|
|
146
|
+
file: "/file.json",
|
|
147
|
+
dereference: async (id) => id,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
expect(processed.paths?.["/remove-me"]).toBeUndefined();
|
|
151
|
+
expect(processed.paths?.["/example"]).toBeDefined();
|
|
152
|
+
expect(processed.paths?.["/another"]).toBeDefined();
|
|
116
153
|
});
|
|
117
154
|
|
|
118
155
|
it("removes specific methods while keeping paths", () => {
|
|
119
156
|
const processed = removePaths({
|
|
120
157
|
shouldRemove: ({ method }) => method === "delete",
|
|
121
|
-
})(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
158
|
+
})({
|
|
159
|
+
schema: baseDoc,
|
|
160
|
+
file: "/file.json",
|
|
161
|
+
dereference: async (id) => id,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(processed.paths?.["/remove-me"]).toBeDefined();
|
|
165
|
+
expect(processed.paths?.["/remove-me"]?.delete).toBeUndefined();
|
|
125
166
|
});
|
|
126
167
|
});
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ProcessorArg } from "../../../../config/validators/BuildSchema.js";
|
|
2
|
+
import type { OpenAPIDocument } from "../../../oas/parser/index.js";
|
|
1
3
|
import { type RecordAny, traverse } from "./traverse.js";
|
|
2
4
|
|
|
3
5
|
interface RemovePathsOptions {
|
|
@@ -12,8 +14,8 @@ interface RemovePathsOptions {
|
|
|
12
14
|
|
|
13
15
|
export const removePaths =
|
|
14
16
|
({ paths = {}, shouldRemove }: RemovePathsOptions) =>
|
|
15
|
-
(
|
|
16
|
-
traverse(
|
|
17
|
+
({ schema }: ProcessorArg) =>
|
|
18
|
+
traverse(schema, (spec) => {
|
|
17
19
|
if (!spec.paths) return spec;
|
|
18
20
|
|
|
19
21
|
const updatedPaths: RecordAny = {};
|
|
@@ -52,4 +54,4 @@ export const removePaths =
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
return { ...spec, paths: updatedPaths };
|
|
55
|
-
});
|
|
57
|
+
}) as OpenAPIDocument;
|