@kubb/plugin-faker 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
@@ -728,6 +728,24 @@ function getOperationParameters(node, options = {}) {
728
728
  };
729
729
  }
730
730
  //#endregion
731
+ //#region ../../internals/shared/src/adapter.ts
732
+ /**
733
+ * Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
734
+ * so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
735
+ *
736
+ * Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
737
+ * clear, actionable error at the point of use.
738
+ *
739
+ * @example
740
+ * ```ts
741
+ * const { dateType } = getOasAdapter(ctx.adapter).options
742
+ * ```
743
+ */
744
+ function getOasAdapter(adapter) {
745
+ if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
746
+ return adapter;
747
+ }
748
+ //#endregion
731
749
  //#region ../../internals/shared/src/group.ts
732
750
  /**
733
751
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
@@ -1013,7 +1031,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1013
1031
  regexGenerator,
1014
1032
  nodes: printer?.nodes,
1015
1033
  cyclicSchemas,
1016
- nameMapping: adapter.options.nameMapping
1034
+ nameMapping: getOasAdapter(adapter).options.nameMapping
1017
1035
  });
1018
1036
  const fakerText = printerInstance.print(node) ?? "undefined";
1019
1037
  const typeReference = resolveTypeReference({
@@ -1220,7 +1238,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
1220
1238
  regexGenerator,
1221
1239
  nodes: printer?.nodes,
1222
1240
  cyclicSchemas,
1223
- nameMapping: adapter.options.nameMapping
1241
+ nameMapping: getOasAdapter(adapter).options.nameMapping
1224
1242
  });
1225
1243
  const fakerText = printerInstance.print(schema) ?? "undefined";
1226
1244
  const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);
@@ -1394,7 +1412,7 @@ const pluginFakerName = "plugin-faker";
1394
1412
  * import { pluginFaker } from '@kubb/plugin-faker'
1395
1413
  *
1396
1414
  * export default defineConfig({
1397
- * input: { path: './petStore.yaml' },
1415
+ * input: './petStore.yaml',
1398
1416
  * output: { path: './src/gen' },
1399
1417
  * plugins: [
1400
1418
  * pluginTs(),