@ir-kit/openapi-typescript 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 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,74 @@
1
+ # @ir-kit/openapi-typescript
2
+
3
+ Thin programmatic wrapper around [`@hey-api/openapi-ts`](https://www.npmjs.com/package/@hey-api/openapi-ts) that exposes the same `generate()` shape as [`@ir-kit/openapi-{go,kotlin,swift}`](https://github.com/ir-kit/ir-kit). Lets the [`sdk-regen`](https://github.com/ir-kit/ir-kit/tree/main/actions/sdk-regen) GitHub Action drive a TypeScript SDK alongside the native ones — same workflow, same inputs, four targets.
4
+
5
+ Part of [ir-kit](https://github.com/ir-kit/ir-kit). **No new codegen** — the entire TypeScript pipeline (types, sdk, schemas, transformers, validators, query hooks, ...) is hey-api's; this package only normalises the calling convention and the result shape.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add -D @ir-kit/openapi-typescript @hey-api/openapi-ts
11
+ ```
12
+
13
+ `@hey-api/openapi-ts` is a peer dep so you can pin its version (and the plugins it ships) without depending on what we happen to bundle.
14
+
15
+ ## Usage
16
+
17
+ ```ts
18
+ import { generate } from "@ir-kit/openapi-typescript";
19
+
20
+ await generate({
21
+ input: "openapi.yaml",
22
+ output: "src/client",
23
+ });
24
+ ```
25
+
26
+ The default plugin set is `["@hey-api/client-fetch", "@hey-api/typescript", "@hey-api/sdk"]` — types + SDK functions + a `fetch`-based runtime adapter. Override `plugins` for any other shape:
27
+
28
+ ```ts
29
+ // types-only
30
+ await generate({ input, output, plugins: ["@hey-api/typescript"] });
31
+
32
+ // SDK + zod validators + tanstack-query hooks
33
+ await generate({
34
+ input,
35
+ output,
36
+ plugins: [
37
+ "@hey-api/client-fetch",
38
+ "@hey-api/typescript",
39
+ "@hey-api/sdk",
40
+ "@hey-api/schemas",
41
+ "zod",
42
+ "@tanstack/react-query",
43
+ ],
44
+ });
45
+ ```
46
+
47
+ Anything else hey-api's `UserConfig` accepts (custom client config, parser transforms, dryRun, etc.) goes into `heyApi:`:
48
+
49
+ ```ts
50
+ await generate({
51
+ input,
52
+ output,
53
+ heyApi: { dryRun: true, parser: { transforms: { enums: "javascript" } } },
54
+ });
55
+ ```
56
+
57
+ ## Result shape
58
+
59
+ ```ts
60
+ interface GenerateResult {
61
+ output: string; // absolute path
62
+ files: { path: string }[]; // relative paths under output
63
+ }
64
+ ```
65
+
66
+ Matches the result shape of `@ir-kit/openapi-go` / `-kotlin` / `-swift`, so downstream tooling (the [`sdk-regen`](https://github.com/ir-kit/ir-kit/tree/main/actions/sdk-regen) action, your own CI scripts) can iterate the four packages uniformly.
67
+
68
+ ## Why a wrapper
69
+
70
+ We don't ship our own TypeScript codegen — hey-api already does it well, and a competing TS gen would mean rebuilding their `ts-dsl` from scratch. But the `sdk-regen` action assumes a `generate({ input, output })` shape across all targets, and hey-api's `createClient(userConfig)` is shaped slightly differently and returns `Context[]` rather than `{ files, output }`. The wrapper closes that gap in ~30 lines of code.
71
+
72
+ ## Limitations
73
+
74
+ - **Result `files`** is collected by walking the output dir post-run. So if hey-api writes outside `output` (e.g. via custom plugin paths), those files won't be reported. The default plugins all write under `output`, so this is only a concern for advanced setups.
@@ -0,0 +1,50 @@
1
+ import { type UserConfig } from "@hey-api/openapi-ts";
2
+ import type { NormalizeOptions } from "@ir-kit/openapi-core";
3
+ export interface GenerateOptions {
4
+ /**
5
+ * Path or URL to the OpenAPI 3.x spec. Forwarded to hey-api which
6
+ * delegates to `@hey-api/json-schema-ref-parser` and accepts both
7
+ * shapes.
8
+ */
9
+ input: string;
10
+ /** Directory the SDK is written to (created if missing). */
11
+ output: string;
12
+ /**
13
+ * Override hey-api's plugin list. When omitted, defaults to
14
+ * `@hey-api/client-fetch` + `@hey-api/typescript` + `@hey-api/sdk`.
15
+ * Pass any combination of hey-api's first-party plugins (validators,
16
+ * Faker, TanStack Query, oRPC, etc.) or third-party plugin packages.
17
+ */
18
+ plugins?: UserConfig["plugins"];
19
+ /**
20
+ * Pass-through for any other hey-api `UserConfig` field —
21
+ * `parser.transforms`, `experimentalParser`, `dryRun`, custom client
22
+ * options, etc. Merged on top of the resolved config last, so it
23
+ * wins over the defaults set here.
24
+ */
25
+ heyApi?: Partial<UserConfig>;
26
+ /**
27
+ * Pre-codegen spec normalization. When enabled, the spec is bundled
28
+ * + normalized before being handed to hey-api as a parsed object,
29
+ * so all four targets share the same normalization logic.
30
+ */
31
+ normalize?: boolean | NormalizeOptions;
32
+ }
33
+ export interface BuiltFile {
34
+ /** Path relative to `output`. */
35
+ path: string;
36
+ }
37
+ export interface GenerateResult {
38
+ /** Absolute output directory. */
39
+ output: string;
40
+ /** Files written under `output`, relative paths. */
41
+ files: BuiltFile[];
42
+ }
43
+ /**
44
+ * Run hey-api's TypeScript codegen against `input`, writing the result
45
+ * to `output`. Thin wrapper around `createClient` that matches the
46
+ * `generate()` shape of `@ir-kit/openapi-{go,kotlin,swift}` so
47
+ * the same `sdk-regen` workflow drives all four targets uniformly.
48
+ */
49
+ export declare function generate(opts: GenerateOptions): Promise<GenerateResult>;
50
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAiB7D,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IAChC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7B;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;CACxC;AAED,MAAM,WAAW,SAAS;IACxB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,KAAK,EAAE,SAAS,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAc7E"}
@@ -0,0 +1,68 @@
1
+ import { readdir, stat } from "node:fs/promises";
2
+ import { join, relative, resolve } from "node:path";
3
+ import { createClient } from "@hey-api/openapi-ts";
4
+ import { loadSpec } from "@ir-kit/openapi-tools";
5
+ /**
6
+ * Default plugin set — emits a runnable client SDK ready to drop into a
7
+ * TypeScript project: types from schemas, the SDK functions, and the
8
+ * `fetch`-based runtime adapter. Consumers wanting alternative shapes
9
+ * (axios / ofetch / TanStack Query / zod / faker / etc.) override
10
+ * `plugins` with the hey-api plugin name they want; the rest of
11
+ * hey-api's plugin ecosystem all plugs in here unchanged.
12
+ */
13
+ const DEFAULT_PLUGINS = [
14
+ "@hey-api/client-fetch",
15
+ "@hey-api/typescript",
16
+ "@hey-api/sdk",
17
+ ];
18
+ /**
19
+ * Run hey-api's TypeScript codegen against `input`, writing the result
20
+ * to `output`. Thin wrapper around `createClient` that matches the
21
+ * `generate()` shape of `@ir-kit/openapi-{go,kotlin,swift}` so
22
+ * the same `sdk-regen` workflow drives all four targets uniformly.
23
+ */
24
+ export async function generate(opts) {
25
+ const out = resolve(process.cwd(), opts.output);
26
+ const input = opts.normalize
27
+ ? await loadSpec({ input: opts.input, normalize: opts.normalize })
28
+ : opts.input;
29
+ const config = {
30
+ input,
31
+ output: out,
32
+ plugins: (opts.plugins ?? DEFAULT_PLUGINS),
33
+ ...opts.heyApi,
34
+ };
35
+ await createClient(config);
36
+ const files = await collectFiles(out);
37
+ return { output: out, files };
38
+ }
39
+ /**
40
+ * Walk `dir` recursively and return every regular file under it as a
41
+ * relative path. Used to surface a `GenerateResult.files` array
42
+ * matching what our other generators return — hey-api's
43
+ * `createClient` resolves to `Context[]`, not a file list, so we read
44
+ * the result back from disk.
45
+ */
46
+ async function collectFiles(dir) {
47
+ const out = [];
48
+ await walk(dir, dir, out);
49
+ return out;
50
+ }
51
+ async function walk(base, current, out) {
52
+ let entries;
53
+ try {
54
+ entries = await readdir(current);
55
+ }
56
+ catch {
57
+ return;
58
+ }
59
+ for (const entry of entries) {
60
+ const full = join(current, entry);
61
+ const s = await stat(full);
62
+ if (s.isDirectory())
63
+ await walk(base, full, out);
64
+ else
65
+ out.push({ path: relative(base, full) });
66
+ }
67
+ }
68
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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GAAG,CAAC,CAAC;IAC1B,OAAO,GAAG,CAAC;AACb,CAAC;AAED,KAAK,UAAU,IAAI,CACjB,IAAY,EACZ,OAAe,EACf,GAAgB;IAEhB,IAAI,OAAiB,CAAC;IACtB,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAClC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,CAAC,WAAW,EAAE;YAAE,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;;YAC5C,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { BuiltFile, GenerateOptions, GenerateResult, } from "./generate.js";
2
+ export { generate } from "./generate.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,eAAe,EACf,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { generate } from "./generate.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@ir-kit/openapi-typescript",
3
+ "version": "0.1.0",
4
+ "description": "Thin programmatic wrapper around @hey-api/openapi-ts that ships a `generate()` matching the shape of @ir-kit/openapi-{go,kotlin,swift}, so the same sdk-regen workflow can target TypeScript clients (types + sdk + schemas + transformers + validators + ...) via hey-api's plugin pipeline.",
5
+ "keywords": [
6
+ "openapi",
7
+ "typescript",
8
+ "codegen",
9
+ "sdk",
10
+ "client",
11
+ "hey-api"
12
+ ],
13
+ "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/openapi/typescript",
14
+ "bugs": {
15
+ "url": "https://github.com/ir-kit/ir-kit/issues"
16
+ },
17
+ "license": "MIT",
18
+ "author": {
19
+ "name": "Ahmed Rowaihi",
20
+ "email": "ahmedrowaihi@gmail.com"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/ir-kit/ir-kit.git",
25
+ "directory": "packages/openapi/typescript"
26
+ },
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "README.md",
41
+ "LICENSE.md"
42
+ ],
43
+ "publishConfig": {
44
+ "access": "public",
45
+ "provenance": true
46
+ },
47
+ "peerDependencies": {
48
+ "@hey-api/openapi-ts": ">=0.97.0"
49
+ },
50
+ "dependencies": {
51
+ "@ir-kit/openapi-core": "0.1.0",
52
+ "@ir-kit/openapi-tools": "0.1.0"
53
+ },
54
+ "devDependencies": {
55
+ "@hey-api/openapi-ts": "^0.97.0",
56
+ "@types/node": "^22",
57
+ "vitest": "^4.0.0",
58
+ "@ir-kit/tsconfig": "0.0.0"
59
+ },
60
+ "engines": {
61
+ "node": ">=20.19.0"
62
+ },
63
+ "scripts": {
64
+ "build": "tsc -p tsconfig.build.json",
65
+ "dev": "tsc -p tsconfig.build.json --watch",
66
+ "typecheck": "tsc --noEmit",
67
+ "test": "vitest run --passWithNoTests"
68
+ }
69
+ }