@hyper-fetch/cli 9.8.1 → 9.9.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/README.md CHANGED
@@ -31,8 +31,8 @@
31
31
  ## 📖 About
32
32
 
33
33
  The HyperFetch CLI reads your OpenAPI 3.x schema and generates a complete, fully typed SDK built on `@hyper-fetch/core`.
34
- Every endpoint with an `operationId` becomes a typed request — params, payloads, query params, and response types are
35
- all extracted from the schema. The generated code is standard HyperFetch you can customize freely.
34
+ Every operation becomes a typed request — params, payloads, query params, and response types are all extracted from the
35
+ schema. The generated code is standard HyperFetch you can customize freely.
36
36
 
37
37
  ## 🎯 Key Capabilities
38
38
 
@@ -64,11 +64,14 @@ npx @hyper-fetch/cli generate --url https://api.example.com/openapi.json
64
64
  ### 3. Use the generated SDK
65
65
 
66
66
  ```ts
67
- import { sdk } from "./src/api/api-openapi.sdk";
67
+ import { createClient } from "@hyper-fetch/core";
68
+ import { createSdk } from "./src/api/api-openapi.sdk";
69
+
70
+ const sdk = createSdk(createClient({ url: "https://api.example.com" }));
68
71
 
69
72
  // Every endpoint is typed — params, payloads, and responses
70
- const { data } = await sdk.users.list.send();
71
- const { data: user } = await sdk.users.get.setParams({ userId: 1 }).send();
73
+ const { data } = await sdk.users.$get.send();
74
+ const { data: user } = await sdk.users.$userId.$get.send({ params: { userId: 1 } });
72
75
  ```
73
76
 
74
77
  ## 📋 Commands
@@ -119,7 +122,7 @@ The `init` command creates an `api.json` file at your project root. This is the
119
122
  "aliases": {
120
123
  "api": "@/api",
121
124
  "hooks": "@/hooks",
122
- "ui": "@/ui",
125
+ "ui": "@/components/ui",
123
126
  "components": "@/components",
124
127
  "lib": "@/lib"
125
128
  }
@@ -146,8 +149,9 @@ src/
146
149
  The generated file contains:
147
150
 
148
151
  1. **Schema types** — TypeScript interfaces for every schema component
149
- 2. **Typed requests** — One `createRequest` call per endpoint (with `operationId`)
150
- 3. **SDK tree** — Nested object mirroring your API paths: `sdk.users.get`, `sdk.posts.list`, etc.
152
+ 2. **Operation types** — `ResponseType`, `RequestBody`, `QueryParams`, `PathParams` and `ErrorType` for every operation
153
+ 3. **SDK schema** — An `SdkSchema` tree mirroring your API paths, with a `$`-prefixed key per HTTP method:
154
+ `sdk.users.$get`, `sdk.users.$userId.$put`, etc.
151
155
  4. **`createSdk` function** — Factory to create the SDK with your custom client
152
156
 
153
157
  ```ts
@@ -156,36 +160,48 @@ import { createSdk as coreCreateSdk } from "@hyper-fetch/core";
156
160
  import type { ClientInstance, RequestModel } from "@hyper-fetch/core";
157
161
 
158
162
  // Schema types extracted from your OpenAPI document
159
- export interface Components {
160
- schemas: {
161
- User: { id: number; name: string; email: string };
163
+ declare namespace Components {
164
+ namespace Schemas {
165
+ export interface User {
166
+ id: number;
167
+ name: string;
168
+ email: string;
169
+ }
162
170
  // ... all your schema types
163
- };
171
+ }
164
172
  }
165
173
 
166
- // Request model for each endpoint with operationId
174
+ export type GetUsersResponseType = Components.Schemas.User[];
175
+
176
+ // Request model for each operation, keyed by path and then by method
167
177
  export type SdkSchema = {
168
178
  users: {
169
- $get: RequestModel<{ response: Components["schemas"]["User"][]; endpoint: "/users" }>;
179
+ $get: RequestModel<{ response: GetUsersResponseType; endpoint: "/users" }>;
170
180
  };
171
181
  };
172
182
 
183
+ export type { Components };
184
+
173
185
  // SDK tree you import and use
174
- export const createSdk = <Client extends ClientInstance>(client: Client) =>
175
- coreCreateSdk<Client, SdkSchema>(client);
186
+ export const createSdk = <Client extends ClientInstance>(
187
+ client: Client,
188
+ options?: Parameters<typeof coreCreateSdk>[1] | undefined,
189
+ ) => {
190
+ return coreCreateSdk<Client, SdkSchema>(client, options);
191
+ };
176
192
  ```
177
193
 
178
194
  ## ⚠️ Important Notes
179
195
 
180
- - **`operationId` is required** — Only endpoints with an `operationId` in the schema are included. Endpoints without one
181
- are silently skipped.
196
+ - **`operationId` is optional** — Operations without one are included too. Their type names are derived from the method
197
+ and path, for example `GetUsers$userIdResponseType` for `GET /users/{userId}`.
182
198
  - **JSON schemas only for local files** — Local file paths must point to `.json` files. YAML is not supported for local
183
199
  files.
184
200
  - **Remote schemas are fetched with GET** — No auth headers are sent. If your schema requires authentication, download
185
201
  it locally first and pass the file path.
186
202
  - **Path params are converted** — `{userId}` in OpenAPI becomes `:userId` in HyperFetch endpoints.
187
203
  - **Path segments are camelCased** — Kebab-case path segments become camelCase keys in the SDK tree. `{param}` segments
188
- become `$param`.
204
+ become `$param` and each HTTP method becomes `$get`, `$post`, `$put`, `$patch` or `$delete`.
189
205
 
190
206
  ## 📚 Documentation
191
207
 
@@ -233,9 +249,9 @@ const client = createClient({ url: "https://api.example.com" });
233
249
  const sdk = createSdk(client);
234
250
 
235
251
  // Every method is fully typed — params, payloads, and responses
236
- const { data: users } = await sdk.users.list.send();
237
- const { data: user } = await sdk.users.get.setParams({ userId: 1 }).send();
238
- const { data: newUser } = await sdk.pets.create.send({
252
+ const { data: users } = await sdk.users.$get.send();
253
+ const { data: user } = await sdk.users.$userId.$get.setParams({ userId: 1 }).send();
254
+ const { data: newPet } = await sdk.pets.$post.send({
239
255
  payload: { name: "Buddy", species: "dog" },
240
256
  });
241
257
  ```
@@ -255,7 +271,7 @@ client.onAuth((request) => {
255
271
  });
256
272
 
257
273
  // All SDK requests now include the auth header automatically
258
- const { data } = await sdk.users.me.send();
274
+ const { data } = await sdk.users.me.$get.send();
259
275
  ```
260
276
 
261
277
  ### Programmatic usage (no CLI)
@@ -263,10 +279,24 @@ const { data } = await sdk.users.me.send();
263
279
  ```ts
264
280
  import { OpenapiRequestGenerator } from "@hyper-fetch/cli";
265
281
 
282
+ // The generator reads relative schema paths from `resolvedPaths.cwd` and writes to `resolvedPaths.api`
283
+ const config = {
284
+ tsx: true,
285
+ aliases: { api: "@/api", hooks: "@/hooks", ui: "@/components/ui", components: "@/components", lib: "@/lib" },
286
+ resolvedPaths: {
287
+ cwd: process.cwd(),
288
+ api: "./src/api",
289
+ hooks: "./src/hooks",
290
+ ui: "./src/components/ui",
291
+ components: "./src/components",
292
+ lib: "./src/lib",
293
+ },
294
+ };
295
+
266
296
  // Use the generator directly in scripts or build tools
267
- const schema = await OpenapiRequestGenerator.getSchemaFromUrl(url, config);
268
- const generator = new OpenapiRequestGenerator(schema, config);
269
- const output = await generator.generateFile(fileName);
297
+ const schema = await OpenapiRequestGenerator.getSchemaFromUrl({ url: "./openapi.json", config });
298
+ const generator = new OpenapiRequestGenerator(schema);
299
+ const filePath = await generator.generateFile({ fileName: "api.sdk.ts", config });
270
300
  ```
271
301
 
272
302
  ## Disclaimer
@@ -275,4 +305,4 @@ This package is inspired by [openapi-client-axios](https://www.npmjs.com/package
275
305
 
276
306
  ## License
277
307
 
278
- [MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
308
+ [Apache-2.0](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
package/dist/cli.js CHANGED
@@ -13490,7 +13490,7 @@ var init = new Command().name("Init").description("Initialize HyperFetch Client
13490
13490
  });
13491
13491
  var package_default = {
13492
13492
  name: "@hyper-fetch/cli",
13493
- version: "9.8.1",
13493
+ version: "9.9.0",
13494
13494
  description: "Hyper Fetch cli for code generation and utilities",
13495
13495
  author: "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
13496
13496
  homepage: "https://hyperfetch.bettertyped.com/",