@kubb/plugin-faker 5.0.8 → 5.0.10
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 +19 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -170,7 +170,8 @@ declare global {
|
|
|
170
170
|
* Partial map of node-type overrides for the Faker printer. Each key is a
|
|
171
171
|
* `SchemaType` (`'string'`, `'date'`, ...) and each handler returns the
|
|
172
172
|
* Faker expression for that schema as a string. Use `this.transform` to
|
|
173
|
-
* recurse into nested schema nodes
|
|
173
|
+
* recurse into nested schema nodes, `this.base` to reuse the built-in handler,
|
|
174
|
+
* and `this.options` to read printer options.
|
|
174
175
|
*
|
|
175
176
|
* @example Override the integer handler
|
|
176
177
|
* ```ts
|
package/dist/index.js
CHANGED
|
@@ -830,6 +830,20 @@ function createCasedFile(caseLast) {
|
|
|
830
830
|
} };
|
|
831
831
|
}
|
|
832
832
|
//#endregion
|
|
833
|
+
//#region ../../internals/shared/src/refs.ts
|
|
834
|
+
/**
|
|
835
|
+
* Collects the resolved target name of every pointer-carrying ref in a schema tree, in
|
|
836
|
+
* first-occurrence order. Use this for name-only checks (e.g. redeclaration detection) where
|
|
837
|
+
* `resolver.imports` would resolve file paths that are then discarded.
|
|
838
|
+
*/
|
|
839
|
+
function collectRefNames(schema) {
|
|
840
|
+
return ast.collectSync(schema, { schema: (node) => {
|
|
841
|
+
const refNode = ast.narrowSchema(node, "ref");
|
|
842
|
+
if (!refNode?.ref) return null;
|
|
843
|
+
return ast.resolveRefName(refNode);
|
|
844
|
+
} });
|
|
845
|
+
}
|
|
846
|
+
//#endregion
|
|
833
847
|
//#region ../../internals/shared/src/group.ts
|
|
834
848
|
/**
|
|
835
849
|
* Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
|
|
@@ -1103,9 +1117,9 @@ const printerFaker = ast.createPrinter((options) => {
|
|
|
1103
1117
|
})) return `get ${objectKey(property.name)}() { const _value = ${value}; Object.defineProperty(this, ${JSON.stringify(property.name)}, { value: _value, configurable: true, writable: true, enumerable: true }); return _value }`;
|
|
1104
1118
|
return `${objectKey(property.name)}: ${value}`;
|
|
1105
1119
|
}));
|
|
1106
|
-
}
|
|
1107
|
-
...options.nodes
|
|
1120
|
+
}
|
|
1108
1121
|
},
|
|
1122
|
+
overrides: options.nodes,
|
|
1109
1123
|
print(node) {
|
|
1110
1124
|
return this.transform(node) ?? null;
|
|
1111
1125
|
}
|
|
@@ -1313,11 +1327,12 @@ const fakerGenerator = defineGenerator({
|
|
|
1313
1327
|
description: node.requestBody?.description ?? schema.description
|
|
1314
1328
|
}));
|
|
1315
1329
|
const responseName = resolver.response.response(node);
|
|
1330
|
+
const hasResponseNameCollision = new Set(node.responses.flatMap((response) => (response.content ?? []).flatMap((entry) => entry.schema ? collectRefNames(entry.schema).map((name) => resolver.name(name)) : []))).has(responseName);
|
|
1316
1331
|
const localHelperNames = /* @__PURE__ */ new Set([
|
|
1317
1332
|
...paramGroups.map((group) => group.name),
|
|
1318
1333
|
...responseUnits.map((unit) => unit.name),
|
|
1319
1334
|
...dataUnits.map((unit) => unit.name),
|
|
1320
|
-
responseName
|
|
1335
|
+
...hasResponseNameCollision ? [] : [responseName]
|
|
1321
1336
|
]);
|
|
1322
1337
|
const cyclicSchemas = new Set(ctx.meta.circularNames);
|
|
1323
1338
|
const meta = {
|
|
@@ -1454,7 +1469,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1454
1469
|
description: unit.description,
|
|
1455
1470
|
skipImportNames: unit.skipImportNames
|
|
1456
1471
|
})),
|
|
1457
|
-
renderEntry({
|
|
1472
|
+
!hasResponseNameCollision && renderEntry({
|
|
1458
1473
|
schema: buildResponseUnionSchema(node, resolver),
|
|
1459
1474
|
name: responseName,
|
|
1460
1475
|
typeName: tsResolver.response.response(node),
|