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