@kubb/plugin-faker 5.3.0 → 5.3.2
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 +28 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -660,6 +660,22 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
660
660
|
}
|
|
661
661
|
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
662
662
|
/**
|
|
663
|
+
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
664
|
+
* per property, typed and serialized like any other.
|
|
665
|
+
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
666
|
+
*/
|
|
667
|
+
function spreadQuerystring(param) {
|
|
668
|
+
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
669
|
+
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
670
|
+
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
671
|
+
return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
|
|
672
|
+
name: property.name,
|
|
673
|
+
in: "query",
|
|
674
|
+
schema: property.schema,
|
|
675
|
+
required: param.required && property.required
|
|
676
|
+
}));
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
663
679
|
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
664
680
|
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
665
681
|
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
@@ -668,17 +684,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
668
684
|
function getOperationParameters(node) {
|
|
669
685
|
const cached = operationParameterGroupsByNode.get(node);
|
|
670
686
|
if (cached) return cached;
|
|
671
|
-
const
|
|
687
|
+
const dedupe = (params) => {
|
|
672
688
|
const seen = /* @__PURE__ */ new Set();
|
|
673
|
-
return
|
|
674
|
-
if (
|
|
689
|
+
return params.filter((param) => {
|
|
690
|
+
if (seen.has(param.name)) return false;
|
|
675
691
|
seen.add(param.name);
|
|
676
692
|
return true;
|
|
677
693
|
});
|
|
678
694
|
};
|
|
695
|
+
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
679
696
|
const groups = {
|
|
680
697
|
path: group("path"),
|
|
681
|
-
query: group("query"),
|
|
698
|
+
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
682
699
|
header: group("header"),
|
|
683
700
|
cookie: group("cookie")
|
|
684
701
|
};
|
|
@@ -1014,7 +1031,11 @@ const printerFaker = _kubb_kit.ast.createPrinter((options) => {
|
|
|
1014
1031
|
integer: (node) => numberCall("int", node.min, node.max),
|
|
1015
1032
|
bigint: () => "faker.number.bigInt()",
|
|
1016
1033
|
blob: () => "faker.image.url() as unknown as Blob",
|
|
1017
|
-
datetime
|
|
1034
|
+
datetime(node) {
|
|
1035
|
+
const parser = this.options.dateParser ?? "faker";
|
|
1036
|
+
if (parser === "faker") return "faker.date.anytime().toISOString()";
|
|
1037
|
+
return `${parser}(faker.date.anytime()).format("${node.local ? "YYYY-MM-DDTHH:mm:ss" : node.offset ? "YYYY-MM-DDTHH:mm:ssZ" : "YYYY-MM-DDTHH:mm:ss[Z]"}")`;
|
|
1038
|
+
},
|
|
1018
1039
|
date(node) {
|
|
1019
1040
|
return dateTimeCall(node.representation ?? "string", {
|
|
1020
1041
|
format: "YYYY-MM-DD",
|
|
@@ -1476,11 +1497,11 @@ const fakerGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1476
1497
|
});
|
|
1477
1498
|
// kubb-extension.json
|
|
1478
1499
|
var compatibility = {
|
|
1479
|
-
"kubb": ">=5.
|
|
1500
|
+
"kubb": ">=5.16.0",
|
|
1480
1501
|
"node": ">=22.22"
|
|
1481
1502
|
};
|
|
1482
1503
|
// package.json
|
|
1483
|
-
var version = "5.3.
|
|
1504
|
+
var version = "5.3.2";
|
|
1484
1505
|
// src/resolvers/resolverFaker.ts
|
|
1485
1506
|
/**
|
|
1486
1507
|
* Default resolver used by `@kubb/plugin-faker`. Decides the names and file
|