@eqxjs/swagger-codegen 1.0.0-beta.1 โ†’ 1.0.0-beta.2

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/QUICKSTART.md CHANGED
@@ -1,118 +1,452 @@
1
1
  # Quick Start Guide
2
2
 
3
- ## Available Example Files
3
+ Get started with `@eqxjs/swagger-codegen` in minutes!
4
4
 
5
- ### Swagger 2.0 Examples
6
- - **`example-swagger.json`** (8.1KB) - Users & Posts API
7
- - **`example-swagger.yaml`** (5.8KB) - Users & Posts API
8
- - 5 DTOs, 2 Services, 2 Controllers, 2 Modules
5
+ ## ๐Ÿ“ฆ Installation
9
6
 
10
- ### OpenAPI 3.0 Examples
11
- - **`openapi3-example.json`** (14KB) - Products & Categories API
12
- - **`openapi3-example.yaml`** (10KB) - Products & Categories API
13
- - 6 DTOs, 2 Services, 2 Controllers, 2 Modules
7
+ ### Option 1: Global Installation
8
+ ```bash
9
+ npm install -g @eqxjs/swagger-codegen
10
+ ```
14
11
 
15
- ## Quick Commands
12
+ ### Option 2: Use with npx (No Installation)
13
+ ```bash
14
+ npx @eqxjs/swagger-codegen generate -i ./swagger.json -o ./generated
15
+ ```
16
16
 
17
+ ### Option 3: Development from Source
17
18
  ```bash
18
- # Install & Build
19
+ git clone <repository-url>
20
+ cd swagger-nestjs-codegen
19
21
  npm install
20
22
  npm run build
23
+ ```
21
24
 
22
- # Test a Single Format
23
- npm run dev -- generate -i ./example-swagger.json -o ./generated
25
+ ---
24
26
 
25
- # Test All Formats
26
- npm run test:all
27
+ ## ๐Ÿš€ Basic Usage
27
28
 
28
- # Clean Generated Files
29
- npm run clean
29
+ ### Generate Server Code (Default)
30
+ ```bash
31
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated
32
+ ```
33
+
34
+ ### Generate with Test Files
35
+ ```bash
36
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated --with-test
37
+ ```
38
+
39
+ ### Generate Client Code
40
+ ```bash
41
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated --mode client
42
+ ```
43
+
44
+ ### Generate Both Server & Client
45
+ ```bash
46
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated --mode both
30
47
  ```
31
48
 
32
- ## Generate Code
49
+ ---
50
+
51
+ ## ๐Ÿ“‹ Available Example Files
52
+
53
+ This repository includes example Swagger/OpenAPI files for testing:
33
54
 
34
- Choose any example file:
55
+ | File | Format | Spec | Description |
56
+ |------|--------|------|-------------|
57
+ | `example-swagger.json` | JSON | Swagger 2.0 | Users & Posts API (5 DTOs, 2 modules) |
58
+ | `example-swagger.yaml` | YAML | Swagger 2.0 | Same API, 28% smaller file |
59
+ | `openapi3-example.json` | JSON | OpenAPI 3.0 | Products & Categories API (6 DTOs, 2 modules) |
60
+ | `openapi3-example.yaml` | YAML | OpenAPI 3.0 | Same API, 29% smaller file |
61
+
62
+ ### Try the Examples
35
63
 
36
64
  ```bash
37
- # Swagger 2.0 - JSON
38
- npm run dev -- generate -i ./example-swagger.json -o ./output
65
+ # Swagger 2.0 - JSON format
66
+ eqxjs-swagger-codegen generate -i ./example-swagger.json -o ./output
39
67
 
40
- # Swagger 2.0 - YAML (28% smaller than JSON)
41
- npm run dev -- generate -i ./example-swagger.yaml -o ./output
68
+ # Swagger 2.0 - YAML format
69
+ eqxjs-swagger-codegen generate -i ./example-swagger.yaml -o ./output
42
70
 
43
- # OpenAPI 3.0 - JSON
44
- npm run dev -- generate -i ./openapi3-example.json -o ./output
71
+ # OpenAPI 3.0 - JSON format
72
+ eqxjs-swagger-codegen generate -i ./openapi3-example.json -o ./output
45
73
 
46
- # OpenAPI 3.0 - YAML (29% smaller than JSON)
47
- npm run dev -- generate -i ./openapi3-example.yaml -o ./output
74
+ # OpenAPI 3.0 - YAML format
75
+ eqxjs-swagger-codegen generate -i ./openapi3-example.yaml -o ./output
48
76
  ```
49
77
 
50
- ## Generated Structure
78
+ ### Development Mode Commands
79
+
80
+ If you're developing the tool itself:
81
+
82
+ ```bash
83
+ # Install dependencies
84
+ npm install
85
+
86
+ # Test with an example
87
+ npm run dev -- generate -i ./example-swagger.json -o ./generated
88
+
89
+ # Test all formats at once
90
+ npm run test:all
51
91
 
92
+ # Clean generated files
93
+ npm run clean
52
94
  ```
53
- output/
95
+
96
+ ---
97
+
98
+ ---
99
+
100
+ ## ๐Ÿ“ Generated Structure
101
+
102
+ ### Without Tests (Default)
103
+ ```
104
+ generated/
105
+ โ”œโ”€โ”€ dtos/
106
+ โ”‚ โ”œโ”€โ”€ user.dto.ts # Data Transfer Objects with validation
107
+ โ”‚ โ”œโ”€โ”€ post.dto.ts
108
+ โ”‚ โ””โ”€โ”€ product.dto.ts
109
+ โ”œโ”€โ”€ users/
110
+ โ”‚ โ”œโ”€โ”€ users.service.ts # Injectable service with business logic
111
+ โ”‚ โ”œโ”€โ”€ users.controller.ts # REST API endpoints
112
+ โ”‚ โ””โ”€โ”€ users.module.ts # Feature module
113
+ โ”œโ”€โ”€ posts/
114
+ โ”‚ โ”œโ”€โ”€ posts.service.ts
115
+ โ”‚ โ”œโ”€โ”€ posts.controller.ts
116
+ โ”‚ โ””โ”€โ”€ posts.module.ts
117
+ โ”œโ”€โ”€ app.module.ts # Root application module (auto-updated)
118
+ โ””โ”€โ”€ index.ts # Barrel exports
119
+ ```
120
+
121
+ ### With Tests (`--with-test` flag)
122
+ ```
123
+ generated/
54
124
  โ”œโ”€โ”€ dtos/
55
- โ”‚ โ”œโ”€โ”€ *.dto.ts # DTOs with @ApiProperty
56
- โ”œโ”€โ”€ products/
57
- โ”‚ โ”œโ”€โ”€ products.service.ts # Injectable service
58
- โ”‚ โ”œโ”€โ”€ products.controller.ts # Controller with routes
59
- โ”‚ โ””โ”€โ”€ products.module.ts # Feature module
60
- โ”œโ”€โ”€ categories/
61
- โ”‚ โ”œโ”€โ”€ categories.service.ts
62
- โ”‚ โ”œโ”€โ”€ categories.controller.ts
63
- โ”‚ โ””โ”€โ”€ categories.module.ts
64
- โ”œโ”€โ”€ app.module.ts # Root module
65
- โ””โ”€โ”€ index.ts # Barrel exports
125
+ โ”‚ โ”œโ”€โ”€ user.dto.ts
126
+ โ”‚ โ””โ”€โ”€ post.dto.ts
127
+ โ”œโ”€โ”€ users/
128
+ โ”‚ โ”œโ”€โ”€ users.service.ts
129
+ โ”‚ โ”œโ”€โ”€ users.controller.ts
130
+ โ”‚ โ””โ”€โ”€ users.module.ts
131
+ โ”œโ”€โ”€ tests/ # Separate test directory
132
+ โ”‚ โ”œโ”€โ”€ dtos/
133
+ โ”‚ โ”‚ โ”œโ”€โ”€ user.dto.spec.ts # DTO validation tests
134
+ โ”‚ โ”‚ โ””โ”€โ”€ post.dto.spec.ts
135
+ โ”‚ โ””โ”€โ”€ users/
136
+ โ”‚ โ”œโ”€โ”€ users.service.spec.ts # Service unit tests
137
+ โ”‚ โ””โ”€โ”€ users.controller.spec.ts # Controller tests with mocks
138
+ โ”œโ”€โ”€ app.module.ts
139
+ โ””โ”€โ”€ index.ts
66
140
  ```
67
141
 
68
- **Structure:** Each resource (tag) has its service, controller, and module grouped together in the same folder.
142
+ **Key Points:**
143
+ - Each resource (Swagger tag) gets its own folder with service, controller, and module
144
+ - All DTOs are grouped in the `dtos/` folder
145
+ - Tests mirror the source structure in a separate `tests/` directory
146
+ - `app.module.ts` is automatically updated with all generated modules
147
+
148
+ ---
69
149
 
70
- ## Example Output
150
+ ## ๐Ÿ“ Example Output
71
151
 
72
- ### DTO
152
+ ### DTO with Validation
73
153
  ```typescript
74
154
  import { ApiProperty } from '@nestjs/swagger';
75
155
 
76
- export class Product {
77
- @ApiProperty({ description: 'Product ID', type: String })
78
- id: string;
156
+ export class CreateUserDto {
157
+ @ApiProperty({ description: 'User email address', type: String })
158
+ email: string;
79
159
 
80
- @ApiProperty({ description: 'Product name', type: String })
160
+ @ApiProperty({ description: 'User full name', type: String })
81
161
  name: string;
162
+
163
+ @ApiProperty({ description: 'User age', type: Number, required: false })
164
+ age?: number;
165
+ }
166
+ ```
167
+
168
+ ### Service
169
+ ```typescript
170
+ import { Injectable } from '@nestjs/common';
171
+ import { CreateUserDto } from '../dtos/create-user.dto';
172
+ import { User } from '../dtos/user.dto';
173
+
174
+ @Injectable()
175
+ export class UsersService {
176
+ async createUser(createUserDto: CreateUserDto): Promise<User> {
177
+ // Implementation here
178
+ throw new Error('Not implemented');
179
+ }
180
+
181
+ async getUser(id: string): Promise<User> {
182
+ // Implementation here
183
+ throw new Error('Not implemented');
184
+ }
82
185
  }
83
186
  ```
84
187
 
85
188
  ### Controller
86
189
  ```typescript
87
- @ApiTags('products')
88
- @Controller('products')
89
- export class ProductsController {
90
- @ApiOperation({ summary: 'List products' })
91
- @Get('')
92
- async listProducts(): Promise<Product[]> {
93
- return this.productsService.listProducts();
190
+ import { Controller, Get, Post, Body, Param } from '@nestjs/common';
191
+ import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
192
+ import { UsersService } from './users.service';
193
+ import { CreateUserDto } from '../dtos/create-user.dto';
194
+ import { User } from '../dtos/user.dto';
195
+
196
+ @ApiTags('users')
197
+ @Controller('users')
198
+ export class UsersController {
199
+ constructor(private readonly usersService: UsersService) {}
200
+
201
+ @ApiOperation({ summary: 'Create a new user' })
202
+ @ApiResponse({ status: 201, description: 'User created', type: User })
203
+ @Post()
204
+ async createUser(@Body() createUserDto: CreateUserDto): Promise<User> {
205
+ return this.usersService.createUser(createUserDto);
206
+ }
207
+
208
+ @ApiOperation({ summary: 'Get user by ID' })
209
+ @ApiResponse({ status: 200, description: 'User found', type: User })
210
+ @Get(':id')
211
+ async getUser(@Param('id') id: string): Promise<User> {
212
+ return this.usersService.getUser(id);
94
213
  }
95
214
  }
96
215
  ```
97
216
 
98
- ## Documentation
217
+ ### Generated Test (with `--with-test`)
218
+ ```typescript
219
+ import { Test, TestingModule } from '@nestjs/testing';
220
+ import { UsersController } from '../../users/users.controller';
221
+ import { UsersService } from '../../users/users.service';
222
+
223
+ describe('UsersController', () => {
224
+ let controller: UsersController;
225
+ let service: UsersService;
226
+
227
+ beforeEach(async () => {
228
+ const module: TestingModule = await Test.createTestingModule({
229
+ controllers: [UsersController],
230
+ providers: [
231
+ {
232
+ provide: UsersService,
233
+ useValue: {
234
+ createUser: jest.fn(),
235
+ getUser: jest.fn(),
236
+ },
237
+ },
238
+ ],
239
+ }).compile();
240
+
241
+ controller = module.get<UsersController>(UsersController);
242
+ service = module.get<UsersService>(UsersService);
243
+ });
244
+
245
+ it('should be defined', () => {
246
+ expect(controller).toBeDefined();
247
+ });
248
+ });
249
+ ```
250
+
251
+ ---
252
+
253
+ ## โš™๏ธ Command Options
254
+
255
+ ```bash
256
+ eqxjs-swagger-codegen generate [options]
257
+
258
+ Options:
259
+ -i, --input <path> Path to Swagger/OpenAPI file (JSON or YAML) [required]
260
+ -o, --output <path> Output directory for generated files (default: "./generated")
261
+ -m, --mode <mode> Generation mode: server, client, or both (default: "server")
262
+ --with-test Generate test files (.spec.ts) for all generated code
263
+ --with-validate Add class-validator decorators to DTOs
264
+ --only-dtos Generate only DTOs (skip services, controllers, modules)
265
+ -h, --help Display help for command
266
+ ```
267
+
268
+ ### Examples
269
+
270
+ ```bash
271
+ # Basic server generation
272
+ eqxjs-swagger-codegen generate -i ./api.json -o ./src/generated
273
+
274
+ # Client SDK generation
275
+ eqxjs-swagger-codegen generate -i ./api.json -o ./client --mode client
276
+
277
+ # Both server and client
278
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --mode both
279
+
280
+ # With comprehensive test suite
281
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --with-test
282
+
283
+ # With validation decorators
284
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --with-validate
285
+
286
+ # Only DTOs with validators (no services/controllers)
287
+ eqxjs-swagger-codegen generate -i ./api.json -o ./dtos --only-dtos --with-validate
288
+
289
+ # Complete setup: server + tests + validators
290
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --with-test --with-validate
291
+
292
+ # Using npx (no installation)
293
+ npx @eqxjs/swagger-codegen generate -i ./api.yaml -o ./generated --with-validate
294
+ ```
295
+
296
+ ---
297
+
298
+ ---
299
+
300
+ ## โœจ Key Features
301
+
302
+ | Feature | Description |
303
+ |---------|-------------|
304
+ | ๐Ÿ”„ **Multiple Specs** | Supports Swagger 2.0 & OpenAPI 3.0 |
305
+ | ๐Ÿ“„ **Multiple Formats** | Accepts both JSON & YAML files |
306
+ | ๐ŸŽฏ **Type Safety** | Generates fully typed TypeScript code |
307
+ | ๐Ÿ—๏ธ **Complete Modules** | Creates services, controllers, and modules |
308
+ | ๐Ÿ“š **Swagger Decorators** | Includes @ApiTags, @ApiOperation, @ApiResponse, etc. |
309
+ | ๐Ÿ”— **Schema References** | Handles $ref, allOf, oneOf, anyOf compositions |
310
+ | ๐Ÿงช **Test Generation** | Creates comprehensive test suites with `--with-test` |
311
+ | โœ… **Validation** | Adds class-validator decorators with `--with-validate` |
312
+ | ๐Ÿ“ฆ **Flexible Output** | Generate server, client, both, or DTOs only |
313
+ | ๐Ÿ”Œ **Three Modes** | Generate server, client, or both |
314
+ | ๐Ÿ”ง **Auto Module Import** | Updates app.module.ts automatically |
315
+ | ๐Ÿšซ **No Self-Imports** | Prevents circular dependency issues in DTOs |
316
+
317
+ ---
318
+
319
+ ## ๐ŸŽฏ Generation Modes
320
+
321
+ ### Server Mode (Default)
322
+ Generates NestJS backend code:
323
+ - Controllers with REST endpoints
324
+ - Injectable services
325
+ - Feature modules
326
+ - DTOs with Swagger decorators
327
+
328
+ ```bash
329
+ eqxjs-swagger-codegen generate -i ./api.json -o ./server
330
+ ```
331
+
332
+ ### Client Mode
333
+ Generates TypeScript client SDK:
334
+ - Axios-based HTTP client
335
+ - Typed request/response interfaces
336
+ - All API methods ready to use
337
+
338
+ ```bash
339
+ eqxjs-swagger-codegen generate -i ./api.json -o ./client --mode client
340
+ ```
341
+
342
+ ### Both Mode
343
+ Generates both server and client code in the same output directory:
344
+
345
+ ```bash
346
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --mode both
347
+ ```
348
+
349
+ ---
350
+
351
+ ## ๐Ÿ“š Documentation
352
+
353
+ | Document | Description |
354
+ |----------|-------------|
355
+ | [README.md](README.md) | Complete documentation and usage guide |
356
+ | [FORMATS.md](FORMATS.md) | JSON vs YAML format comparison |
357
+ | [OPENAPI-COMPARISON.md](OPENAPI-COMPARISON.md) | Swagger 2.0 vs OpenAPI 3.0 differences |
358
+ | [ARCHITECTURE.md](ARCHITECTURE.md) | System architecture and design decisions |
359
+ | [SUMMARY.md](SUMMARY.md) | Project overview and summary |
360
+
361
+ ---
362
+
363
+ ## ๐Ÿ†˜ Common Use Cases
364
+
365
+ ### Use Case 1: Generate Backend from Existing API Spec
366
+ ```bash
367
+ # You have an API specification and want to generate NestJS backend
368
+ eqxjs-swagger-codegen generate -i ./my-api.yaml -o ./src/generated
369
+ ```
370
+
371
+ ### Use Case 2: Generate Client SDK for Frontend
372
+ ```bash
373
+ # Generate TypeScript client for your React/Angular/Vue app
374
+ eqxjs-swagger-codegen generate -i ./api.json -o ./src/api-client --mode client
375
+ ```
376
+
377
+ ### Use Case 3: Full-Stack with Tests
378
+ ```bash
379
+ # Generate both server and client with complete test coverage
380
+ eqxjs-swagger-codegen generate -i ./api.json -o ./generated --mode both --with-test
381
+ ```
382
+
383
+ ### Use Case 4: Quick Prototyping with Validation
384
+ ```bash
385
+ # Generate DTOs with built-in validation for rapid API development
386
+ npx @eqxjs/swagger-codegen generate -i ./prototype-api.yaml -o ./src --with-validate
387
+ ```
388
+
389
+ ### Use Case 5: Shared Type Library
390
+ ```bash
391
+ # Generate only DTOs for a shared package across microservices
392
+ eqxjs-swagger-codegen generate -i ./api-contract.json -o ./packages/types --only-dtos
393
+ ```
394
+
395
+ ---
396
+
397
+ ## ๐Ÿ’ก Tips
398
+
399
+ - **Use YAML files** - They're 28-29% smaller than JSON and easier to read
400
+ - **Enable test generation** - Add `--with-test` for instant test coverage
401
+ - **Add validators** - Use `--with-validate` for automatic DTO validation with class-validator
402
+ - **DTOs only mode** - Use `--only-dtos` when you only need type definitions
403
+ - **Check app.module.ts** - It's automatically updated with all generated modules
404
+ - **Review generated code** - Services have placeholder implementations to fill in
405
+ - **Run type checking** - Use `tsc --noEmit` to verify generated code compiles
406
+ - **Install dependencies** - Generated tests require `@nestjs/testing` and `jest`
407
+ - **Install validators** - `--with-validate` requires `class-validator` and `class-transformer`
408
+
409
+ ---
410
+
411
+ ## ๐Ÿš€ Next Steps
412
+
413
+ 1. **Install the package**
414
+ ```bash
415
+ npm install -g @eqxjs/swagger-codegen
416
+ ```
417
+
418
+ 2. **Generate code from your Swagger/OpenAPI file**
419
+ ```bash
420
+ eqxjs-swagger-codegen generate -i ./your-api.yaml -o ./generated --with-test
421
+ ```
422
+
423
+ 3. **Review the generated code**
424
+ - Check DTOs in `generated/dtos/`
425
+ - Review controllers and services
426
+ - See `generated/app.module.ts` for module imports
427
+
428
+ 4. **Implement business logic**
429
+ - Fill in service method implementations
430
+ - Add database integration
431
+ - Implement error handling
432
+
433
+ 5. **Run tests**
434
+ ```bash
435
+ npm test
436
+ ```
437
+
438
+ 6. **Read the full documentation**
439
+ - See [README.md](README.md) for advanced features
440
+ - Check [ARCHITECTURE.md](ARCHITECTURE.md) for design details
99
441
 
100
- - **[README.md](README.md)** - Main documentation
101
- - **[FORMATS.md](FORMATS.md)** - JSON vs YAML comparison
102
- - **[OPENAPI-COMPARISON.md](OPENAPI-COMPARISON.md)** - Swagger 2.0 vs OpenAPI 3.0
103
- - **[ARCHITECTURE.md](ARCHITECTURE.md)** - System architecture
104
- - **[SUMMARY.md](SUMMARY.md)** - Project overview
442
+ ---
105
443
 
106
- ## Key Features
444
+ ## ๐Ÿ“ž Need Help?
107
445
 
108
- โœ… Supports Swagger 2.0 & OpenAPI 3.0
109
- โœ… Accepts JSON & YAML formats
110
- โœ… Generates type-safe TypeScript code
111
- โœ… Creates complete NestJS modules
112
- โœ… Includes Swagger decorators
113
- โœ… Handles complex schemas & references
114
- โœ… Supports path, query, and body parameters
446
+ - **Documentation**: [README.md](README.md)
447
+ - **Issues**: Check the repository issues page
448
+ - **Examples**: See the included example files in this repository
115
449
 
116
- ## Need Help?
450
+ ---
117
451
 
118
- See the full documentation in [README.md](README.md) for detailed usage instructions and examples.
452
+ **Happy Coding! ๐ŸŽ‰**
package/README.md CHANGED
@@ -31,7 +31,17 @@ A TypeScript CLI tool to generate NestJS modules, controllers, services, and DTO
31
31
 
32
32
  ## Installation
33
33
 
34
+ ### From NPM
35
+
36
+ ```bash
37
+ npm install -g @eqxjs/swagger-codegen
38
+ ```
39
+
40
+ ### From Source
41
+
34
42
  ```bash
43
+ git clone <repository-url>
44
+ cd swagger-nestjs-codegen
35
45
  npm install
36
46
  npm run build
37
47
  ```
@@ -74,28 +84,138 @@ npm run dev -- generate -i ./openapi3-example.yaml -o ./generated
74
84
  ### Production Mode
75
85
 
76
86
  ```bash
77
- # Build the project first
78
- npm run build
87
+ # Using the global CLI
88
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated
79
89
 
80
- # Run the CLI with JSON
81
- node dist/cli.js generate -i ./swagger.json -o ./generated
90
+ # Using npx (no installation required)
91
+ npx @eqxjs/swagger-codegen generate -i ./swagger.json -o ./generated
82
92
 
83
- # Run the CLI with YAML
84
- node dist/cli.js generate -i ./swagger.yaml -o ./generated
93
+ # With YAML files
94
+ eqxjs-swagger-codegen generate -i ./swagger.yaml -o ./generated
85
95
 
86
- # Or use the npm script
87
- npm start -- generate -i ./swagger.json -o ./generated
96
+ # Local installation
97
+ node dist/cli.js generate -i ./swagger.json -o ./generated
88
98
  ```
89
99
 
90
100
  ### Command Options
91
101
 
92
102
  ```bash
93
- swagger-nestjs-codegen generate [options]
103
+ eqxjs-swagger-codegen generate [options]
94
104
 
95
105
  Options:
96
- -i, --input <path> Path to Swagger/OpenAPI file (JSON or YAML) [required]
97
- -o, --output <path> Output directory for generated files (default: "./generated")
98
- -h, --help Display help for command
106
+ -i, --input <path> Path to Swagger/OpenAPI file (JSON or YAML) [required]
107
+ -o, --output <path> Output directory for generated files (default: "./generated")
108
+ -m, --mode <mode> Generation mode: server, client, or both (default: "server")
109
+ --with-test Generate test files (.spec.ts) for all generated files
110
+ --with-validate Add class-validator decorators to DTOs for validation
111
+ --only-dtos Generate only DTOs (skip services, controllers, modules)
112
+ -h, --help Display help for command
113
+ ```
114
+
115
+ ### Generating with Test Files
116
+
117
+ Use the `--with-test` flag to automatically generate test files for all controllers, services, and DTOs:
118
+
119
+ ```bash
120
+ # Generate with test files
121
+ eqxjs-swagger-codegen generate -i ./example-swagger.json -o ./generated --with-test
122
+
123
+ # Using npx
124
+ npx @eqxjs/swagger-codegen generate -i ./swagger.json -o ./generated --with-test
125
+
126
+ # Development mode
127
+ npm run dev -- generate -i ./example-swagger.json -o ./generated --with-test
128
+ ```
129
+
130
+ ### Generating with Validation Decorators
131
+
132
+ Use the `--with-validate` flag to add class-validator decorators to all DTO properties:
133
+
134
+ ```bash
135
+ # Generate DTOs with validation decorators
136
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated --with-validate
137
+
138
+ # Combine with test generation
139
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./generated --with-validate --with-test
140
+ ```
141
+
142
+ **Generated validators include:**
143
+ - `@IsString()`, `@IsNumber()`, `@IsInt()`, `@IsBoolean()`, `@IsDate()` for basic types
144
+ - `@IsEmail()` for email format
145
+ - `@IsUUID()` for UUID format
146
+ - `@IsUrl()` for URL format
147
+ - `@IsEnum()` for enum values
148
+ - `@IsArray()` with `@IsString({ each: true })` for arrays
149
+ - `@ValidateNested()` with `@Type()` for nested objects
150
+ - `@Min()`, `@Max()` for number constraints
151
+ - `@MinLength()`, `@MaxLength()` for string length
152
+ - `@Matches()` for regex patterns
153
+
154
+ **Example output:**
155
+ ```typescript
156
+ import { ApiProperty } from '@nestjs/swagger';
157
+ import { IsString, IsEmail, IsInt, Min } from 'class-validator';
158
+
159
+ export class CreateUserDto {
160
+ @IsString()
161
+ @IsEmail()
162
+ @ApiProperty({ description: 'User email', type: String })
163
+ email!: string;
164
+
165
+ @IsInt()
166
+ @Min(18)
167
+ @ApiProperty({ description: 'User age', type: Number })
168
+ age!: number;
169
+ }
170
+ ```
171
+
172
+ ### Generating Only DTOs
173
+
174
+ Use the `--only-dtos` flag to generate only Data Transfer Objects without services, controllers, or modules:
175
+
176
+ ```bash
177
+ # Generate only DTOs
178
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./dtos --only-dtos
179
+
180
+ # DTOs with validators
181
+ eqxjs-swagger-codegen generate -i ./swagger.json -o ./dtos --only-dtos --with-validate
182
+ ```
183
+
184
+ This is useful when you:
185
+ - Only need the data models for a separate project
186
+ - Want to share DTOs between multiple services
187
+ - Are building a monorepo and need consistent type definitions
188
+ - Want to generate TypeScript interfaces from your API spec
189
+
190
+ This will create test files alongside their corresponding source files:
191
+ - **Controller specs**: Test files with mocked services and test cases for each endpoint
192
+ - **Service specs**: Test files with basic setup and method existence checks
193
+ - **DTO specs**: Test files with class-validator integration for validating DTOs
194
+
195
+ **Example output:**
196
+ ```
197
+ generated/
198
+ โ”œโ”€โ”€ dtos/
199
+ โ”‚ โ”œโ”€โ”€ user.dto.ts
200
+ โ”‚ โ””โ”€โ”€ post.dto.ts
201
+ โ”œโ”€โ”€ users/
202
+ โ”‚ โ”œโ”€โ”€ users.service.ts
203
+ โ”‚ โ”œโ”€โ”€ users.controller.ts
204
+ โ”‚ โ””โ”€โ”€ users.module.ts
205
+ โ”œโ”€โ”€ posts/
206
+ โ”‚ โ”œโ”€โ”€ posts.service.ts
207
+ โ”‚ โ”œโ”€โ”€ posts.controller.ts
208
+ โ”‚ โ””โ”€โ”€ posts.module.ts
209
+ โ””โ”€โ”€ tests/ # ๐Ÿงช Test files with same structure
210
+ โ”œโ”€โ”€ dtos/
211
+ โ”‚ โ”œโ”€โ”€ user.dto.spec.ts
212
+ โ”‚ โ””โ”€โ”€ post.dto.spec.ts
213
+ โ”œโ”€โ”€ users/
214
+ โ”‚ โ”œโ”€โ”€ users.controller.spec.ts
215
+ โ”‚ โ””โ”€โ”€ users.service.spec.ts
216
+ โ””โ”€โ”€ posts/
217
+ โ”œโ”€โ”€ posts.controller.spec.ts
218
+ โ””โ”€โ”€ posts.service.spec.ts
99
219
  ```
100
220
 
101
221
  ## Generated File Structure