@kubb/plugin-faker 5.0.4 → 5.0.5
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 +10 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +10 -14
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/index.cjs
CHANGED
|
@@ -969,27 +969,23 @@ const fakerKeywordMapper = {
|
|
|
969
969
|
email: () => "faker.internet.email()",
|
|
970
970
|
blob: () => "faker.image.url() as unknown as Blob"
|
|
971
971
|
};
|
|
972
|
-
function getEnumValues(node) {
|
|
973
|
-
if (node.namedEnumValues?.length) return node.namedEnumValues.map((item) => item.value);
|
|
974
|
-
return node.enumValues ?? [];
|
|
975
|
-
}
|
|
976
972
|
function parseEnumValue(value) {
|
|
977
973
|
if (typeof value === "string") return stringify(value);
|
|
978
974
|
return value;
|
|
979
975
|
}
|
|
980
976
|
/**
|
|
981
977
|
* Reads the discriminator literal off a variant, or `undefined` when it can't be determined.
|
|
978
|
+
*
|
|
979
|
+
* A variant carries exactly one discriminator value, so a property resolving to several literals
|
|
980
|
+
* (a `ref` to the enum shared by every branch, say) identifies no branch and narrows nothing.
|
|
982
981
|
*/
|
|
983
982
|
function getDiscriminatorValue(member, discriminatorPropertyName) {
|
|
984
|
-
const
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
for (const intersectionMember of intersectionNode?.members ?? []) {
|
|
991
|
-
const value = getDiscriminatorValue(intersectionMember, discriminatorPropertyName);
|
|
992
|
-
if (value !== void 0) return value;
|
|
983
|
+
for (const property of kubb_kit.ast.resolveSchemaProperties({
|
|
984
|
+
node: member,
|
|
985
|
+
propertyName: discriminatorPropertyName
|
|
986
|
+
})) {
|
|
987
|
+
const values = kubb_kit.ast.getSchemaLiteralValues(property.schema);
|
|
988
|
+
if (values.length === 1) return values[0];
|
|
993
989
|
}
|
|
994
990
|
}
|
|
995
991
|
/**
|
|
@@ -1055,7 +1051,7 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
|
|
|
1055
1051
|
return `${resolvedName}${this.options.nestedInUnion && (node.schema?.type === "object" || node.schema?.type === "intersection") ? "<object>" : ""}()`;
|
|
1056
1052
|
},
|
|
1057
1053
|
enum(node) {
|
|
1058
|
-
return fakerKeywordMapper.enum(
|
|
1054
|
+
return fakerKeywordMapper.enum(kubb_kit.ast.getSchemaLiteralValues(node).map(parseEnumValue), this.options.typeName);
|
|
1059
1055
|
},
|
|
1060
1056
|
union(node) {
|
|
1061
1057
|
const { discriminatorPropertyName } = node;
|