@kubb/plugin-zod 5.0.0-beta.86 → 5.0.0-beta.94

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.d.ts CHANGED
@@ -454,7 +454,7 @@ declare const pluginZodName = "plugin-zod";
454
454
  * import { pluginZod } from '@kubb/plugin-zod'
455
455
  *
456
456
  * export default defineConfig({
457
- * input: { path: './petStore.yaml' },
457
+ * input: './petStore.yaml',
458
458
  * output: { path: './src/gen' },
459
459
  * plugins: [
460
460
  * pluginTs(),
package/dist/index.js CHANGED
@@ -428,6 +428,24 @@ function getSuccessResponses(responses) {
428
428
  return responses.filter((response) => isSuccessStatusCode(response.statusCode));
429
429
  }
430
430
  //#endregion
431
+ //#region ../../internals/shared/src/adapter.ts
432
+ /**
433
+ * Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
434
+ * so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
435
+ *
436
+ * Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
437
+ * clear, actionable error at the point of use.
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * const { dateType } = getOasAdapter(ctx.adapter).options
442
+ * ```
443
+ */
444
+ function getOasAdapter(adapter) {
445
+ if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
446
+ return adapter;
447
+ }
448
+ //#endregion
431
449
  //#region ../../internals/shared/src/group.ts
432
450
  /**
433
451
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
@@ -1272,16 +1290,14 @@ function getStdPrinters(resolver, params) {
1272
1290
  output: cached.output,
1273
1291
  input: cached.input
1274
1292
  };
1275
- const base = {
1276
- ...params,
1277
- resolver
1278
- };
1279
1293
  const output = printerZod({
1280
- ...base,
1294
+ ...params,
1295
+ resolver,
1281
1296
  direction: "output"
1282
1297
  });
1283
1298
  const input = printerZod({
1284
- ...base,
1299
+ ...params,
1300
+ resolver,
1285
1301
  direction: "input"
1286
1302
  });
1287
1303
  zodPrinterCache.set(resolver, {
@@ -1325,7 +1341,7 @@ const zodGenerator = defineGenerator({
1325
1341
  schema(node, ctx) {
1326
1342
  const { adapter, config, resolver, root } = ctx;
1327
1343
  const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
1328
- const dateType = adapter.options.dateType;
1344
+ const dateType = getOasAdapter(adapter).options.dateType;
1329
1345
  if (!node.name) return;
1330
1346
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1331
1347
  const cyclicSchemas = new Set(ctx.meta.circularNames);
@@ -1369,7 +1385,7 @@ const zodGenerator = defineGenerator({
1369
1385
  })
1370
1386
  };
1371
1387
  const inferTypeName = inferred ? resolver.schema.typeName(node.name) : null;
1372
- const nameMapping = adapter.options.nameMapping;
1388
+ const nameMapping = getOasAdapter(adapter).options.nameMapping;
1373
1389
  const stdPrinters = mini ? null : getStdPrinters(resolver, {
1374
1390
  coercion,
1375
1391
  guidType,
@@ -1442,7 +1458,7 @@ const zodGenerator = defineGenerator({
1442
1458
  if (!ast.isHttpOperationNode(node)) return null;
1443
1459
  const { adapter, config, resolver, root } = ctx;
1444
1460
  const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
1445
- const dateType = adapter.options.dateType;
1461
+ const dateType = getOasAdapter(adapter).options.dateType;
1446
1462
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1447
1463
  const params = caseParams(node.parameters, "camelcase");
1448
1464
  const meta = { file: resolver.file({
@@ -1455,7 +1471,7 @@ const zodGenerator = defineGenerator({
1455
1471
  group: group ?? void 0
1456
1472
  }) };
1457
1473
  const cyclicSchemas = new Set(ctx.meta.circularNames);
1458
- const nameMapping = adapter.options.nameMapping;
1474
+ const nameMapping = getOasAdapter(adapter).options.nameMapping;
1459
1475
  function renderSchemaEntry({ schema, name, keysToOmit, direction = "output" }) {
1460
1476
  if (!schema) return null;
1461
1477
  const inferTypeName = inferred ? resolver.schema.type(name) : null;
@@ -1737,7 +1753,7 @@ const pluginZodName = "plugin-zod";
1737
1753
  * import { pluginZod } from '@kubb/plugin-zod'
1738
1754
  *
1739
1755
  * export default defineConfig({
1740
- * input: { path: './petStore.yaml' },
1756
+ * input: './petStore.yaml',
1741
1757
  * output: { path: './src/gen' },
1742
1758
  * plugins: [
1743
1759
  * pluginTs(),