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