@puffinstudio/fizzyx 0.4.8 → 0.5.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/.fizzy.yaml CHANGED
@@ -21,3 +21,7 @@ oss:
21
21
  endpoint:
22
22
  region:
23
23
  bucket:
24
+ openapi:
25
+ - input: https://api.d.osuki.dev/docs/openapi.json
26
+ output: tests/api
27
+ client: wx
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fizzyx
2
2
 
3
- CLI tool for Fizzy board workflow and OSS/S3-compatible storage management.
3
+ CLI tool for Fizzy board workflow, OSS/S3-compatible storage, and OpenAPI client generation.
4
4
 
5
5
  ## Install
6
6
 
@@ -147,6 +147,111 @@ List exact pending files without uploading:
147
147
  fizzyx oss status --files
148
148
  ```
149
149
 
150
+ ## OpenAPI Commands
151
+
152
+ Generate a typed API client from an OpenAPI spec.
153
+
154
+ ### Generate
155
+
156
+ ```sh
157
+ fizzyx openapi generate -i <url|path> -o <dir> -c wx
158
+ ```
159
+
160
+ Options:
161
+
162
+ | Flag | Description |
163
+ | -------------------------- | ------------------------------------------------------- |
164
+ | `-i, --input <url\|path>` | OpenAPI spec URL or file path (JSON/YAML) |
165
+ | `-o, --output <dir\|file>` | Output directory (or `.ts` path for custom api name) |
166
+ | `-c, --client <name>` | Client target (`wx`) |
167
+ | `--api-name <name>` | API filename (default: `api.ts`) |
168
+ | `--types-name <name>` | Types filename (default: `types.ts`, `false` to inline) |
169
+ | `--runtime-name <name>` | Runtime filename (default: `wx-request.ts`) |
170
+ | `--run <script\|cmd>` | npm script or shell command after generation |
171
+
172
+ If `--input`/`--output`/`--client` are omitted, values from `.fizzy.yaml` `openapi[0]` are used.
173
+
174
+ Output is 3 files — runtime, types, and tree-shakeable endpoint functions:
175
+
176
+ ```
177
+ src/api/
178
+ ├── wx-request.ts # runtime (configure, setToken, onError, request)
179
+ ├── types.ts # named interfaces / enums / aliases
180
+ └── api.ts # tree-shakeable export functions + param types
181
+ ```
182
+
183
+ ### Generated Runtime API
184
+
185
+ ```ts
186
+ import { configure, setToken, onError, initToken } from "./api";
187
+
188
+ // Setup at app startup
189
+ configure({ baseUrl: "https://api.example.com", storageKey: "myapp_token" });
190
+
191
+ // Or with custom logger + hooks
192
+ configure({
193
+ baseUrl: "https://api.example.com",
194
+ storageKey: "tb_token",
195
+ logger: { error: myReporter, warn: () => {}, info: () => {}, debug: () => {} },
196
+ hooks: [
197
+ { onError: (ctx) => wx.showToast({ title: ctx.message }) },
198
+ { onSuccess: (ctx) => reportAnalytics(ctx) },
199
+ ],
200
+ });
201
+
202
+ // Token auto-loads from storage. Explicit load if needed:
203
+ await initToken();
204
+
205
+ // Token persists to storage on set
206
+ setToken("jwt...");
207
+ setToken(null); // logout, clears storage
208
+ ```
209
+
210
+ **Logger vs Hooks:**
211
+
212
+ - `Logger` controls **output** (console, file, sentry). Default: `console.error/warn/info/debug` with `[fizzyx]` prefix.
213
+ - `RequestHook` fires **business callbacks** at lifecycle points (`onRequest`, `onSuccess`, `onError`). Use for toast, analytics, loading state.
214
+
215
+ ### Generated Endpoint API
216
+
217
+ Each endpoint is a standalone export function with typed params:
218
+
219
+ ```ts
220
+ import { listPets, createPet, ListPetsQueryParams } from "./api";
221
+
222
+ // GET with query params
223
+ const pets = await listPets({ query: { limit: 10, status: "available" } });
224
+
225
+ // POST with body
226
+ const pet = await createPet({ name: "Fluffy" });
227
+
228
+ // POST without requestBody (no data param generated)
229
+ const result = await someAction();
230
+ ```
231
+
232
+ - No `createApi()` wrapper — tree-shakeable by default
233
+ - Each function exports its param types (`ListPetsQueryParams`, `CreatePetPathParams`)
234
+ - JSDoc comments from OpenAPI `description`/`summary` on endpoints and params
235
+
236
+ ### List Generators
237
+
238
+ ```sh
239
+ fizzyx openapi list
240
+ ```
241
+
242
+ ### Config (`.fizzy.yaml`)
243
+
244
+ ```yaml
245
+ openapi:
246
+ - input: ./openapi.json
247
+ output: ./src/api
248
+ client: wx
249
+ api_name: sdk.ts
250
+ types_name: types.ts
251
+ runtime_name: wx-request.ts
252
+ run: check
253
+ ```
254
+
150
255
  ## Config File (`.fizzy.yaml`)
151
256
 
152
257
  Minimal OSS-only config: