@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.cjs CHANGED
@@ -438,6 +438,24 @@ function getSuccessResponses(responses) {
438
438
  return responses.filter((response) => isSuccessStatusCode(response.statusCode));
439
439
  }
440
440
  //#endregion
441
+ //#region ../../internals/shared/src/adapter.ts
442
+ /**
443
+ * Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
444
+ * so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
445
+ *
446
+ * Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
447
+ * clear, actionable error at the point of use.
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * const { dateType } = getOasAdapter(ctx.adapter).options
452
+ * ```
453
+ */
454
+ function getOasAdapter(adapter) {
455
+ if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
456
+ return adapter;
457
+ }
458
+ //#endregion
441
459
  //#region ../../internals/shared/src/group.ts
442
460
  /**
443
461
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
@@ -1282,16 +1300,14 @@ function getStdPrinters(resolver, params) {
1282
1300
  output: cached.output,
1283
1301
  input: cached.input
1284
1302
  };
1285
- const base = {
1286
- ...params,
1287
- resolver
1288
- };
1289
1303
  const output = printerZod({
1290
- ...base,
1304
+ ...params,
1305
+ resolver,
1291
1306
  direction: "output"
1292
1307
  });
1293
1308
  const input = printerZod({
1294
- ...base,
1309
+ ...params,
1310
+ resolver,
1295
1311
  direction: "input"
1296
1312
  });
1297
1313
  zodPrinterCache.set(resolver, {
@@ -1335,7 +1351,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1335
1351
  schema(node, ctx) {
1336
1352
  const { adapter, config, resolver, root } = ctx;
1337
1353
  const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
1338
- const dateType = adapter.options.dateType;
1354
+ const dateType = getOasAdapter(adapter).options.dateType;
1339
1355
  if (!node.name) return;
1340
1356
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1341
1357
  const cyclicSchemas = new Set(ctx.meta.circularNames);
@@ -1379,7 +1395,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1379
1395
  })
1380
1396
  };
1381
1397
  const inferTypeName = inferred ? resolver.schema.typeName(node.name) : null;
1382
- const nameMapping = adapter.options.nameMapping;
1398
+ const nameMapping = getOasAdapter(adapter).options.nameMapping;
1383
1399
  const stdPrinters = mini ? null : getStdPrinters(resolver, {
1384
1400
  coercion,
1385
1401
  guidType,
@@ -1452,7 +1468,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1452
1468
  if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
1453
1469
  const { adapter, config, resolver, root } = ctx;
1454
1470
  const { output, coercion, guidType, regexType, mini, inferred, importPath, group, printer } = ctx.options;
1455
- const dateType = adapter.options.dateType;
1471
+ const dateType = getOasAdapter(adapter).options.dateType;
1456
1472
  const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1457
1473
  const params = caseParams(node.parameters, "camelcase");
1458
1474
  const meta = { file: resolver.file({
@@ -1465,7 +1481,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1465
1481
  group: group ?? void 0
1466
1482
  }) };
1467
1483
  const cyclicSchemas = new Set(ctx.meta.circularNames);
1468
- const nameMapping = adapter.options.nameMapping;
1484
+ const nameMapping = getOasAdapter(adapter).options.nameMapping;
1469
1485
  function renderSchemaEntry({ schema, name, keysToOmit, direction = "output" }) {
1470
1486
  if (!schema) return null;
1471
1487
  const inferTypeName = inferred ? resolver.schema.type(name) : null;
@@ -1747,7 +1763,7 @@ const pluginZodName = "plugin-zod";
1747
1763
  * import { pluginZod } from '@kubb/plugin-zod'
1748
1764
  *
1749
1765
  * export default defineConfig({
1750
- * input: { path: './petStore.yaml' },
1766
+ * input: './petStore.yaml',
1751
1767
  * output: { path: './src/gen' },
1752
1768
  * plugins: [
1753
1769
  * pluginTs(),