@kubb/plugin-faker 5.0.0-beta.85 → 5.0.0-beta.87
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 +24 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +24 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -277,7 +277,7 @@ declare const pluginFakerName = "plugin-faker";
|
|
|
277
277
|
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
278
278
|
*
|
|
279
279
|
* export default defineConfig({
|
|
280
|
-
* input:
|
|
280
|
+
* input: './petStore.yaml',
|
|
281
281
|
* output: { path: './src/gen' },
|
|
282
282
|
* plugins: [
|
|
283
283
|
* pluginTs(),
|
package/dist/index.js
CHANGED
|
@@ -131,7 +131,7 @@ const reservedWords = /* @__PURE__ */ new Set([
|
|
|
131
131
|
*/
|
|
132
132
|
function isValidVarName(name) {
|
|
133
133
|
if (!name || reservedWords.has(name)) return false;
|
|
134
|
-
return
|
|
134
|
+
return isIdentifier(name);
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Returns `name` when it's a syntactically valid JavaScript variable name,
|
|
@@ -484,7 +484,6 @@ const SCALAR_TYPES$1 = /* @__PURE__ */ new Set([
|
|
|
484
484
|
"blob",
|
|
485
485
|
"enum"
|
|
486
486
|
]);
|
|
487
|
-
const ARRAY_TYPES$1 = /* @__PURE__ */ new Set(["array"]);
|
|
488
487
|
function toRelativeImportPath(from, to) {
|
|
489
488
|
const relativePath = posix.relative(posix.dirname(from), to);
|
|
490
489
|
return relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
|
|
@@ -529,7 +528,7 @@ function getScalarType(node, typeName) {
|
|
|
529
528
|
* Determines the data type, return type, and whether it uses the type name.
|
|
530
529
|
*/
|
|
531
530
|
function resolveFakerTypeUsage(node, typeName, canOverride) {
|
|
532
|
-
const isArray =
|
|
531
|
+
const isArray = node.type === "array";
|
|
533
532
|
const isTuple = node.type === "tuple";
|
|
534
533
|
const isScalar = SCALAR_TYPES$1.has(node.type);
|
|
535
534
|
let dataType = `Partial<${typeName}>`;
|
|
@@ -546,7 +545,6 @@ function resolveFakerTypeUsage(node, typeName, canOverride) {
|
|
|
546
545
|
//#endregion
|
|
547
546
|
//#region src/components/Faker.tsx
|
|
548
547
|
const OBJECT_TYPES = /* @__PURE__ */ new Set(["object", "intersection"]);
|
|
549
|
-
const ARRAY_TYPES = /* @__PURE__ */ new Set(["array"]);
|
|
550
548
|
const SCALAR_TYPES = /* @__PURE__ */ new Set([
|
|
551
549
|
"string",
|
|
552
550
|
"email",
|
|
@@ -565,7 +563,7 @@ const SCALAR_TYPES = /* @__PURE__ */ new Set([
|
|
|
565
563
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
566
564
|
function Faker({ node, description, name, typeName, printer, seed, canOverride }) {
|
|
567
565
|
const fakerText = printer.print(node) ?? "undefined";
|
|
568
|
-
const isArray =
|
|
566
|
+
const isArray = node.type === "array";
|
|
569
567
|
const isObject = OBJECT_TYPES.has(node.type);
|
|
570
568
|
const isTuple = node.type === "tuple";
|
|
571
569
|
const isScalar = SCALAR_TYPES.has(node.type);
|
|
@@ -726,6 +724,24 @@ function getOperationParameters(node, options = {}) {
|
|
|
726
724
|
};
|
|
727
725
|
}
|
|
728
726
|
//#endregion
|
|
727
|
+
//#region ../../internals/shared/src/adapter.ts
|
|
728
|
+
/**
|
|
729
|
+
* Narrows the generic `Adapter` from a generator context to the OpenAPI adapter,
|
|
730
|
+
* so OAS-only options (`dateType`, `nameMapping`) and the parsed `document` are typed.
|
|
731
|
+
*
|
|
732
|
+
* Throws when a non-OAS adapter is configured, turning a silently wrong cast into a
|
|
733
|
+
* clear, actionable error at the point of use.
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ```ts
|
|
737
|
+
* const { dateType } = getOasAdapter(ctx.adapter).options
|
|
738
|
+
* ```
|
|
739
|
+
*/
|
|
740
|
+
function getOasAdapter(adapter) {
|
|
741
|
+
if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
|
|
742
|
+
return adapter;
|
|
743
|
+
}
|
|
744
|
+
//#endregion
|
|
729
745
|
//#region ../../internals/shared/src/group.ts
|
|
730
746
|
/**
|
|
731
747
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
@@ -1011,7 +1027,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1011
1027
|
regexGenerator,
|
|
1012
1028
|
nodes: printer?.nodes,
|
|
1013
1029
|
cyclicSchemas,
|
|
1014
|
-
nameMapping: adapter.options.nameMapping
|
|
1030
|
+
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1015
1031
|
});
|
|
1016
1032
|
const fakerText = printerInstance.print(node) ?? "undefined";
|
|
1017
1033
|
const typeReference = resolveTypeReference({
|
|
@@ -1218,7 +1234,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1218
1234
|
regexGenerator,
|
|
1219
1235
|
nodes: printer?.nodes,
|
|
1220
1236
|
cyclicSchemas,
|
|
1221
|
-
nameMapping: adapter.options.nameMapping
|
|
1237
|
+
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1222
1238
|
});
|
|
1223
1239
|
const fakerText = printerInstance.print(schema) ?? "undefined";
|
|
1224
1240
|
const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);
|
|
@@ -1392,7 +1408,7 @@ const pluginFakerName = "plugin-faker";
|
|
|
1392
1408
|
* import { pluginFaker } from '@kubb/plugin-faker'
|
|
1393
1409
|
*
|
|
1394
1410
|
* export default defineConfig({
|
|
1395
|
-
* input:
|
|
1411
|
+
* input: './petStore.yaml',
|
|
1396
1412
|
* output: { path: './src/gen' },
|
|
1397
1413
|
* plugins: [
|
|
1398
1414
|
* pluginTs(),
|