@kubb/plugin-faker 5.0.0-beta.98 → 5.0.0-beta.99
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 +42 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -42
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -632,39 +632,19 @@ function Faker({ node, description, name, typeName, printer, seed, canOverride }
|
|
|
632
632
|
}
|
|
633
633
|
//#endregion
|
|
634
634
|
//#region ../../internals/shared/src/params.ts
|
|
635
|
-
const caseParamsCache = /* @__PURE__ */ new WeakMap();
|
|
636
635
|
/**
|
|
637
|
-
*
|
|
636
|
+
* Drops parameters that share the same name, keeping the first.
|
|
638
637
|
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
638
|
+
* A malformed spec can declare the same parameter name twice within one `in` location. Both would
|
|
639
|
+
* resolve to the same output property, so emitting both would yield an object type with a duplicate
|
|
640
|
+
* member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
|
|
641
|
+
* parameter names flow through unchanged, so no two distinct names ever collide here anymore.
|
|
642
642
|
*/
|
|
643
|
-
function
|
|
644
|
-
if (!casing) return params;
|
|
645
|
-
const cached = caseParamsCache.get(params);
|
|
646
|
-
if (cached) return cached;
|
|
647
|
-
const result = params.map((param) => ({
|
|
648
|
-
...param,
|
|
649
|
-
name: camelCase(param.name)
|
|
650
|
-
}));
|
|
651
|
-
caseParamsCache.set(params, result);
|
|
652
|
-
return result;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Drops parameters that collapse to the same property identity once camelCased, keeping the first.
|
|
656
|
-
*
|
|
657
|
-
* Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
|
|
658
|
-
* `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
|
|
659
|
-
* an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
|
|
660
|
-
* identity so the resulting group is collision-free regardless of the names each caller carries.
|
|
661
|
-
*/
|
|
662
|
-
function dedupeByCasedName(params) {
|
|
643
|
+
function dedupeParams(params) {
|
|
663
644
|
const seen = /* @__PURE__ */ new Set();
|
|
664
645
|
return params.filter((param) => {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
seen.add(key);
|
|
646
|
+
if (seen.has(param.name)) return false;
|
|
647
|
+
seen.add(param.name);
|
|
668
648
|
return true;
|
|
669
649
|
});
|
|
670
650
|
}
|
|
@@ -718,13 +698,15 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
718
698
|
};
|
|
719
699
|
});
|
|
720
700
|
}
|
|
721
|
-
function getOperationParameters(node
|
|
722
|
-
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
701
|
+
function getOperationParameters(node) {
|
|
723
702
|
return {
|
|
724
|
-
path:
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
703
|
+
path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
|
|
704
|
+
...param,
|
|
705
|
+
name: camelCase(param.name)
|
|
706
|
+
})),
|
|
707
|
+
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
708
|
+
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
709
|
+
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
728
710
|
};
|
|
729
711
|
}
|
|
730
712
|
//#endregion
|
|
@@ -834,6 +816,28 @@ function createGroupConfig(group) {
|
|
|
834
816
|
};
|
|
835
817
|
}
|
|
836
818
|
//#endregion
|
|
819
|
+
//#region ../../internals/shared/src/schemaTraversal.ts
|
|
820
|
+
/**
|
|
821
|
+
* Maps each member of a union or intersection schema to its transformed output, pairing every
|
|
822
|
+
* result with the original member.
|
|
823
|
+
*/
|
|
824
|
+
function mapSchemaMembers(node, transform) {
|
|
825
|
+
return (node.members ?? []).map((schema) => ({
|
|
826
|
+
schema,
|
|
827
|
+
output: transform(schema)
|
|
828
|
+
}));
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Maps each item of an array or tuple schema to its transformed output, pairing every result with
|
|
832
|
+
* the original item.
|
|
833
|
+
*/
|
|
834
|
+
function mapSchemaItems(node, transform) {
|
|
835
|
+
return (node.items ?? []).map((schema) => ({
|
|
836
|
+
schema,
|
|
837
|
+
output: transform(schema)
|
|
838
|
+
}));
|
|
839
|
+
}
|
|
840
|
+
//#endregion
|
|
837
841
|
//#region src/printers/printerFaker.ts
|
|
838
842
|
const fakerKeywordMapper = {
|
|
839
843
|
any: () => "undefined",
|
|
@@ -985,7 +989,7 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
|
|
|
985
989
|
union(node) {
|
|
986
990
|
const { discriminatorPropertyName } = node;
|
|
987
991
|
const baseTypeName = this.options.typeName;
|
|
988
|
-
const items =
|
|
992
|
+
const items = mapSchemaMembers(node, (member) => {
|
|
989
993
|
const value = discriminatorPropertyName ? getDiscriminatorValue(member, discriminatorPropertyName) : void 0;
|
|
990
994
|
if (baseTypeName && value !== void 0) {
|
|
991
995
|
const typeName = `Extract<NonNullable<${baseTypeName}>, { ${JSON.stringify(discriminatorPropertyName)}: ${parseEnumValue(value)} }>`;
|
|
@@ -1003,11 +1007,11 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
|
|
|
1003
1007
|
return fakerKeywordMapper.union(items);
|
|
1004
1008
|
},
|
|
1005
1009
|
intersection(node) {
|
|
1006
|
-
const items =
|
|
1010
|
+
const items = mapSchemaMembers(node, (member) => printNested(member, { nestedInObject: true })).map(({ output }) => output).filter((item) => Boolean(item) && item !== "undefined");
|
|
1007
1011
|
return fakerKeywordMapper.and(items);
|
|
1008
1012
|
},
|
|
1009
1013
|
array(node) {
|
|
1010
|
-
const items =
|
|
1014
|
+
const items = mapSchemaItems(node, (member) => printNested(member, {
|
|
1011
1015
|
typeName: this.options.typeName ? `NonNullable<${this.options.typeName}>[number]` : void 0,
|
|
1012
1016
|
nestedInObject: true
|
|
1013
1017
|
})).map(({ output }) => output).filter((item) => Boolean(item));
|
|
@@ -1176,11 +1180,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1176
1180
|
const pluginTs = ctx.driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1177
1181
|
if (!pluginTs) return;
|
|
1178
1182
|
const tsResolver = ctx.driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1179
|
-
const
|
|
1180
|
-
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters({
|
|
1181
|
-
...node,
|
|
1182
|
-
parameters: params
|
|
1183
|
-
}, { paramsCasing: "original" });
|
|
1183
|
+
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
|
|
1184
1184
|
const paramGroups = [
|
|
1185
1185
|
{
|
|
1186
1186
|
params: pathParams,
|