@ir-kit/k6-gen
v0.3.0
Published
Programmatic generator: OpenAPI spec → typed k6 client (one function per operation), TS types, and faker-backed data builders. No hey-api plugin required.
Maintainers
Readme
@ir-kit/k6-gen
Standalone programmatic generator: OpenAPI 3.x spec → typed k6 client + TS types + faker-backed data builders. Same shape as @ir-kit/openapi-swift, @ir-kit/openapi-go, @ir-kit/openapi-kotlin — pure generate({ spec, output }), no hey-api plugin runner required at the call site.
Use cases
- The @ir-kit/k6-tools CLI uses this internally for
k6-tools syncandk6-tools init. - Embedding in your own tooling (MCP servers, internal CLIs, custom generators).
- The @ir-kit/openapi-ts-k6 hey-api plugin wraps this when you prefer the
openapi-ts.config.tsworkflow.
Usage
import { generate } from "@ir-kit/k6-gen";
await generate({
input: "./openapi.yaml", // path | URL | parsed spec object
output: "./src/gen",
defaultBaseUrl: "https://api.example.com", // optional override
normalize: true, // safe normalize preset
});Emits four files under output:
| File | Contents |
| ------------ | ------------------------------------------------------------------------------ |
| types.ts | One export type <Name> per spec schema. Object schemas → type literals; enums → string-literal unions; refs → TypeReferenceNodes. |
| client.ts | One export function <opId>(...) per spec operation. Path/query/body/headers typed; returns the parsed JSON response (__parseJson<T>). Each call tags { operation: <opId> } and reads middleware headers from @ir-kit/k6/runtime. |
| data.ts | data.<TypeName>(overrides?) builders — @faker-js/faker underneath. Format-aware (uuid, email, date-time, …) and refs resolve to nested data.<X>() calls so cycles stay lazy. |
| index.ts | Re-exports the above (* from client, * as types from types, data). |
Shape
Internally:
@hey-api/json-schema-ref-parserbundles external refs.@ir-kit/openapi'snormalizeSpecruns (optional, on by default).@ir-kit/openapi-tools/parsereturns hey-api's normalized IR.- Operation + schema walkers emit
ts.factoryAST → printed withts.createPrinter.
That's it — no hey-api plugin runner is loaded, no $ DSL is touched.
See also
- @ir-kit/k6 — runtime framework consumed by the generated client
- @ir-kit/k6-tools — CLI built on top of this
