klasik 1.0.17 → 1.0.19
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 +75 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -95,6 +95,9 @@ Generate a TypeScript client from an OpenAPI spec (remote URL or local file).
|
|
|
95
95
|
- `-u, --url <url>` - URL or file path to the OpenAPI spec (required)
|
|
96
96
|
- Supports: `https://...`, `http://...`, `file://...`, `/absolute/path`, `./relative/path`
|
|
97
97
|
- `-o, --output <dir>` - Output directory for generated client code (required)
|
|
98
|
+
- `-m, --mode <mode>` - Generation mode: `full` (models + APIs + config) or `models-only` (default: `full`)
|
|
99
|
+
- `full`: Generates complete axios client with APIs, models, and configuration
|
|
100
|
+
- `models-only`: Generates only model classes with class-transformer decorators (no API client code)
|
|
98
101
|
- `-H, --header <header...>` - Custom headers for HTTP requests (format: "Key: Value")
|
|
99
102
|
- Can be used multiple times for multiple headers
|
|
100
103
|
- Perfect for authorization: `--header "Authorization: Bearer token"`
|
|
@@ -417,6 +420,78 @@ await new K8sClientGenerator().generate({
|
|
|
417
420
|
});
|
|
418
421
|
```
|
|
419
422
|
|
|
423
|
+
## Best Practices for Existing Projects
|
|
424
|
+
|
|
425
|
+
When integrating klasik into an existing TypeScript project, follow these best practices to avoid conflicts:
|
|
426
|
+
|
|
427
|
+
### Generate into a Subdirectory
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# Generate models into src/generated to avoid overwriting project files
|
|
431
|
+
npx klasik generate \
|
|
432
|
+
--url https://api.example.com/openapi.yaml \
|
|
433
|
+
--output ./src/generated \
|
|
434
|
+
--mode models-only \
|
|
435
|
+
--resolve-refs
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Clean Up Generated Config Files
|
|
439
|
+
|
|
440
|
+
klasik generates `package.json` and `tsconfig.json` files. Remove them after generation:
|
|
441
|
+
|
|
442
|
+
```json
|
|
443
|
+
// package.json
|
|
444
|
+
{
|
|
445
|
+
"scripts": {
|
|
446
|
+
"generate-client": "npx klasik generate --url $API_URL --output ./src/generated --mode models-only --resolve-refs && npm run cleanup-generated",
|
|
447
|
+
"cleanup-generated": "rm -f ./src/generated/package.json ./src/generated/tsconfig*.json ./src/generated/.openapi-generator*"
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### TypeScript Configuration for class-transformer
|
|
453
|
+
|
|
454
|
+
Add these settings to your `tsconfig.json` for compatibility:
|
|
455
|
+
|
|
456
|
+
```json
|
|
457
|
+
{
|
|
458
|
+
"compilerOptions": {
|
|
459
|
+
"experimentalDecorators": true,
|
|
460
|
+
"emitDecoratorMetadata": true,
|
|
461
|
+
"skipLibCheck": true // Skip type checking in node_modules (recommended for class-transformer)
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### Models-Only Mode
|
|
467
|
+
|
|
468
|
+
Use `--mode models-only` when you:
|
|
469
|
+
- Only need data models with class-transformer decorators
|
|
470
|
+
- Want to use your own API client (axios, fetch, etc.)
|
|
471
|
+
- Are integrating into an existing project with its own HTTP layer
|
|
472
|
+
- Want to avoid package.json/tsconfig.json conflicts
|
|
473
|
+
|
|
474
|
+
```bash
|
|
475
|
+
npx klasik generate \
|
|
476
|
+
--url https://api.example.com/openapi.yaml \
|
|
477
|
+
--output ./src/generated \
|
|
478
|
+
--mode models-only # ✅ Generates only models, no API client
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### Full Mode
|
|
482
|
+
|
|
483
|
+
Use `--mode full` (default) when you:
|
|
484
|
+
- Want a complete ready-to-use axios client
|
|
485
|
+
- Are starting a new project from scratch
|
|
486
|
+
- Want automatic response transformation with class-transformer
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
npx klasik generate \
|
|
490
|
+
--url https://api.example.com/openapi.yaml \
|
|
491
|
+
--output ./api-client \
|
|
492
|
+
--mode full # Generates complete client with APIs
|
|
493
|
+
```
|
|
494
|
+
|
|
420
495
|
## Advanced Configuration
|
|
421
496
|
|
|
422
497
|
### Custom Error Handling
|
package/package.json
CHANGED