@kubb/plugin-zod 5.0.0-beta.25 → 5.0.0-beta.28
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/index.cjs +158 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/generators/zodGenerator.tsx +6 -6
- package/src/resolvers/resolverZod.ts +6 -5
package/dist/index.cjs
CHANGED
|
@@ -136,6 +136,129 @@ function toRegExpString(text, func = "RegExp") {
|
|
|
136
136
|
return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
|
|
137
137
|
}
|
|
138
138
|
//#endregion
|
|
139
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
140
|
+
/**
|
|
141
|
+
* JavaScript and Java reserved words.
|
|
142
|
+
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
143
|
+
*/
|
|
144
|
+
const reservedWords = new Set([
|
|
145
|
+
"abstract",
|
|
146
|
+
"arguments",
|
|
147
|
+
"boolean",
|
|
148
|
+
"break",
|
|
149
|
+
"byte",
|
|
150
|
+
"case",
|
|
151
|
+
"catch",
|
|
152
|
+
"char",
|
|
153
|
+
"class",
|
|
154
|
+
"const",
|
|
155
|
+
"continue",
|
|
156
|
+
"debugger",
|
|
157
|
+
"default",
|
|
158
|
+
"delete",
|
|
159
|
+
"do",
|
|
160
|
+
"double",
|
|
161
|
+
"else",
|
|
162
|
+
"enum",
|
|
163
|
+
"eval",
|
|
164
|
+
"export",
|
|
165
|
+
"extends",
|
|
166
|
+
"false",
|
|
167
|
+
"final",
|
|
168
|
+
"finally",
|
|
169
|
+
"float",
|
|
170
|
+
"for",
|
|
171
|
+
"function",
|
|
172
|
+
"goto",
|
|
173
|
+
"if",
|
|
174
|
+
"implements",
|
|
175
|
+
"import",
|
|
176
|
+
"in",
|
|
177
|
+
"instanceof",
|
|
178
|
+
"int",
|
|
179
|
+
"interface",
|
|
180
|
+
"let",
|
|
181
|
+
"long",
|
|
182
|
+
"native",
|
|
183
|
+
"new",
|
|
184
|
+
"null",
|
|
185
|
+
"package",
|
|
186
|
+
"private",
|
|
187
|
+
"protected",
|
|
188
|
+
"public",
|
|
189
|
+
"return",
|
|
190
|
+
"short",
|
|
191
|
+
"static",
|
|
192
|
+
"super",
|
|
193
|
+
"switch",
|
|
194
|
+
"synchronized",
|
|
195
|
+
"this",
|
|
196
|
+
"throw",
|
|
197
|
+
"throws",
|
|
198
|
+
"transient",
|
|
199
|
+
"true",
|
|
200
|
+
"try",
|
|
201
|
+
"typeof",
|
|
202
|
+
"var",
|
|
203
|
+
"void",
|
|
204
|
+
"volatile",
|
|
205
|
+
"while",
|
|
206
|
+
"with",
|
|
207
|
+
"yield",
|
|
208
|
+
"Array",
|
|
209
|
+
"Date",
|
|
210
|
+
"hasOwnProperty",
|
|
211
|
+
"Infinity",
|
|
212
|
+
"isFinite",
|
|
213
|
+
"isNaN",
|
|
214
|
+
"isPrototypeOf",
|
|
215
|
+
"length",
|
|
216
|
+
"Math",
|
|
217
|
+
"name",
|
|
218
|
+
"NaN",
|
|
219
|
+
"Number",
|
|
220
|
+
"Object",
|
|
221
|
+
"prototype",
|
|
222
|
+
"String",
|
|
223
|
+
"toString",
|
|
224
|
+
"undefined",
|
|
225
|
+
"valueOf"
|
|
226
|
+
]);
|
|
227
|
+
/**
|
|
228
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```ts
|
|
232
|
+
* isValidVarName('status') // true
|
|
233
|
+
* isValidVarName('class') // false (reserved word)
|
|
234
|
+
* isValidVarName('42foo') // false (starts with digit)
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
function isValidVarName(name) {
|
|
238
|
+
if (!name || reservedWords.has(name)) return false;
|
|
239
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
243
|
+
* otherwise prefixes it with `_` so the result is a valid identifier.
|
|
244
|
+
*
|
|
245
|
+
* Useful for sanitizing OpenAPI schema names or operation IDs that start with
|
|
246
|
+
* a digit (e.g. `409`, `504AccountCancel`) before using them as exported
|
|
247
|
+
* variable, type, or function names.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* ensureValidVarName('409') // '_409'
|
|
252
|
+
* ensureValidVarName('504AccountCancel') // '_504AccountCancel'
|
|
253
|
+
* ensureValidVarName('Pet') // 'Pet'
|
|
254
|
+
* ensureValidVarName('class') // '_class'
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
function ensureValidVarName(name) {
|
|
258
|
+
if (!name || isValidVarName(name)) return name;
|
|
259
|
+
return `_${name}`;
|
|
260
|
+
}
|
|
261
|
+
//#endregion
|
|
139
262
|
//#region src/components/Operations.tsx
|
|
140
263
|
function Operations({ name, operations }) {
|
|
141
264
|
const operationsJSON = operations.reduce((prev, acc) => {
|
|
@@ -810,11 +933,19 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
810
933
|
meta: meta.file.meta,
|
|
811
934
|
banner: resolver.resolveBanner(ctx.meta, {
|
|
812
935
|
output,
|
|
813
|
-
config
|
|
936
|
+
config,
|
|
937
|
+
file: {
|
|
938
|
+
path: meta.file.path,
|
|
939
|
+
baseName: meta.file.baseName
|
|
940
|
+
}
|
|
814
941
|
}),
|
|
815
942
|
footer: resolver.resolveFooter(ctx.meta, {
|
|
816
943
|
output,
|
|
817
|
-
config
|
|
944
|
+
config,
|
|
945
|
+
file: {
|
|
946
|
+
path: meta.file.path,
|
|
947
|
+
baseName: meta.file.baseName
|
|
948
|
+
}
|
|
818
949
|
}),
|
|
819
950
|
children: [
|
|
820
951
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -958,11 +1089,19 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
958
1089
|
meta: meta.file.meta,
|
|
959
1090
|
banner: resolver.resolveBanner(ctx.meta, {
|
|
960
1091
|
output,
|
|
961
|
-
config
|
|
1092
|
+
config,
|
|
1093
|
+
file: {
|
|
1094
|
+
path: meta.file.path,
|
|
1095
|
+
baseName: meta.file.baseName
|
|
1096
|
+
}
|
|
962
1097
|
}),
|
|
963
1098
|
footer: resolver.resolveFooter(ctx.meta, {
|
|
964
1099
|
output,
|
|
965
|
-
config
|
|
1100
|
+
config,
|
|
1101
|
+
file: {
|
|
1102
|
+
path: meta.file.path,
|
|
1103
|
+
baseName: meta.file.baseName
|
|
1104
|
+
}
|
|
966
1105
|
}),
|
|
967
1106
|
children: [
|
|
968
1107
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1027,11 +1166,19 @@ const zodGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1027
1166
|
meta: meta.file.meta,
|
|
1028
1167
|
banner: resolver.resolveBanner(ctx.meta, {
|
|
1029
1168
|
output,
|
|
1030
|
-
config
|
|
1169
|
+
config,
|
|
1170
|
+
file: {
|
|
1171
|
+
path: meta.file.path,
|
|
1172
|
+
baseName: meta.file.baseName
|
|
1173
|
+
}
|
|
1031
1174
|
}),
|
|
1032
1175
|
footer: resolver.resolveFooter(ctx.meta, {
|
|
1033
1176
|
output,
|
|
1034
|
-
config
|
|
1177
|
+
config,
|
|
1178
|
+
file: {
|
|
1179
|
+
path: meta.file.path,
|
|
1180
|
+
baseName: meta.file.baseName
|
|
1181
|
+
}
|
|
1035
1182
|
}),
|
|
1036
1183
|
children: [
|
|
1037
1184
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1069,19 +1216,20 @@ const resolverZod = (0, _kubb_core.defineResolver)(() => {
|
|
|
1069
1216
|
name: "default",
|
|
1070
1217
|
pluginName: "plugin-zod",
|
|
1071
1218
|
default(name, type) {
|
|
1072
|
-
|
|
1219
|
+
const resolved = camelCase(name, {
|
|
1073
1220
|
isFile: type === "file",
|
|
1074
1221
|
suffix: type ? "schema" : void 0
|
|
1075
1222
|
});
|
|
1223
|
+
return type === "file" ? resolved : ensureValidVarName(resolved);
|
|
1076
1224
|
},
|
|
1077
1225
|
resolveSchemaName(name) {
|
|
1078
|
-
return camelCase(name, { suffix: "schema" });
|
|
1226
|
+
return ensureValidVarName(camelCase(name, { suffix: "schema" }));
|
|
1079
1227
|
},
|
|
1080
1228
|
resolveSchemaTypeName(name) {
|
|
1081
|
-
return pascalCase(name, { suffix: "schema" });
|
|
1229
|
+
return ensureValidVarName(pascalCase(name, { suffix: "schema" }));
|
|
1082
1230
|
},
|
|
1083
1231
|
resolveTypeName(name) {
|
|
1084
|
-
return pascalCase(name);
|
|
1232
|
+
return ensureValidVarName(pascalCase(name));
|
|
1085
1233
|
},
|
|
1086
1234
|
resolvePathName(name, type) {
|
|
1087
1235
|
return this.default(name, type);
|