@ir-kit/openapi-ts-faker 0.1.0
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/LICENSE.md +21 -0
- package/README.md +78 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +38 -0
- package/dist/config.js.map +1 -0
- package/dist/core/builders.d.ts +20 -0
- package/dist/core/builders.d.ts.map +1 -0
- package/dist/core/builders.js +71 -0
- package/dist/core/builders.js.map +1 -0
- package/dist/core/hints.d.ts +4 -0
- package/dist/core/hints.d.ts.map +1 -0
- package/dist/core/hints.js +24 -0
- package/dist/core/hints.js.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/resolve.d.ts +15 -0
- package/dist/core/resolve.d.ts.map +1 -0
- package/dist/core/resolve.js +43 -0
- package/dist/core/resolve.js.map +1 -0
- package/dist/core/types.d.ts +45 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generators/factories.d.ts +3 -0
- package/dist/generators/factories.d.ts.map +1 -0
- package/dist/generators/factories.js +182 -0
- package/dist/generators/factories.js.map +1 -0
- package/dist/generators/index.d.ts +3 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +3 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/types.d.ts +13 -0
- package/dist/generators/types.d.ts.map +1 -0
- package/dist/generators/types.js +2 -0
- package/dist/generators/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +24 -0
- package/dist/plugin.js.map +1 -0
- package/dist/symbols/external.d.ts +6 -0
- package/dist/symbols/external.d.ts.map +1 -0
- package/dist/symbols/external.js +11 -0
- package/dist/symbols/external.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/helpers.d.ts +35 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +78 -0
- package/dist/utils/helpers.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +84 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ahmed Rowaihi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @ir-kit/openapi-ts-faker
|
|
2
|
+
|
|
3
|
+
Faker.js mock-data factories from an OpenAPI spec. Plugin for [`@hey-api/openapi-ts`](https://heyapi.dev).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @ir-kit/openapi-ts-faker @hey-api/openapi-ts
|
|
9
|
+
npm install @faker-js/faker
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Use
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { defineConfig } from "@hey-api/openapi-ts";
|
|
16
|
+
import { defineConfig as defineFakerConfig } from "@ir-kit/openapi-ts-faker";
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
input: "openapi.yaml",
|
|
20
|
+
output: { path: "./generated" },
|
|
21
|
+
plugins: [
|
|
22
|
+
"@hey-api/typescript",
|
|
23
|
+
defineFakerConfig({
|
|
24
|
+
fieldNameHints: { email: "internet.email", firstName: "person.firstName" },
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Resolution order (per property)
|
|
31
|
+
|
|
32
|
+
1. OpenAPI `format` → `formatMapping`
|
|
33
|
+
2. `fieldNameHints` exact match (keys are case/separator-insensitive: `email`, `Email`, `user_email` all normalize the same)
|
|
34
|
+
3. `enum` → `helpers.arrayElement([...])`
|
|
35
|
+
4. Type fallback (`integer` → `number.int`, etc.)
|
|
36
|
+
|
|
37
|
+
No default field hints. `formatMapping` ships with sensible defaults you can override.
|
|
38
|
+
|
|
39
|
+
## Mapping
|
|
40
|
+
|
|
41
|
+
| OpenAPI | Output |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `type: object` | `() => ({ ...props })` |
|
|
44
|
+
| `allOf` | merged object |
|
|
45
|
+
| `oneOf` / `anyOf` | `helpers.arrayElement([() => v1, () => v2])()` |
|
|
46
|
+
| `enum` | `helpers.arrayElement([...])` |
|
|
47
|
+
| `type: array` | `helpers.multiple(() => item, { count: { min, max } })` |
|
|
48
|
+
| `$ref` | call to sibling factory: `createMockX()` |
|
|
49
|
+
| cyclic `$ref` | `null` (broken at codegen to avoid runtime recursion) |
|
|
50
|
+
|
|
51
|
+
## Type safety
|
|
52
|
+
|
|
53
|
+
`fieldNameHints` and `formatMapping` values are typed against `FakerMethodPath` — every Faker method callable with zero args. Typos and arg-required methods (e.g. `helpers.arrayElement`) fail at compile time.
|
|
54
|
+
|
|
55
|
+
## Options
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
defineFakerConfig({
|
|
59
|
+
output: "factories.gen", // filename
|
|
60
|
+
fieldNameHints: {}, // field → faker method
|
|
61
|
+
formatMapping: {}, // format → faker method (merged with defaults)
|
|
62
|
+
respectConstraints: true, // honor minimum/maximum, minLength/maxLength, minItems/maxItems
|
|
63
|
+
generateBatchCreators: true, // emit createMockXs(count?)
|
|
64
|
+
defaultBatchCount: 10, // default count when caller omits arg
|
|
65
|
+
include: ["User", "Order"], // only these schemas
|
|
66
|
+
exclude: ["Internal"], // skip these schemas
|
|
67
|
+
filter: (s) => Boolean(s.title), // custom predicate
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
When `respectConstraints` is on:
|
|
72
|
+
- `{ minimum: 18, maximum: 99 }` → `number.int({ min: 18, max: 99 })`
|
|
73
|
+
- `{ maxLength: 8 }` → `string.alpha({ length: 8 })`
|
|
74
|
+
- `{ minItems: 2, maxItems: 5 }` → `helpers.multiple(..., { count: { min: 2, max: 5 } })`
|
|
75
|
+
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_FORMAT_MAPPING } from "./core/hints.js";
|
|
2
|
+
import type { FakerPlugin } from "./types.js";
|
|
3
|
+
export { DEFAULT_FORMAT_MAPPING };
|
|
4
|
+
export declare const defaultConfig: FakerPlugin["Config"];
|
|
5
|
+
export declare const defineConfig: (userConfig?: Omit<import("./types.js").UserConfig, "name"> | undefined) => Omit<import("@hey-api/shared").Plugin.Config<import("@hey-api/shared").Plugin.Types<import("./types.js").UserConfig, import("./types.js").Config, never>>, "name"> & {
|
|
6
|
+
name: any;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAclC,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,QAAQ,CAuB/C,CAAC;AAEF,eAAO,MAAM,YAAY;;CAAoC,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { definePluginConfig } from "@hey-api/shared";
|
|
2
|
+
import { DEFAULT_FORMAT_MAPPING } from "./core/hints.js";
|
|
3
|
+
import { handler } from "./plugin.js";
|
|
4
|
+
export { DEFAULT_FORMAT_MAPPING };
|
|
5
|
+
const normalizeHintKey = (key) => key.toLowerCase().replace(/[_-]/g, "");
|
|
6
|
+
const normalizeFieldNameHints = (hints) => {
|
|
7
|
+
if (!hints)
|
|
8
|
+
return {};
|
|
9
|
+
const out = {};
|
|
10
|
+
for (const [key, value] of Object.entries(hints)) {
|
|
11
|
+
out[normalizeHintKey(key)] = value;
|
|
12
|
+
}
|
|
13
|
+
return out;
|
|
14
|
+
};
|
|
15
|
+
export const defaultConfig = {
|
|
16
|
+
config: {
|
|
17
|
+
output: "factories.gen",
|
|
18
|
+
fieldNameHints: {},
|
|
19
|
+
formatMapping: DEFAULT_FORMAT_MAPPING,
|
|
20
|
+
generateBatchCreators: true,
|
|
21
|
+
defaultBatchCount: 10,
|
|
22
|
+
respectConstraints: true,
|
|
23
|
+
includeInEntry: true,
|
|
24
|
+
},
|
|
25
|
+
dependencies: ["@hey-api/typescript"],
|
|
26
|
+
handler,
|
|
27
|
+
name: "@ir-kit/openapi-ts-faker",
|
|
28
|
+
resolveConfig: (plugin) => {
|
|
29
|
+
plugin.config.fieldNameHints = normalizeFieldNameHints(plugin.config.fieldNameHints);
|
|
30
|
+
plugin.config.formatMapping = {
|
|
31
|
+
...DEFAULT_FORMAT_MAPPING,
|
|
32
|
+
...plugin.config.formatMapping,
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
tags: ["transformer"],
|
|
36
|
+
};
|
|
37
|
+
export const defineConfig = definePluginConfig(defaultConfig);
|
|
38
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAElC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAU,EAAE,CAC/C,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAEzC,MAAM,uBAAuB,GAAG,CAAC,KAAsB,EAAkB,EAAE;IACzE,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,GAAG,GAAmB,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,MAAM,EAAE;QACN,MAAM,EAAE,eAAe;QACvB,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,sBAAsB;QACrC,qBAAqB,EAAE,IAAI;QAC3B,iBAAiB,EAAE,EAAE;QACrB,kBAAkB,EAAE,IAAI;QACxB,cAAc,EAAE,IAAI;KACrB;IACD,YAAY,EAAE,CAAC,qBAAqB,CAAC;IACrC,OAAO;IACP,IAAI,EAAE,0BAA0B;IAChC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;QACxB,MAAM,CAAC,MAAM,CAAC,cAAc,GAAG,uBAAuB,CACpD,MAAM,CAAC,MAAM,CAAC,cAAc,CAC7B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,aAAa,GAAG;YAC5B,GAAG,sBAAsB;YACzB,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa;SAC/B,CAAC;IACJ,CAAC;IACD,IAAI,EAAE,CAAC,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Symbol as CodegenSymbol } from "@hey-api/codegen-core";
|
|
2
|
+
import { type TsDsl } from "@hey-api/openapi-ts";
|
|
3
|
+
import type ts from "typescript";
|
|
4
|
+
import { type FakerCallSpec, type ResolveOptions } from "./resolve.js";
|
|
5
|
+
import type { PropertyInfo } from "./types.js";
|
|
6
|
+
export type FakerSymbol = CodegenSymbol;
|
|
7
|
+
export type FakerExpr = TsDsl<ts.Expression>;
|
|
8
|
+
export interface BuildFakerOptions extends ResolveOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Called when `info.$ref` is set. Return an expression (typically a call to
|
|
11
|
+
* a sibling factory) or `null` to skip ref handling. When `null` is returned
|
|
12
|
+
* or no resolver is provided, the builder falls through to inline generation
|
|
13
|
+
* if `info.children` / `info.items` / `info.type` are present, otherwise
|
|
14
|
+
* defaults to `lorem.word`.
|
|
15
|
+
*/
|
|
16
|
+
resolveRef?: (ref: string) => FakerExpr | null;
|
|
17
|
+
}
|
|
18
|
+
export declare function buildFakerCall(faker: FakerSymbol, spec: FakerCallSpec): FakerExpr;
|
|
19
|
+
export declare function buildFakerExpression(faker: FakerSymbol, info: PropertyInfo, opts?: BuildFakerOptions): FakerExpr;
|
|
20
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/core/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAK,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AACxC,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;AAE7C,MAAM,WAAW,iBAAkB,SAAQ,cAAc;IACvD;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,GAAG,IAAI,CAAC;CAChD;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,aAAa,GAClB,SAAS,CAqBX;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,YAAY,EAClB,IAAI,GAAE,iBAAsB,GAC3B,SAAS,CAkDX"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { $ } from "@hey-api/openapi-ts";
|
|
2
|
+
import { DATE_METHODS } from "./hints.js";
|
|
3
|
+
import { resolveFakerCall, } from "./resolve.js";
|
|
4
|
+
export function buildFakerCall(faker, spec) {
|
|
5
|
+
if (spec.method === "__null__")
|
|
6
|
+
return $.literal(null);
|
|
7
|
+
const [mod, fn] = spec.method.split(".");
|
|
8
|
+
const args = [];
|
|
9
|
+
if (spec.args && Object.keys(spec.args).length > 0) {
|
|
10
|
+
let argObj = $.object();
|
|
11
|
+
for (const [key, value] of Object.entries(spec.args)) {
|
|
12
|
+
argObj = argObj.prop(key, $.literal(value));
|
|
13
|
+
}
|
|
14
|
+
args.push(argObj);
|
|
15
|
+
}
|
|
16
|
+
const call = $(faker)
|
|
17
|
+
.attr(mod)
|
|
18
|
+
.attr(fn)
|
|
19
|
+
.call(...args);
|
|
20
|
+
if (DATE_METHODS.has(spec.method)) {
|
|
21
|
+
return call.attr("toISOString").call();
|
|
22
|
+
}
|
|
23
|
+
return call;
|
|
24
|
+
}
|
|
25
|
+
export function buildFakerExpression(faker, info, opts = {}) {
|
|
26
|
+
if (info.$ref && opts.resolveRef) {
|
|
27
|
+
const refExpr = opts.resolveRef(info.$ref);
|
|
28
|
+
if (refExpr)
|
|
29
|
+
return refExpr;
|
|
30
|
+
}
|
|
31
|
+
if (info.variants && info.variants.length > 0) {
|
|
32
|
+
const arrowFns = info.variants.map((v) => $.func().do($.return(buildFakerExpression(faker, v, opts))));
|
|
33
|
+
return $(faker)
|
|
34
|
+
.attr("helpers")
|
|
35
|
+
.attr("arrayElement")
|
|
36
|
+
.call($.array(...arrowFns))
|
|
37
|
+
.call();
|
|
38
|
+
}
|
|
39
|
+
if (info.enum && info.enum.length > 0) {
|
|
40
|
+
const literals = $.array(...info.enum.map((v) => $.literal(v)));
|
|
41
|
+
return $(faker).attr("helpers").attr("arrayElement").call(literals);
|
|
42
|
+
}
|
|
43
|
+
if (info.type === "object") {
|
|
44
|
+
if (info.children && Object.keys(info.children).length > 0) {
|
|
45
|
+
let obj = $.object().pretty();
|
|
46
|
+
for (const [key, child] of Object.entries(info.children)) {
|
|
47
|
+
obj = obj.prop(key, buildFakerExpression(faker, child, opts));
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
return $.object();
|
|
52
|
+
}
|
|
53
|
+
if (info.type === "array") {
|
|
54
|
+
if (!info.items)
|
|
55
|
+
return $.array();
|
|
56
|
+
const itemExpr = buildFakerExpression(faker, info.items, opts);
|
|
57
|
+
const itemFn = $.func().do($.return(itemExpr));
|
|
58
|
+
const respect = opts.respectConstraints ?? false;
|
|
59
|
+
const min = respect ? (info.minItems ?? 1) : 1;
|
|
60
|
+
const max = respect ? (info.maxItems ?? Math.max(min, 3)) : 3;
|
|
61
|
+
const countArg = $.object()
|
|
62
|
+
.prop("min", $.literal(min))
|
|
63
|
+
.prop("max", $.literal(max));
|
|
64
|
+
return $(faker)
|
|
65
|
+
.attr("helpers")
|
|
66
|
+
.attr("multiple")
|
|
67
|
+
.call(itemFn, $.object().prop("count", countArg));
|
|
68
|
+
}
|
|
69
|
+
return buildFakerCall(faker, resolveFakerCall(info, opts));
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.js","sourceRoot":"","sources":["../../src/core/builders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAc,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAGL,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAiBtB,MAAM,UAAU,cAAc,CAC5B,KAAkB,EAClB,IAAmB;IAEnB,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU;QAAE,OAAO,CAAC,CAA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AAC;aACZ,IAAI,CAAC,SAAS,CAAC;aACf,IAAI,CAAC,UAAU,CAAC;aAChB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../src/core/hints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,eAAO,MAAM,sBAAsB,EAAE,aAiBpC,CAAC;AAEF,eAAO,MAAM,YAAY,aAIvB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const DEFAULT_FORMAT_MAPPING = {
|
|
2
|
+
email: "internet.email",
|
|
3
|
+
uri: "internet.url",
|
|
4
|
+
url: "internet.url",
|
|
5
|
+
hostname: "internet.domainName",
|
|
6
|
+
ipv4: "internet.ipv4",
|
|
7
|
+
ipv6: "internet.ipv6",
|
|
8
|
+
uuid: "string.uuid",
|
|
9
|
+
"date-time": "date.recent",
|
|
10
|
+
date: "date.past",
|
|
11
|
+
time: "date.recent",
|
|
12
|
+
binary: "string.alphanumeric",
|
|
13
|
+
byte: "string.alphanumeric",
|
|
14
|
+
float: "number.float",
|
|
15
|
+
double: "number.float",
|
|
16
|
+
int32: "number.int",
|
|
17
|
+
int64: "number.int",
|
|
18
|
+
};
|
|
19
|
+
export const DATE_METHODS = new Set([
|
|
20
|
+
"date.past",
|
|
21
|
+
"date.recent",
|
|
22
|
+
"date.birthdate",
|
|
23
|
+
]);
|
|
24
|
+
//# sourceMappingURL=hints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hints.js","sourceRoot":"","sources":["../../src/core/hints.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,KAAK,EAAE,gBAAgB;IACvB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,cAAc;IACnB,QAAQ,EAAE,qBAAqB;IAC/B,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,aAAa;IAC1B,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,aAAa;IACnB,MAAM,EAAE,qBAAqB;IAC7B,IAAI,EAAE,qBAAqB;IAC3B,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE,cAAc;IACtB,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,YAAY;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAClC,WAAW;IACX,aAAa;IACb,gBAAgB;CACjB,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type BuildFakerOptions, buildFakerCall, buildFakerExpression, type FakerExpr, type FakerSymbol, } from "./builders.js";
|
|
2
|
+
export { DATE_METHODS, DEFAULT_FORMAT_MAPPING } from "./hints.js";
|
|
3
|
+
export { type FakerCallSpec, type ResolvedFakerMethod, type ResolveOptions, resolveFakerCall, } from "./resolve.js";
|
|
4
|
+
export type { FakerMethodPath, FieldNameHints, FormatMapping, PropertyInfo, ResponseSchemaInfo, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EACtB,cAAc,EACd,oBAAoB,EACpB,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAIL,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FakerMethodPath, FieldNameHints, FormatMapping, PropertyInfo } from "./types.js";
|
|
2
|
+
declare const NULL_METHOD: "__null__";
|
|
3
|
+
export type ResolvedFakerMethod = FakerMethodPath | typeof NULL_METHOD;
|
|
4
|
+
export interface ResolveOptions {
|
|
5
|
+
fieldHints?: FieldNameHints;
|
|
6
|
+
formatHints?: FormatMapping;
|
|
7
|
+
respectConstraints?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface FakerCallSpec {
|
|
10
|
+
method: ResolvedFakerMethod;
|
|
11
|
+
args?: Record<string, number>;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveFakerCall(info: PropertyInfo, opts?: ResolveOptions): FakerCallSpec;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/core/resolve.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,QAAA,MAAM,WAAW,EAAG,UAAmB,CAAC;AACxC,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG,OAAO,WAAW,CAAC;AAEvE,MAAM,WAAW,cAAc;IAC7B,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAQD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,YAAY,EAClB,IAAI,GAAE,cAAmB,GACxB,aAAa,CAwCf"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DEFAULT_FORMAT_MAPPING } from "./hints.js";
|
|
2
|
+
const NULL_METHOD = "__null__";
|
|
3
|
+
const hasNumericConstraint = (info) => info.minimum !== undefined || info.maximum !== undefined;
|
|
4
|
+
const hasLengthConstraint = (info) => info.minLength !== undefined || info.maxLength !== undefined;
|
|
5
|
+
export function resolveFakerCall(info, opts = {}) {
|
|
6
|
+
const fieldHints = opts.fieldHints ?? {};
|
|
7
|
+
const formatHints = opts.formatHints ?? DEFAULT_FORMAT_MAPPING;
|
|
8
|
+
const respect = opts.respectConstraints ?? false;
|
|
9
|
+
if (info.format && formatHints[info.format]) {
|
|
10
|
+
return { method: formatHints[info.format] };
|
|
11
|
+
}
|
|
12
|
+
const normalized = info.name.toLowerCase().replace(/[_-]/g, "");
|
|
13
|
+
if (fieldHints[normalized]) {
|
|
14
|
+
return { method: fieldHints[normalized] };
|
|
15
|
+
}
|
|
16
|
+
switch (info.type) {
|
|
17
|
+
case "integer":
|
|
18
|
+
case "number": {
|
|
19
|
+
const method = info.type === "integer" ? "number.int" : "number.float";
|
|
20
|
+
if (respect && hasNumericConstraint(info)) {
|
|
21
|
+
const args = {};
|
|
22
|
+
if (info.minimum !== undefined)
|
|
23
|
+
args.min = info.minimum;
|
|
24
|
+
if (info.maximum !== undefined)
|
|
25
|
+
args.max = info.maximum;
|
|
26
|
+
return { method, args };
|
|
27
|
+
}
|
|
28
|
+
return { method };
|
|
29
|
+
}
|
|
30
|
+
case "boolean":
|
|
31
|
+
return { method: "datatype.boolean" };
|
|
32
|
+
case "null":
|
|
33
|
+
return { method: NULL_METHOD };
|
|
34
|
+
default: {
|
|
35
|
+
if (respect && hasLengthConstraint(info)) {
|
|
36
|
+
const length = info.maxLength ?? info.minLength;
|
|
37
|
+
return { method: "string.alpha", args: { length } };
|
|
38
|
+
}
|
|
39
|
+
return { method: "lorem.word" };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/core/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAQpD,MAAM,WAAW,GAAG,UAAmB,CAAC;AAcxC,MAAM,oBAAoB,GAAG,CAAC,IAAkB,EAAW,EAAE,CAC3D,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC;AAE3D,MAAM,mBAAmB,GAAG,CAAC,IAAkB,EAAW,EAAE,CAC1D,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;AAE/D,MAAM,UAAU,gBAAgB,CAC9B,IAAkB,EAClB,OAAuB,EAAE;IAEzB,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;IACzC,MAAM,WAAW,GACf,IAAI,CAAC,WAAW,IAAK,sBAAwC,CAAC;IAChE,MAAM,OAAO,GAAG,IAAI,CAAC,kBAAkB,IAAI,KAAK,CAAC;IAEjD,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,C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AAI,IAAI,CAAC,SAAU,CAAC;gBACjD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;YACtD,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Faker } from "@faker-js/faker";
|
|
2
|
+
export interface PropertyInfo {
|
|
3
|
+
type: string;
|
|
4
|
+
format?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* Set when this property is a `$ref` to another schema. The builder calls
|
|
8
|
+
* `opts.resolveRef(ref)` to emit a reference (e.g. a call to a sibling
|
|
9
|
+
* factory) instead of inlining the target schema. Avoids infinite recursion
|
|
10
|
+
* for cyclic schemas and matches the zod-plugin / openapi-ts ref-by-symbol
|
|
11
|
+
* convention.
|
|
12
|
+
*/
|
|
13
|
+
$ref?: string;
|
|
14
|
+
enum?: (string | number | boolean)[];
|
|
15
|
+
/** Set for `oneOf`/`anyOf` schemas. Builder emits a runtime random pick. */
|
|
16
|
+
variants?: PropertyInfo[];
|
|
17
|
+
children?: Record<string, PropertyInfo>;
|
|
18
|
+
items?: PropertyInfo;
|
|
19
|
+
minimum?: number;
|
|
20
|
+
maximum?: number;
|
|
21
|
+
minLength?: number;
|
|
22
|
+
maxLength?: number;
|
|
23
|
+
minItems?: number;
|
|
24
|
+
maxItems?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ResponseSchemaInfo {
|
|
27
|
+
properties: Record<string, PropertyInfo>;
|
|
28
|
+
isArray: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* All `module.method` paths on the Faker instance whose method is callable
|
|
32
|
+
* with zero arguments. Methods that require arguments (e.g.
|
|
33
|
+
* `helpers.arrayElement`, `helpers.fromRegExp`) are excluded so they cannot
|
|
34
|
+
* be used as field-name or format hints — those would emit empty calls.
|
|
35
|
+
*/
|
|
36
|
+
type ExtractZeroArgFakerPaths<T> = {
|
|
37
|
+
[K in keyof T]: K extends string ? T[K] extends object ? {
|
|
38
|
+
[M in keyof T[K]]: M extends string ? T[K][M] extends () => unknown ? `${K}.${M}` : never : never;
|
|
39
|
+
}[keyof T[K]] : never : never;
|
|
40
|
+
}[keyof T];
|
|
41
|
+
export type FakerMethodPath = ExtractZeroArgFakerPaths<Faker>;
|
|
42
|
+
export type FieldNameHints = Record<string, FakerMethodPath>;
|
|
43
|
+
export type FormatMapping = Record<string, FakerMethodPath>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IACrC,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACzC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,KAAK,wBAAwB,CAAC,CAAC,IAAI;KAChC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,MAAM,GAC5B,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GACjB;SACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,GAC/B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,OAAO,GAC3B,GAAG,CAAC,IAAI,CAAC,EAAE,GACX,KAAK,GACP,KAAK;KACV,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GACb,KAAK,GACP,KAAK;CACV,CAAC,MAAM,CAAC,CAAC,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAC7D,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../src/generators/factories.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAuB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AA2G9E,eAAO,MAAM,iBAAiB,GAAI,yBAG/B,sBAAsB,KAAG,IAwE3B,CAAC"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { $ } from "@hey-api/openapi-ts";
|
|
2
|
+
import { buildGraph } from "@hey-api/shared";
|
|
3
|
+
import { buildFakerExpression } from "../core/builders.js";
|
|
4
|
+
import { schemaToBatchFactoryName, schemaToFactoryName, shouldIncludeSchema, } from "../utils/helpers.js";
|
|
5
|
+
const schemaNameFromRef = (ref) => {
|
|
6
|
+
const m = ref.match(/\/([^/]+)$/);
|
|
7
|
+
return m ? decodeURIComponent(m[1]) : null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* IR walker. Produces a `PropertyInfo` tree from an `IR.SchemaObject`.
|
|
11
|
+
*
|
|
12
|
+
* Refs (`$ref`) are recorded but not followed — the builder emits a sibling
|
|
13
|
+
* factory call via `opts.resolveRef`. The exception is `allOf` composition,
|
|
14
|
+
* which must inline ref'd properties to merge them; for that path we resolve
|
|
15
|
+
* refs via `plugin.context.resolveIrRef` and guard cycles with `visited`.
|
|
16
|
+
*/
|
|
17
|
+
function irToPropertyInfo(name, schema, plugin, visited = new Set()) {
|
|
18
|
+
if (schema.$ref) {
|
|
19
|
+
return { type: "ref", name, $ref: schema.$ref };
|
|
20
|
+
}
|
|
21
|
+
// IR encodes enums as { type: "enum", items: [{ const: value }, ...] }
|
|
22
|
+
if (schema.type === "enum" && schema.items?.length) {
|
|
23
|
+
const values = schema.items
|
|
24
|
+
.map((item) => item.const)
|
|
25
|
+
.filter((v) => v !== undefined);
|
|
26
|
+
return {
|
|
27
|
+
type: "string",
|
|
28
|
+
format: schema.format,
|
|
29
|
+
name,
|
|
30
|
+
...(values.length > 0 && { enum: values }),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// allOf — merge children. Resolve refs inline since merging requires the
|
|
34
|
+
// target's properties.
|
|
35
|
+
if (schema.logicalOperator === "and" && schema.items?.length) {
|
|
36
|
+
const merged = {};
|
|
37
|
+
for (const part of schema.items) {
|
|
38
|
+
const partInfo = mergePart(part, plugin, visited);
|
|
39
|
+
if (partInfo?.children)
|
|
40
|
+
Object.assign(merged, partInfo.children);
|
|
41
|
+
}
|
|
42
|
+
return { type: "object", name, children: merged };
|
|
43
|
+
}
|
|
44
|
+
// oneOf / anyOf — record variants for runtime random pick.
|
|
45
|
+
if (schema.logicalOperator === "or" && schema.items?.length) {
|
|
46
|
+
return {
|
|
47
|
+
type: "union",
|
|
48
|
+
name,
|
|
49
|
+
variants: schema.items.map((variant, i) => irToPropertyInfo(`${name}_v${i}`, variant, plugin, visited)),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const type = Array.isArray(schema.type)
|
|
53
|
+
? (schema.type.find((t) => t !== "null") ?? "string")
|
|
54
|
+
: (schema.type ?? "string");
|
|
55
|
+
const info = { type, format: schema.format, name };
|
|
56
|
+
if (schema.minimum !== undefined)
|
|
57
|
+
info.minimum = schema.minimum;
|
|
58
|
+
if (schema.maximum !== undefined)
|
|
59
|
+
info.maximum = schema.maximum;
|
|
60
|
+
if (schema.minLength !== undefined)
|
|
61
|
+
info.minLength = schema.minLength;
|
|
62
|
+
if (schema.maxLength !== undefined)
|
|
63
|
+
info.maxLength = schema.maxLength;
|
|
64
|
+
if (schema.minItems !== undefined)
|
|
65
|
+
info.minItems = schema.minItems;
|
|
66
|
+
if (schema.maxItems !== undefined)
|
|
67
|
+
info.maxItems = schema.maxItems;
|
|
68
|
+
if (type === "object" && schema.properties) {
|
|
69
|
+
info.children = {};
|
|
70
|
+
for (const [key, value] of Object.entries(schema.properties)) {
|
|
71
|
+
if (value)
|
|
72
|
+
info.children[key] = irToPropertyInfo(key, value, plugin, visited);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (type === "array" && schema.items?.length) {
|
|
76
|
+
info.items = irToPropertyInfo("item", schema.items[0], plugin, visited);
|
|
77
|
+
}
|
|
78
|
+
return info;
|
|
79
|
+
}
|
|
80
|
+
/** Resolve a part of an allOf composition into an object PropertyInfo. */
|
|
81
|
+
function mergePart(part, plugin, visited) {
|
|
82
|
+
if (part.$ref) {
|
|
83
|
+
if (visited.has(part.$ref))
|
|
84
|
+
return null;
|
|
85
|
+
const next = new Set(visited);
|
|
86
|
+
next.add(part.$ref);
|
|
87
|
+
const target = plugin.context.resolveIrRef(part.$ref);
|
|
88
|
+
if (!target)
|
|
89
|
+
return null;
|
|
90
|
+
return irToPropertyInfo("merged", target, plugin, next);
|
|
91
|
+
}
|
|
92
|
+
return irToPropertyInfo("merged", part, plugin, visited);
|
|
93
|
+
}
|
|
94
|
+
const refToSchemaName = (ref) => schemaNameFromRef(ref);
|
|
95
|
+
export const generateFactories = ({ plugin, outputFile, }) => {
|
|
96
|
+
const config = plugin.config;
|
|
97
|
+
const faker = plugin.external("@faker-js/faker.faker");
|
|
98
|
+
const { graph } = buildGraph(plugin.context.spec, plugin.context.logger);
|
|
99
|
+
const reaches = (fromName, toName) => {
|
|
100
|
+
for (const [refKey, deps] of graph.transitiveDependencies) {
|
|
101
|
+
if (refToSchemaName(refKey) !== fromName)
|
|
102
|
+
continue;
|
|
103
|
+
for (const dep of deps) {
|
|
104
|
+
if (refToSchemaName(dep) === toName)
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
};
|
|
110
|
+
const generatedFactories = [];
|
|
111
|
+
// Schemas we emit a factory for: plain objects + allOf composition + oneOf/
|
|
112
|
+
// anyOf unions. Skip raw scalars, top-level enums, and standalone arrays.
|
|
113
|
+
const isFactoryable = (s) => s.type === "object" ||
|
|
114
|
+
s.logicalOperator === "and" ||
|
|
115
|
+
s.logicalOperator === "or";
|
|
116
|
+
// Pass 2: emit factories.
|
|
117
|
+
plugin.forEach("schema", (event) => {
|
|
118
|
+
const { schema, name } = event;
|
|
119
|
+
if (!name)
|
|
120
|
+
return;
|
|
121
|
+
const schemaName = name;
|
|
122
|
+
if (!isFactoryable(schema))
|
|
123
|
+
return;
|
|
124
|
+
if (!shouldIncludeSchema(schemaName, config.include, config.exclude)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (config.filter && !config.filter(schema))
|
|
128
|
+
return;
|
|
129
|
+
const factoryName = schemaToFactoryName(schemaName);
|
|
130
|
+
const factorySymbol = plugin.symbol(factoryName, {
|
|
131
|
+
getFilePath: () => outputFile,
|
|
132
|
+
});
|
|
133
|
+
const rootInfo = irToPropertyInfo(schemaName, schema, plugin);
|
|
134
|
+
const body = buildFakerExpression(faker, rootInfo, {
|
|
135
|
+
fieldHints: config.fieldNameHints,
|
|
136
|
+
formatHints: config.formatMapping,
|
|
137
|
+
respectConstraints: config.respectConstraints,
|
|
138
|
+
resolveRef: (ref) => {
|
|
139
|
+
const target = refToSchemaName(ref);
|
|
140
|
+
if (!target)
|
|
141
|
+
return null;
|
|
142
|
+
if (target === schemaName || reaches(target, schemaName)) {
|
|
143
|
+
return $.literal(null);
|
|
144
|
+
}
|
|
145
|
+
return $(schemaToFactoryName(target)).call();
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const factoryFn = $.func().do($.return(body));
|
|
149
|
+
const statement = $.const(factorySymbol).export().assign(factoryFn);
|
|
150
|
+
plugin.node(statement);
|
|
151
|
+
generatedFactories.push(schemaName);
|
|
152
|
+
});
|
|
153
|
+
if (config.generateBatchCreators && generatedFactories.length > 0) {
|
|
154
|
+
generateBatchCreators({
|
|
155
|
+
plugin,
|
|
156
|
+
outputFile,
|
|
157
|
+
schemaNames: generatedFactories,
|
|
158
|
+
faker,
|
|
159
|
+
defaultCount: config.defaultBatchCount,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function generateBatchCreators({ plugin, outputFile, schemaNames, faker, defaultCount, }) {
|
|
164
|
+
for (const schemaName of schemaNames) {
|
|
165
|
+
const factoryName = schemaToFactoryName(schemaName);
|
|
166
|
+
const batchFactoryName = schemaToBatchFactoryName(schemaName);
|
|
167
|
+
const batchSymbol = plugin.symbol(batchFactoryName, {
|
|
168
|
+
getFilePath: () => outputFile,
|
|
169
|
+
});
|
|
170
|
+
const countExpr = $.binary($.id("count"), "??", $.literal(defaultCount));
|
|
171
|
+
const batchCall = $(faker)
|
|
172
|
+
.attr("helpers")
|
|
173
|
+
.attr("multiple")
|
|
174
|
+
.call($.id(factoryName), $.object().prop("count", countExpr));
|
|
175
|
+
const batchFn = $.func()
|
|
176
|
+
.param("count", (p) => p.type($.type.expr("number")).optional())
|
|
177
|
+
.do($.return(batchCall));
|
|
178
|
+
const statement = $.const(batchSymbol).export().assign(batchFn);
|
|
179
|
+
plugin.node(statement);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=factories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factories.js","sourceRoot":"","sources":["../../src/generators/factories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACxC,OAAO,EAAE,UAAU,EAAW,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAAoB,MAAM,qBAAqB,CAAC;AAE7E,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAG7B,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAiB,EAAE;IACvD,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,SAAS,gBAAgB,CACvB,IAAY,EACZ,MAAuB,EACvB,MAA2B,EAC3B,UAA+B,IAAI,GAAG,EAAE;IAExC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;QAChB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAClD,CAAC;IAED,uEAAuE;IACvE,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,CAA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AE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;aAC/D,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAE3B,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAChE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FakerPlugin } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Plugin instance type for Faker generators
|
|
4
|
+
*/
|
|
5
|
+
export type FakerPluginInstance = Parameters<FakerPlugin["Handler"]>[0]["plugin"];
|
|
6
|
+
/**
|
|
7
|
+
* Input for factories generator
|
|
8
|
+
*/
|
|
9
|
+
export interface GenerateFactoriesInput {
|
|
10
|
+
plugin: FakerPluginInstance;
|
|
11
|
+
outputFile: string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generators/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAC1C,WAAW,CAAC,SAAS,CAAC,CACvB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generators/types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,OAAO,YAAY,CAAC;AAEpB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC1D,cAAc,iBAAiB,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,OAAO,EAAE,WAAW,CAAC,SAAS,CAqB1C,CAAC"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { generateFactories } from "./generators/index.js";
|
|
2
|
+
import { registerExternalSymbols } from "./symbols/external.js";
|
|
3
|
+
/**
|
|
4
|
+
* Main faker plugin handler.
|
|
5
|
+
* Generates faker factory functions from OpenAPI schemas.
|
|
6
|
+
*/
|
|
7
|
+
export const handler = ({ plugin }) => {
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// External Symbols Registration
|
|
10
|
+
// ============================================================================
|
|
11
|
+
registerExternalSymbols(plugin);
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// File Paths Configuration
|
|
14
|
+
// ============================================================================
|
|
15
|
+
const outputFile = `${plugin.name}/${plugin.config.output}`;
|
|
16
|
+
// ============================================================================
|
|
17
|
+
// Factory Generation
|
|
18
|
+
// ============================================================================
|
|
19
|
+
generateFactories({
|
|
20
|
+
plugin,
|
|
21
|
+
outputFile,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAGhE;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAA2B,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5D,+EAA+E;IAC/E,gCAAgC;IAChC,+EAA+E;IAE/E,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAEhC,+EAA+E;IAC/E,2BAA2B;IAC3B,+EAA+E;IAE/E,MAAM,UAAU,GAAG,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAE5D,+EAA+E;IAC/E,qBAAqB;IACrB,+EAA+E;IAE/E,iBAAiB,CAAC;QAChB,MAAM;QACN,UAAU;KACX,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/symbols/external.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,QAAQ,mBAAmB,KAAG,IAMrE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register external symbols from faker library
|
|
3
|
+
*/
|
|
4
|
+
export const registerExternalSymbols = (plugin) => {
|
|
5
|
+
// Register faker as an external symbol that can be used with $()
|
|
6
|
+
plugin.symbol("faker", {
|
|
7
|
+
external: "@faker-js/faker",
|
|
8
|
+
meta: { category: "external", resource: "@faker-js/faker.faker" },
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=external.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/symbols/external.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAA2B,EAAQ,EAAE;IAC3E,iEAAiE;IACjE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;QACrB,QAAQ,EAAE,iBAAiB;QAC3B,IAAI,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,uBAAuB,EAAE;KAClE,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { DefinePlugin, IR, Plugin } from "@hey-api/shared";
|
|
2
|
+
import type { FieldNameHints, FormatMapping } from "./core/types.js";
|
|
3
|
+
export type { FakerMethodPath, FieldNameHints, FormatMapping, } from "./core/types.js";
|
|
4
|
+
export type SchemaFilter = (schema: IR.SchemaObject) => boolean;
|
|
5
|
+
export type UserConfig = Plugin.Hooks & Plugin.UserExports & {
|
|
6
|
+
name: "@ir-kit/openapi-ts-faker";
|
|
7
|
+
/**
|
|
8
|
+
* Output file name for generated factories
|
|
9
|
+
* @default 'factories.gen'
|
|
10
|
+
*/
|
|
11
|
+
output?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Field name hints. Keys are field names (any case, with or without
|
|
14
|
+
* separators — `email`, `Email`, `user_email` all normalize the same way).
|
|
15
|
+
* Values must be valid faker method paths.
|
|
16
|
+
* @example { email: "internet.email", phone: "phone.number" }
|
|
17
|
+
*/
|
|
18
|
+
fieldNameHints?: FieldNameHints;
|
|
19
|
+
/**
|
|
20
|
+
* OpenAPI format → faker method mapping. Merged with defaults.
|
|
21
|
+
*/
|
|
22
|
+
formatMapping?: FormatMapping;
|
|
23
|
+
/** Include only these schemas (by name). Mutually exclusive with `exclude`. */
|
|
24
|
+
include?: readonly string[];
|
|
25
|
+
/** Exclude these schemas (by name). Mutually exclusive with `include`. */
|
|
26
|
+
exclude?: readonly string[];
|
|
27
|
+
/** Custom filter function for schemas. */
|
|
28
|
+
filter?: SchemaFilter;
|
|
29
|
+
/**
|
|
30
|
+
* Generate batch creator functions (e.g. `createMockUsers(count)`).
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
generateBatchCreators?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Default count for batch creators when caller omits the argument.
|
|
36
|
+
* @default 10
|
|
37
|
+
*/
|
|
38
|
+
defaultBatchCount?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Honor `minimum`/`maximum` and `minLength`/`maxLength` from the spec.
|
|
41
|
+
* Numeric methods receive `{ min, max }`; constrained strings switch to
|
|
42
|
+
* `string.alpha` with `{ length }`.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
respectConstraints?: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type Config = Plugin.Hooks & Plugin.Exports & {
|
|
48
|
+
name: "@ir-kit/openapi-ts-faker";
|
|
49
|
+
output: string;
|
|
50
|
+
fieldNameHints: FieldNameHints;
|
|
51
|
+
formatMapping: FormatMapping;
|
|
52
|
+
include?: readonly string[];
|
|
53
|
+
exclude?: readonly string[];
|
|
54
|
+
filter?: SchemaFilter;
|
|
55
|
+
generateBatchCreators: boolean;
|
|
56
|
+
defaultBatchCount: number;
|
|
57
|
+
respectConstraints: boolean;
|
|
58
|
+
};
|
|
59
|
+
export type FakerPlugin = DefinePlugin<UserConfig, Config>;
|
|
60
|
+
declare module "@hey-api/openapi-ts" {
|
|
61
|
+
interface PluginConfigMap {
|
|
62
|
+
"@ir-kit/openapi-ts-faker": FakerPlugin["Types"];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEhE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErE,YAAY,EACV,eAAe,EACf,cAAc,EACd,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,KAAK,OAAO,CAAC;AAEhE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,GACnC,MAAM,CAAC,WAAW,GAAG;IACnB,IAAI,EAAE,0BAA0B,CAAC;IACjC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,0EAA0E;IAC1E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEJ,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,GAC/B,MAAM,CAAC,OAAO,GAAG;IACf,IAAI,EAAE,0BAA0B,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEJ,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAE3D,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAiB,eAAe;QAC9B,0BAA0B,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;KAClD;CACF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a schema name to a factory function name
|
|
3
|
+
* @example "User" -> "createMockUser"
|
|
4
|
+
* @example "BlogPost" -> "createMockBlogPost"
|
|
5
|
+
*/
|
|
6
|
+
export declare const schemaToFactoryName: (schemaName: string) => string;
|
|
7
|
+
/**
|
|
8
|
+
* Convert a schema name to a batch factory function name
|
|
9
|
+
* @example "User" -> "createMockUsers"
|
|
10
|
+
* @example "Post" -> "createMockPosts"
|
|
11
|
+
*/
|
|
12
|
+
export declare const schemaToBatchFactoryName: (schemaName: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a schema should be included based on filters
|
|
15
|
+
*/
|
|
16
|
+
export declare const shouldIncludeSchema: (schemaName: string, include?: readonly string[], exclude?: readonly string[]) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Safely access nested faker methods
|
|
19
|
+
* @example "internet.email" -> "faker.internet.email()"
|
|
20
|
+
* @example "number.int" -> "faker.number.int()"
|
|
21
|
+
*/
|
|
22
|
+
export declare const getFakerMethodCall: (method: string, args?: Record<string, any>) => string;
|
|
23
|
+
/**
|
|
24
|
+
* Escape strings for JSDoc comments
|
|
25
|
+
*/
|
|
26
|
+
export declare const escapeJsDoc: (text: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Generate JSDoc comment for a factory function
|
|
29
|
+
*/
|
|
30
|
+
export declare const generateFactoryJsDoc: (schemaName: string, description?: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Generate JSDoc comment for a batch factory function
|
|
33
|
+
*/
|
|
34
|
+
export declare const generateBatchFactoryJsDoc: (schemaName: string, defaultCount: number) => string;
|
|
35
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,YAAY,MAAM,KAAG,MAExD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,YAAY,MAAM,KAAG,MAS7D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,EAClB,UAAU,SAAS,MAAM,EAAE,EAC3B,UAAU,SAAS,MAAM,EAAE,KAC1B,OAUF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,MAAM,EACd,OAAO,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KACzB,MAKF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MAE1C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,cAAc,MAAM,KACnB,MAgBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,MAAM,EAClB,cAAc,MAAM,KACnB,MAQF,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a schema name to a factory function name
|
|
3
|
+
* @example "User" -> "createMockUser"
|
|
4
|
+
* @example "BlogPost" -> "createMockBlogPost"
|
|
5
|
+
*/
|
|
6
|
+
export const schemaToFactoryName = (schemaName) => {
|
|
7
|
+
return `createMock${schemaName}`;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Convert a schema name to a batch factory function name
|
|
11
|
+
* @example "User" -> "createMockUsers"
|
|
12
|
+
* @example "Post" -> "createMockPosts"
|
|
13
|
+
*/
|
|
14
|
+
export const schemaToBatchFactoryName = (schemaName) => {
|
|
15
|
+
// Simple pluralization (handles most common cases)
|
|
16
|
+
const pluralized = schemaName.endsWith("s")
|
|
17
|
+
? schemaName
|
|
18
|
+
: schemaName.endsWith("y")
|
|
19
|
+
? `${schemaName.slice(0, -1)}ies`
|
|
20
|
+
: `${schemaName}s`;
|
|
21
|
+
return `createMock${pluralized}`;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Check if a schema should be included based on filters
|
|
25
|
+
*/
|
|
26
|
+
export const shouldIncludeSchema = (schemaName, include, exclude) => {
|
|
27
|
+
if (include && include.length > 0) {
|
|
28
|
+
return include.includes(schemaName);
|
|
29
|
+
}
|
|
30
|
+
if (exclude && exclude.length > 0) {
|
|
31
|
+
return !exclude.includes(schemaName);
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Safely access nested faker methods
|
|
37
|
+
* @example "internet.email" -> "faker.internet.email()"
|
|
38
|
+
* @example "number.int" -> "faker.number.int()"
|
|
39
|
+
*/
|
|
40
|
+
export const getFakerMethodCall = (method, args) => {
|
|
41
|
+
const hasArgs = args && Object.keys(args).length > 0;
|
|
42
|
+
const argsString = hasArgs ? JSON.stringify(args) : "";
|
|
43
|
+
return `faker.${method}(${argsString})`;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Escape strings for JSDoc comments
|
|
47
|
+
*/
|
|
48
|
+
export const escapeJsDoc = (text) => {
|
|
49
|
+
return text.replace(/\*\//g, "*\\/").replace(/\/\*/g, "/\\*");
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Generate JSDoc comment for a factory function
|
|
53
|
+
*/
|
|
54
|
+
export const generateFactoryJsDoc = (schemaName, description) => {
|
|
55
|
+
const lines = ["/**"];
|
|
56
|
+
if (description) {
|
|
57
|
+
lines.push(` * ${escapeJsDoc(description)}`);
|
|
58
|
+
lines.push(" *");
|
|
59
|
+
}
|
|
60
|
+
lines.push(` * Factory function to create mock ${schemaName} data`);
|
|
61
|
+
lines.push(" * @param overrides - Partial object to override generated values");
|
|
62
|
+
lines.push(` * @returns Mock ${schemaName} object`);
|
|
63
|
+
lines.push(" */");
|
|
64
|
+
return lines.join("\n");
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Generate JSDoc comment for a batch factory function
|
|
68
|
+
*/
|
|
69
|
+
export const generateBatchFactoryJsDoc = (schemaName, defaultCount) => {
|
|
70
|
+
return [
|
|
71
|
+
"/**",
|
|
72
|
+
` * Generate multiple mock ${schemaName} objects`,
|
|
73
|
+
` * @param count - Number of objects to generate (default: ${defaultCount})`,
|
|
74
|
+
` * @returns Array of mock ${schemaName} objects`,
|
|
75
|
+
" */",
|
|
76
|
+
].join("\n");
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=helpers.js.map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AI,CAAC,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ir-kit/openapi-ts-faker",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Faker.js plugin for @hey-api/openapi-ts - Generate realistic mock data factories from OpenAPI specs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"openapi",
|
|
7
|
+
"openapi-ts",
|
|
8
|
+
"faker",
|
|
9
|
+
"fakerjs",
|
|
10
|
+
"mock",
|
|
11
|
+
"mocking",
|
|
12
|
+
"testing",
|
|
13
|
+
"typescript",
|
|
14
|
+
"codegen",
|
|
15
|
+
"type-safe",
|
|
16
|
+
"plugin"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/openapi/plugins/faker",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/ir-kit/ir-kit/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Ahmed Rowaihi",
|
|
25
|
+
"email": "ahmedrowaihi@gmail.com"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/ir-kit/ir-kit.git",
|
|
30
|
+
"directory": "packages/openapi/plugins/faker"
|
|
31
|
+
},
|
|
32
|
+
"type": "module",
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./core": {
|
|
41
|
+
"types": "./dist/core/index.d.ts",
|
|
42
|
+
"import": "./dist/core/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE.md"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"provenance": true
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@faker-js/faker": "^10.0.0 || ^9.0.0 || ^8.0.0",
|
|
57
|
+
"@hey-api/codegen-core": ">=0.7.0",
|
|
58
|
+
"@hey-api/openapi-ts": ">=0.95.0",
|
|
59
|
+
"@hey-api/shared": ">=0.2.0",
|
|
60
|
+
"typescript": ">=5.0.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"typescript": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@faker-js/faker": "^10.4.0",
|
|
69
|
+
"@hey-api/codegen-core": "^0.8.1",
|
|
70
|
+
"@hey-api/openapi-ts": "^0.97.0",
|
|
71
|
+
"@hey-api/shared": "^0.4.2",
|
|
72
|
+
"@types/node": "^22",
|
|
73
|
+
"typescript": "5.9.3",
|
|
74
|
+
"@ir-kit/tsconfig": "0.0.0"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=20.19.0"
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "tsc",
|
|
81
|
+
"dev": "tsc --watch",
|
|
82
|
+
"typecheck": "tsc --noEmit"
|
|
83
|
+
}
|
|
84
|
+
}
|