@kubb/plugin-faker 5.0.7 → 5.0.9

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.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
@@ -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),