nest-scramble 1.8.2 β 1.8.3
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
|
@@ -1,749 +1,765 @@
|
|
|
1
|
-
# Nest-Scramble
|
|
2
|
-
|
|
3
|
-
> Zero-config API Documentation & Postman Generator for NestJS using static analysis
|
|
4
|
-
|
|
5
|
-
[](https://badge.fury.io/js/nest-scramble)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
|
-
[](https://github.com/Eng-MMustafa/nest-scramble)
|
|
8
|
-
[](https://github.com/Eng-MMustafa)
|
|
9
|
-
|
|
10
|
-
## π Why Nest-Scramble?
|
|
11
|
-
|
|
12
|
-
As a NestJS developer, I was tired of drowning in `@ApiProperty` decorators just to get basic API documentation. I longed for a zero-config solution where docs just worked without polluting my code. **Nest-Scramble changes that** by using static TypeScript analysis to automatically generate:
|
|
13
|
-
|
|
14
|
-
- β
**OpenAPI 3.0 specifications** from your DTOs
|
|
15
|
-
- β
**Interactive Scalar UI documentation** with zero configuration
|
|
16
|
-
- β
**Postman collections** with smart mock data
|
|
17
|
-
- β
**Live mocking** for rapid prototyping
|
|
18
|
-
|
|
19
|
-
**Zero configuration. Zero decorators. Just pure TypeScript.**
|
|
20
|
-
|
|
21
|
-
## π The Story Behind Nest-Scramble
|
|
22
|
-
|
|
23
|
-
It all started with a vision: API documentation should be effortless. As a developer passionate about clean code and developer experience, I knew there had to be a better way than manual decorators and runtime reflection.
|
|
24
|
-
|
|
25
|
-
When I switched to NestJS for its powerful architecture and TypeScript-first approach, I was disappointed by the lack of zero-config documentation tools. Hours wasted on `@ApiProperty({ type: String })` instead of building features.
|
|
26
|
-
|
|
27
|
-
I knew there had to be a better way. Leveraging my expertise in static analysis and Abstract Syntax Trees (AST), I built Nest-Scramble to bring that same developer experience to the Node.js ecosystem. It's not just a toolβit's my mission to make API documentation as effortless as it should be.
|
|
28
|
-
|
|
29
|
-
## π Features Gallery
|
|
30
|
-
|
|
31
|
-
| Feature | Nest-Scramble | Swagger (@nestjs/swagger) |
|
|
32
|
-
|---------|---------------|---------------------------|
|
|
33
|
-
| Analysis Method | Static AST Traversal | Runtime Reflection |
|
|
34
|
-
| Performance Impact | Zero Overhead | Decorator Runtime Cost |
|
|
35
|
-
| Type Accuracy | Full TypeScript Inference | Partial Mapping |
|
|
36
|
-
| Circular References | Auto-Detected & Resolved | Manual Workarounds |
|
|
37
|
-
| Bundle Size | Minimal | Heavy with Decorators |
|
|
38
|
-
| Code Purity | Zero Decorators | Decorator Pollution |
|
|
39
|
-
| Future Compatibility | TypeScript Evolution Ready | Framework Dependent |
|
|
40
|
-
|
|
41
|
-
## π§ The Vision
|
|
42
|
-
|
|
43
|
-
Nest-Scramble embodies my engineering philosophy: **Clean Code through Automation**. As a developer who values TypeScript's type safety and NestJS's architecture, I believe that documentation should never compromise code quality.
|
|
44
|
-
|
|
45
|
-
This library represents a paradigm shiftβfrom manual, error-prone decorators to intelligent, compile-time analysis. It's about empowering developers to focus on building features, not fighting frameworks.
|
|
46
|
-
|
|
47
|
-
## π¬ How it's Built
|
|
48
|
-
|
|
49
|
-
Nest-Scramble is engineered using cutting-edge static analysis techniques that traditional tools cannot match:
|
|
50
|
-
|
|
51
|
-
- **Abstract Syntax Tree (AST) Traversal**: Direct manipulation of TypeScript's AST using `ts-morph` for unparalleled type inference
|
|
52
|
-
- **Zero-Decorator Architecture**: Pure TypeScript classes remain untouched, preserving domain integrity
|
|
53
|
-
- **Compile-Time Intelligence**: All analysis happens at build-time, eliminating runtime performance costs
|
|
54
|
-
- **Circular Reference Mastery**: Advanced algorithms detect and handle complex type relationships automatically
|
|
55
|
-
|
|
56
|
-
This approach delivers what runtime reflection simply cannot: perfect accuracy, zero overhead, and future-proof compatibility with TypeScript's evolving type system.
|
|
57
|
-
|
|
58
|
-
## β‘ Quick Start - Zero Config (2 Steps!)
|
|
59
|
-
|
|
60
|
-
### Option A: Auto-Injection (Recommended - 30 seconds!)
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
# 1. Install
|
|
64
|
-
npm install nest-scramble
|
|
65
|
-
|
|
66
|
-
# 2. Auto-inject into your project
|
|
67
|
-
npx nest-scramble init
|
|
68
|
-
|
|
69
|
-
# 3. Start your app
|
|
70
|
-
npm run start:dev
|
|
71
|
-
|
|
72
|
-
# π Done! Visit http://localhost:3000/docs
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
The `init` command automatically:
|
|
76
|
-
- β
Adds the import statement to your `app.module.ts`
|
|
77
|
-
- β
Injects `NestScrambleModule.forRoot()` into your imports
|
|
78
|
-
- β
Uses smart defaults with zero configuration needed
|
|
79
|
-
|
|
80
|
-
### Option B: Manual Installation (3 Steps)
|
|
81
|
-
|
|
82
|
-
#### 1. Install the Package
|
|
83
|
-
|
|
84
|
-
```bash
|
|
85
|
-
# Using npm
|
|
86
|
-
npm install nest-scramble
|
|
87
|
-
|
|
88
|
-
# Using yarn
|
|
89
|
-
yarn add nest-scramble
|
|
90
|
-
|
|
91
|
-
# Using pnpm
|
|
92
|
-
pnpm add nest-scramble
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### 2. Import Module in Your NestJS App
|
|
96
|
-
|
|
97
|
-
**Zero-Config (Recommended):**
|
|
98
|
-
```typescript
|
|
99
|
-
import { Module } from '@nestjs/common';
|
|
100
|
-
import { NestScrambleModule } from 'nest-scramble';
|
|
101
|
-
|
|
102
|
-
@Module({
|
|
103
|
-
imports: [
|
|
104
|
-
NestScrambleModule.forRoot(), // π― That's it! Zero config needed
|
|
105
|
-
],
|
|
106
|
-
})
|
|
107
|
-
export class AppModule {}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
**With Custom Options:**
|
|
111
|
-
```typescript
|
|
112
|
-
import { Module } from '@nestjs/common';
|
|
113
|
-
import { NestScrambleModule } from 'nest-scramble';
|
|
114
|
-
|
|
115
|
-
@Module({
|
|
116
|
-
imports: [
|
|
117
|
-
NestScrambleModule.forRoot({
|
|
118
|
-
sourcePath: 'src', // Auto-detected by default
|
|
119
|
-
baseUrl: 'http://localhost:3000', // Auto-detected from PORT env
|
|
120
|
-
enableMock: true, // Enabled by default
|
|
121
|
-
autoExportPostman: false, // Disabled by default
|
|
122
|
-
apiTitle: 'My API', // Auto-detected from package.json
|
|
123
|
-
apiVersion: '1.0.0', // Auto-detected from package.json
|
|
124
|
-
}),
|
|
125
|
-
],
|
|
126
|
-
})
|
|
127
|
-
export class AppModule {}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
#### 3. Start Your App and Visit Documentation
|
|
131
|
-
|
|
132
|
-
```bash
|
|
133
|
-
npm run start:dev
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
You'll see a beautiful dashboard in your terminal:
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
140
|
-
β π Nest-Scramble by Mohamed Mustafa is Active! β
|
|
141
|
-
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
142
|
-
β π Docs: http://localhost:3000/docs β
|
|
143
|
-
β π JSON: http://localhost:3000/docs-json β
|
|
144
|
-
β π Mock: http://localhost:3000/scramble-mock β
|
|
145
|
-
β β¨ Scanning: src β
|
|
146
|
-
β π― Controllers: 5 β
|
|
147
|
-
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Then open your browser:
|
|
151
|
-
|
|
152
|
-
- **π
|
|
153
|
-
- **π OpenAPI JSON Spec**: http://localhost:3000/docs-json
|
|
154
|
-
- **π Mock Endpoints**: http://localhost:3000/scramble-mock/*
|
|
155
|
-
|
|
156
|
-
**That's it!** Nest-Scramble automatically:
|
|
157
|
-
- π Detects your project structure
|
|
158
|
-
- π Finds your controllers
|
|
159
|
-
- π Generates OpenAPI spec
|
|
160
|
-
- π¨ Serves beautiful documentation
|
|
161
|
-
- π Provides mock endpoints
|
|
162
|
-
|
|
163
|
-
## βοΈ Configuration Options
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
NestScrambleModule.forRoot({
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
-
|
|
363
|
-
-
|
|
364
|
-
-
|
|
365
|
-
- **
|
|
366
|
-
- **
|
|
367
|
-
- **
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
-
|
|
386
|
-
-
|
|
387
|
-
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
-
|
|
393
|
-
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
- β
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
-
|
|
562
|
-
-
|
|
563
|
-
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
- Ensure
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1
|
+
# Nest-Scramble
|
|
2
|
+
|
|
3
|
+
> Zero-config API Documentation & Postman Generator for NestJS using static analysis
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/nest-scramble)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/Eng-MMustafa/nest-scramble)
|
|
8
|
+
[](https://github.com/Eng-MMustafa)
|
|
9
|
+
|
|
10
|
+
## π Why Nest-Scramble?
|
|
11
|
+
|
|
12
|
+
As a NestJS developer, I was tired of drowning in `@ApiProperty` decorators just to get basic API documentation. I longed for a zero-config solution where docs just worked without polluting my code. **Nest-Scramble changes that** by using static TypeScript analysis to automatically generate:
|
|
13
|
+
|
|
14
|
+
- β
**OpenAPI 3.0 specifications** from your DTOs
|
|
15
|
+
- β
**Interactive Scalar UI documentation** with zero configuration
|
|
16
|
+
- β
**Postman collections** with smart mock data
|
|
17
|
+
- β
**Live mocking** for rapid prototyping
|
|
18
|
+
|
|
19
|
+
**Zero configuration. Zero decorators. Just pure TypeScript.**
|
|
20
|
+
|
|
21
|
+
## π The Story Behind Nest-Scramble
|
|
22
|
+
|
|
23
|
+
It all started with a vision: API documentation should be effortless. As a developer passionate about clean code and developer experience, I knew there had to be a better way than manual decorators and runtime reflection.
|
|
24
|
+
|
|
25
|
+
When I switched to NestJS for its powerful architecture and TypeScript-first approach, I was disappointed by the lack of zero-config documentation tools. Hours wasted on `@ApiProperty({ type: String })` instead of building features.
|
|
26
|
+
|
|
27
|
+
I knew there had to be a better way. Leveraging my expertise in static analysis and Abstract Syntax Trees (AST), I built Nest-Scramble to bring that same developer experience to the Node.js ecosystem. It's not just a toolβit's my mission to make API documentation as effortless as it should be.
|
|
28
|
+
|
|
29
|
+
## π Features Gallery
|
|
30
|
+
|
|
31
|
+
| Feature | Nest-Scramble | Swagger (@nestjs/swagger) |
|
|
32
|
+
|---------|---------------|---------------------------|
|
|
33
|
+
| Analysis Method | Static AST Traversal | Runtime Reflection |
|
|
34
|
+
| Performance Impact | Zero Overhead | Decorator Runtime Cost |
|
|
35
|
+
| Type Accuracy | Full TypeScript Inference | Partial Mapping |
|
|
36
|
+
| Circular References | Auto-Detected & Resolved | Manual Workarounds |
|
|
37
|
+
| Bundle Size | Minimal | Heavy with Decorators |
|
|
38
|
+
| Code Purity | Zero Decorators | Decorator Pollution |
|
|
39
|
+
| Future Compatibility | TypeScript Evolution Ready | Framework Dependent |
|
|
40
|
+
|
|
41
|
+
## π§ The Vision
|
|
42
|
+
|
|
43
|
+
Nest-Scramble embodies my engineering philosophy: **Clean Code through Automation**. As a developer who values TypeScript's type safety and NestJS's architecture, I believe that documentation should never compromise code quality.
|
|
44
|
+
|
|
45
|
+
This library represents a paradigm shiftβfrom manual, error-prone decorators to intelligent, compile-time analysis. It's about empowering developers to focus on building features, not fighting frameworks.
|
|
46
|
+
|
|
47
|
+
## π¬ How it's Built
|
|
48
|
+
|
|
49
|
+
Nest-Scramble is engineered using cutting-edge static analysis techniques that traditional tools cannot match:
|
|
50
|
+
|
|
51
|
+
- **Abstract Syntax Tree (AST) Traversal**: Direct manipulation of TypeScript's AST using `ts-morph` for unparalleled type inference
|
|
52
|
+
- **Zero-Decorator Architecture**: Pure TypeScript classes remain untouched, preserving domain integrity
|
|
53
|
+
- **Compile-Time Intelligence**: All analysis happens at build-time, eliminating runtime performance costs
|
|
54
|
+
- **Circular Reference Mastery**: Advanced algorithms detect and handle complex type relationships automatically
|
|
55
|
+
|
|
56
|
+
This approach delivers what runtime reflection simply cannot: perfect accuracy, zero overhead, and future-proof compatibility with TypeScript's evolving type system.
|
|
57
|
+
|
|
58
|
+
## β‘ Quick Start - Zero Config (2 Steps!)
|
|
59
|
+
|
|
60
|
+
### Option A: Auto-Injection (Recommended - 30 seconds!)
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 1. Install
|
|
64
|
+
npm install nest-scramble
|
|
65
|
+
|
|
66
|
+
# 2. Auto-inject into your project
|
|
67
|
+
npx nest-scramble init
|
|
68
|
+
|
|
69
|
+
# 3. Start your app
|
|
70
|
+
npm run start:dev
|
|
71
|
+
|
|
72
|
+
# π Done! Visit http://localhost:3000/docs
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The `init` command automatically:
|
|
76
|
+
- β
Adds the import statement to your `app.module.ts`
|
|
77
|
+
- β
Injects `NestScrambleModule.forRoot()` into your imports
|
|
78
|
+
- β
Uses smart defaults with zero configuration needed
|
|
79
|
+
|
|
80
|
+
### Option B: Manual Installation (3 Steps)
|
|
81
|
+
|
|
82
|
+
#### 1. Install the Package
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Using npm
|
|
86
|
+
npm install nest-scramble
|
|
87
|
+
|
|
88
|
+
# Using yarn
|
|
89
|
+
yarn add nest-scramble
|
|
90
|
+
|
|
91
|
+
# Using pnpm
|
|
92
|
+
pnpm add nest-scramble
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### 2. Import Module in Your NestJS App
|
|
96
|
+
|
|
97
|
+
**Zero-Config (Recommended):**
|
|
98
|
+
```typescript
|
|
99
|
+
import { Module } from '@nestjs/common';
|
|
100
|
+
import { NestScrambleModule } from 'nest-scramble';
|
|
101
|
+
|
|
102
|
+
@Module({
|
|
103
|
+
imports: [
|
|
104
|
+
NestScrambleModule.forRoot(), // π― That's it! Zero config needed
|
|
105
|
+
],
|
|
106
|
+
})
|
|
107
|
+
export class AppModule {}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**With Custom Options:**
|
|
111
|
+
```typescript
|
|
112
|
+
import { Module } from '@nestjs/common';
|
|
113
|
+
import { NestScrambleModule } from 'nest-scramble';
|
|
114
|
+
|
|
115
|
+
@Module({
|
|
116
|
+
imports: [
|
|
117
|
+
NestScrambleModule.forRoot({
|
|
118
|
+
sourcePath: 'src', // Auto-detected by default
|
|
119
|
+
baseUrl: 'http://localhost:3000', // Auto-detected from PORT env
|
|
120
|
+
enableMock: true, // Enabled by default
|
|
121
|
+
autoExportPostman: false, // Disabled by default
|
|
122
|
+
apiTitle: 'My API', // Auto-detected from package.json
|
|
123
|
+
apiVersion: '1.0.0', // Auto-detected from package.json
|
|
124
|
+
}),
|
|
125
|
+
],
|
|
126
|
+
})
|
|
127
|
+
export class AppModule {}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### 3. Start Your App and Visit Documentation
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm run start:dev
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
You'll see a beautiful dashboard in your terminal:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
140
|
+
β π Nest-Scramble by Mohamed Mustafa is Active! β
|
|
141
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
142
|
+
β π Docs: http://localhost:3000/docs β
|
|
143
|
+
β π JSON: http://localhost:3000/docs-json β
|
|
144
|
+
β π Mock: http://localhost:3000/scramble-mock β
|
|
145
|
+
β β¨ Scanning: src β
|
|
146
|
+
β π― Controllers: 5 β
|
|
147
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Then open your browser:
|
|
151
|
+
|
|
152
|
+
- **π Interactive API Docs (Scalar UI)**: http://localhost:3000/docs
|
|
153
|
+
- **π OpenAPI JSON Spec**: http://localhost:3000/docs-json
|
|
154
|
+
- **π Mock Endpoints**: http://localhost:3000/scramble-mock/*
|
|
155
|
+
|
|
156
|
+
**That's it!** Nest-Scramble automatically:
|
|
157
|
+
- π Detects your project structure
|
|
158
|
+
- π Finds your controllers
|
|
159
|
+
- π Generates OpenAPI spec
|
|
160
|
+
- π¨ Serves beautiful documentation
|
|
161
|
+
- π Provides mock endpoints
|
|
162
|
+
|
|
163
|
+
## βοΈ Configuration Options
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
NestScrambleModule.forRoot({
|
|
167
|
+
// Source directory to scan for controllers
|
|
168
|
+
sourcePath: 'src', // default: 'src'
|
|
169
|
+
|
|
170
|
+
// API base URL for OpenAPI spec
|
|
171
|
+
baseUrl: 'http://localhost:3000', // default: 'http://localhost:3000'
|
|
172
|
+
|
|
173
|
+
// Enable live mocking middleware
|
|
174
|
+
enableMock: true, // default: true
|
|
175
|
+
|
|
176
|
+
// Auto-export Postman collection on startup
|
|
177
|
+
autoExportPostman: false, // default: false
|
|
178
|
+
|
|
179
|
+
// Postman collection output path
|
|
180
|
+
postmanOutputPath: 'collection.json', // default: 'collection.json'
|
|
181
|
+
})
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Configuration Details
|
|
185
|
+
|
|
186
|
+
| Option | Type | Default | Description |
|
|
187
|
+
|--------|------|---------|-------------|
|
|
188
|
+
| `sourcePath` | `string` | `'src'` | Directory where your NestJS controllers are located |
|
|
189
|
+
| `baseUrl` | `string` | `'http://localhost:3000'` | Base URL for your API (used in OpenAPI spec) |
|
|
190
|
+
| `enableMock` | `boolean` | `true` | Enable `/scramble-mock/*` endpoints for testing |
|
|
191
|
+
| `autoExportPostman` | `boolean` | `false` | Automatically generate Postman collection file |
|
|
192
|
+
| `postmanOutputPath` | `string` | `'collection.json'` | Output path for Postman collection |
|
|
193
|
+
|
|
194
|
+
## π Live Mocking Guide
|
|
195
|
+
|
|
196
|
+
Nest-Scramble provides **instant API mocking** without writing controllers:
|
|
197
|
+
|
|
198
|
+
### How It Works
|
|
199
|
+
1. Define your DTOs and controllers normally
|
|
200
|
+
2. Enable `enableMock: true`
|
|
201
|
+
3. All requests to `/scramble-mock/*` return smart mock data
|
|
202
|
+
|
|
203
|
+
### Example
|
|
204
|
+
|
|
205
|
+
**Controller:**
|
|
206
|
+
```typescript
|
|
207
|
+
@Controller('users')
|
|
208
|
+
export class UserController {
|
|
209
|
+
@Get(':id')
|
|
210
|
+
getUser(@Param('id') id: number): UserDto {
|
|
211
|
+
// Your logic here
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Mock Response:**
|
|
217
|
+
```bash
|
|
218
|
+
GET /scramble-mock/users/123
|
|
219
|
+
# Returns: { "id": 123, "name": "John Doe", "email": "john@example.com" }
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Smart Mocking Examples:**
|
|
223
|
+
- `email` β `faker.internet.email()`
|
|
224
|
+
- `name` β `faker.person.fullName()`
|
|
225
|
+
- `createdAt` β `faker.date.recent()`
|
|
226
|
+
- `posts` β Array of mock posts
|
|
227
|
+
|
|
228
|
+

|
|
229
|
+
|
|
230
|
+
## π§ Advanced Usage
|
|
231
|
+
|
|
232
|
+
### CLI Generation
|
|
233
|
+
|
|
234
|
+
The Nest-Scramble CLI allows you to generate API documentation without running your NestJS application.
|
|
235
|
+
|
|
236
|
+
#### Generate OpenAPI Specification
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# Using npx
|
|
240
|
+
npx nest-scramble generate src
|
|
241
|
+
|
|
242
|
+
# Using pnpm dlx
|
|
243
|
+
pnpm dlx nest-scramble generate src
|
|
244
|
+
|
|
245
|
+
# Using yarn dlx
|
|
246
|
+
yarn dlx nest-scramble generate src
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### CLI Options
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
nest-scramble generate <sourcePath> [options]
|
|
253
|
+
|
|
254
|
+
Options:
|
|
255
|
+
-o, --output <file> Output file path (default: "openapi.json")
|
|
256
|
+
-f, --format <type> Output format: openapi or postman (default: "openapi")
|
|
257
|
+
-b, --baseUrl <url> Base URL for the API (default: "http://localhost:3000")
|
|
258
|
+
-t, --title <title> API title (default: "NestJS API")
|
|
259
|
+
-v, --apiVersion <version> API version (default: "1.0.0")
|
|
260
|
+
-h, --help Display help for command
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### Examples
|
|
264
|
+
|
|
265
|
+
**Generate OpenAPI JSON:**
|
|
266
|
+
```bash
|
|
267
|
+
pnpm dlx nest-scramble generate src --output openapi.json
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Generate Postman Collection:**
|
|
271
|
+
```bash
|
|
272
|
+
pnpm dlx nest-scramble generate src --format postman --output collection.json
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Custom API Details:**
|
|
276
|
+
```bash
|
|
277
|
+
pnpm dlx nest-scramble generate src \
|
|
278
|
+
--output my-api.json \
|
|
279
|
+
--title "My Awesome API" \
|
|
280
|
+
--apiVersion "2.0.0" \
|
|
281
|
+
--baseUrl "https://api.example.com"
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Check Version:**
|
|
285
|
+
```bash
|
|
286
|
+
pnpm dlx nest-scramble --version
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Programmatic API
|
|
290
|
+
|
|
291
|
+
Use Nest-Scramble programmatically in your Node.js scripts:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { ScannerService, OpenApiTransformer, PostmanCollectionGenerator } from 'nest-scramble';
|
|
295
|
+
import * as fs from 'fs';
|
|
296
|
+
|
|
297
|
+
// Scan controllers
|
|
298
|
+
const scanner = new ScannerService();
|
|
299
|
+
const controllers = scanner.scanControllers('src');
|
|
300
|
+
|
|
301
|
+
// Generate OpenAPI spec
|
|
302
|
+
const transformer = new OpenApiTransformer('http://localhost:3000');
|
|
303
|
+
const openApiSpec = transformer.transform(
|
|
304
|
+
controllers,
|
|
305
|
+
'My API',
|
|
306
|
+
'1.0.0',
|
|
307
|
+
'http://localhost:3000'
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
// Save to file
|
|
311
|
+
fs.writeFileSync('openapi.json', JSON.stringify(openApiSpec, null, 2));
|
|
312
|
+
|
|
313
|
+
// Or generate Postman collection
|
|
314
|
+
const postmanGen = new PostmanCollectionGenerator('http://localhost:3000');
|
|
315
|
+
const collection = postmanGen.generateCollection(controllers);
|
|
316
|
+
fs.writeFileSync('collection.json', JSON.stringify(collection, null, 2));
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### CI/CD Integration
|
|
320
|
+
|
|
321
|
+
Add to your CI/CD pipeline to auto-generate documentation:
|
|
322
|
+
|
|
323
|
+
```yaml
|
|
324
|
+
# .github/workflows/docs.yml
|
|
325
|
+
name: Generate API Docs
|
|
326
|
+
|
|
327
|
+
on:
|
|
328
|
+
push:
|
|
329
|
+
branches: [main]
|
|
330
|
+
|
|
331
|
+
jobs:
|
|
332
|
+
generate-docs:
|
|
333
|
+
runs-on: ubuntu-latest
|
|
334
|
+
steps:
|
|
335
|
+
- uses: actions/checkout@v3
|
|
336
|
+
- uses: actions/setup-node@v3
|
|
337
|
+
with:
|
|
338
|
+
node-version: '18'
|
|
339
|
+
- run: npm install
|
|
340
|
+
- run: npx nest-scramble generate src --output openapi.json
|
|
341
|
+
- uses: actions/upload-artifact@v3
|
|
342
|
+
with:
|
|
343
|
+
name: api-docs
|
|
344
|
+
path: openapi.json
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## π¨ Documentation UI - Professional API Dashboard
|
|
348
|
+
|
|
349
|
+
### β¨ Elite Dashboard Design (NEW!)
|
|
350
|
+
|
|
351
|
+
Nest-Scramble features a **professional, high-end API dashboard** inspired by Stripe and Postman, where each request is displayed on a separate page for focused documentation!
|
|
352
|
+
|
|
353
|
+
**π Key Features:**
|
|
354
|
+
- **Sidebar-Only Navigation** - Fixed 320px sidebar with controller grouping
|
|
355
|
+
- **Single-Request Per Page** - Each endpoint gets its own dedicated view
|
|
356
|
+
- **Three-Column Elite Layout** - Information | Request Editor | Test Panel
|
|
357
|
+
- **Deep Black Background** - Professional `#000000` and `#0B0E14` theme
|
|
358
|
+
- **Cyber-Cyan Accents** - `#00f2ff` for active states and primary actions
|
|
359
|
+
- **Vibrant HTTP Method Badges** - Color-coded with glow effects:
|
|
360
|
+
- GET = Royal Blue (`#3B82F6`)
|
|
361
|
+
- POST = Emerald Green (`#10B981`)
|
|
362
|
+
- PUT = Amber Orange (`#F59E0B`)
|
|
363
|
+
- PATCH = Violet Purple (`#8B5CF6`)
|
|
364
|
+
- DELETE = Vibrant Red (`#EF4444`)
|
|
365
|
+
- **Glassmorphism Effects** - Backdrop blur on request/response panels
|
|
366
|
+
- **40px Spacious Padding** - Premium whitespace throughout
|
|
367
|
+
- **Terminal-Style Response** - Black box with green text for API responses
|
|
368
|
+
- **High-Contrast Labels** - Required, Type, and Default badges
|
|
369
|
+
- **Custom Scrollbars** - Gradient cyan-to-purple styling
|
|
370
|
+
- **Plus Jakarta Sans Typography** - Modern, professional font family
|
|
371
|
+
- **Powered by Badge** - Animated branding with pulse effect
|
|
372
|
+
|
|
373
|
+
### π Three-Column Elite Interface
|
|
374
|
+
|
|
375
|
+
The dashboard uses a professional three-column layout for each endpoint:
|
|
376
|
+
|
|
377
|
+
**Column 1 (Left) - Information Panel:**
|
|
378
|
+
- Endpoint title with large, bold typography
|
|
379
|
+
- HTTP method badge with vibrant colors and glow
|
|
380
|
+
- Endpoint description and documentation
|
|
381
|
+
- Clean parameters table with high-contrast labels
|
|
382
|
+
- Type information and required field indicators
|
|
383
|
+
|
|
384
|
+
**Column 2 (Middle) - Request Body Editor:**
|
|
385
|
+
- Glassmorphism design with backdrop blur
|
|
386
|
+
- Auto-filled mock data examples
|
|
387
|
+
- JSON editor with syntax highlighting
|
|
388
|
+
- Copy-to-clipboard functionality
|
|
389
|
+
- Real-time validation
|
|
390
|
+
|
|
391
|
+
**Column 3 (Right) - Test Request Panel:**
|
|
392
|
+
- Enhanced glassmorphism with cyan border glow
|
|
393
|
+
- Large "Send Request" button with gradient animation
|
|
394
|
+
- Terminal-style response viewer (black background, green text)
|
|
395
|
+
- Status code indicators
|
|
396
|
+
- Response headers display
|
|
397
|
+
|
|
398
|
+
### π¨ Theme Customization
|
|
399
|
+
|
|
400
|
+
**Futuristic Theme (Default):**
|
|
401
|
+
```typescript
|
|
402
|
+
NestScrambleModule.forRoot({
|
|
403
|
+
theme: 'futuristic', // Professional dark dashboard
|
|
404
|
+
primaryColor: '#00f2ff', // Cyber-Cyan (default)
|
|
405
|
+
customDomainIcon: '/logo.png', // Your brand favicon
|
|
406
|
+
apiTitle: 'My Awesome API',
|
|
407
|
+
})
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**Classic Theme:**
|
|
411
|
+
```typescript
|
|
412
|
+
NestScrambleModule.forRoot({
|
|
413
|
+
theme: 'classic', // Clean, light, professional
|
|
414
|
+
primaryColor: '#0066cc', // Corporate blue
|
|
415
|
+
apiTitle: 'Enterprise API',
|
|
416
|
+
})
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**Custom Color Branding:**
|
|
420
|
+
```typescript
|
|
421
|
+
// One line changes the entire UI color scheme!
|
|
422
|
+
NestScrambleModule.forRoot({
|
|
423
|
+
primaryColor: '#a855f7', // Electric Purple
|
|
424
|
+
// or '#10b981' for Emerald Green
|
|
425
|
+
// or '#f59e0b' for Amber Orange
|
|
426
|
+
// or any hex color you want!
|
|
427
|
+
})
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
### π UI Configuration Options
|
|
431
|
+
|
|
432
|
+
| Option | Type | Default | Description |
|
|
433
|
+
|--------|------|---------|-------------|
|
|
434
|
+
| `theme` | `'classic' \| 'futuristic'` | `'futuristic'` | UI theme selection |
|
|
435
|
+
| `primaryColor` | `string` | `'#00f2ff'` | Primary accent color (hex) |
|
|
436
|
+
| `customDomainIcon` | `string` | `''` | Custom favicon URL |
|
|
437
|
+
| `apiTitle` | `string` | Auto-detected | API documentation title |
|
|
438
|
+
| `apiVersion` | `string` | Auto-detected | API version number |
|
|
439
|
+
|
|
440
|
+
### π Interactive Features
|
|
441
|
+
|
|
442
|
+
When you visit `http://localhost:3000/docs`, you'll experience:
|
|
443
|
+
|
|
444
|
+
- π― **Single-Request Navigation** - Each endpoint on its own dedicated page
|
|
445
|
+
- π **Controller Grouping** - Organized sidebar with uppercase section headers
|
|
446
|
+
- π¨ **Active State Glow** - Cyber-cyan highlight for selected endpoints
|
|
447
|
+
- π **Auto-generated Examples** - Pre-filled mock data in request editor
|
|
448
|
+
- π§ͺ **Live Testing** - Send requests directly from the three-column interface
|
|
449
|
+
- π» **Terminal Response** - Black box with green text for authentic feel
|
|
450
|
+
- π **Quick Search** - Press 'K' to search endpoints instantly
|
|
451
|
+
- π± **Responsive Design** - Adapts to mobile, tablet, and desktop
|
|
452
|
+
- β¨ **Animated Branding** - Pulsing "Powered by Nest-Scramble" badge
|
|
453
|
+
- π **Developer Easter Eggs** - Check your browser console for surprises!
|
|
454
|
+
|
|
455
|
+
### π₯οΈ Terminal Dashboard
|
|
456
|
+
|
|
457
|
+
The startup dashboard now features **gradient styling** with ANSI colors:
|
|
458
|
+
|
|
459
|
+
```
|
|
460
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
461
|
+
β β¨ NEST-SCRAMBLE by Mohamed Mustafa β
|
|
462
|
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
463
|
+
β β
|
|
464
|
+
β β Documentation β
|
|
465
|
+
β β http://localhost:3000/docs β
|
|
466
|
+
β β
|
|
467
|
+
β β OpenAPI Spec β
|
|
468
|
+
β β http://localhost:3000/docs-json β
|
|
469
|
+
β β
|
|
470
|
+
β β Mock Server β
|
|
471
|
+
β β http://localhost:3000/scramble-mock β
|
|
472
|
+
β β
|
|
473
|
+
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
|
|
474
|
+
β π¦ Source Path: src β
|
|
475
|
+
β π― Controllers: 5 β
|
|
476
|
+
β π¨ Theme: Futuristic β
|
|
477
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### π More UI Documentation
|
|
481
|
+
|
|
482
|
+
For complete UI customization guide, see:
|
|
483
|
+
- **[UI_FEATURES.md](./UI_FEATURES.md)** - Comprehensive feature documentation
|
|
484
|
+
- **[examples/futuristic-ui-example.ts](./examples/futuristic-ui-example.ts)** - Usage examples
|
|
485
|
+
|
|
486
|
+
### Available Endpoints
|
|
487
|
+
|
|
488
|
+
| Endpoint | Description |
|
|
489
|
+
|----------|-------------|
|
|
490
|
+
| `GET /docs` | Interactive Scalar UI documentation |
|
|
491
|
+
| `GET /docs-json` | OpenAPI 3.0 JSON specification |
|
|
492
|
+
| `GET /docs/json` | Legacy endpoint (same as above) |
|
|
493
|
+
| `GET /docs/spec` | OpenAPI spec as JSON response |
|
|
494
|
+
|
|
495
|
+
### Accessing the OpenAPI Spec
|
|
496
|
+
|
|
497
|
+
You can use the OpenAPI JSON with other tools:
|
|
498
|
+
|
|
499
|
+
```bash
|
|
500
|
+
# Download the spec
|
|
501
|
+
curl http://localhost:3000/docs-json > openapi.json
|
|
502
|
+
|
|
503
|
+
# Use with Swagger UI
|
|
504
|
+
docker run -p 8080:8080 -e SWAGGER_JSON=/openapi.json -v $(pwd):/usr/share/nginx/html/openapi.json swaggerapi/swagger-ui
|
|
505
|
+
|
|
506
|
+
# Import into Postman
|
|
507
|
+
# File > Import > Link > http://localhost:3000/docs-json
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
## β
Supported Features
|
|
511
|
+
|
|
512
|
+
### Type Analysis
|
|
513
|
+
- β
Primitive types (string, number, boolean)
|
|
514
|
+
- β
Arrays and nested objects
|
|
515
|
+
- β
Union types
|
|
516
|
+
- β
Enums
|
|
517
|
+
- β
Optional properties
|
|
518
|
+
- β
Circular references (auto-detected)
|
|
519
|
+
|
|
520
|
+
### HTTP Methods
|
|
521
|
+
- β
GET, POST, PUT, DELETE, PATCH
|
|
522
|
+
- β
Path parameters (@Param)
|
|
523
|
+
- β
Query parameters (@Query)
|
|
524
|
+
- β
Request bodies (@Body)
|
|
525
|
+
|
|
526
|
+
### Code Generation
|
|
527
|
+
- β
Curl commands
|
|
528
|
+
- β
JavaScript Fetch
|
|
529
|
+
- β
TypeScript with types
|
|
530
|
+
|
|
531
|
+
## π§ͺ Testing with Demo Controller
|
|
532
|
+
|
|
533
|
+
The library includes a `DemoController` with complex DTOs:
|
|
534
|
+
|
|
535
|
+
```typescript
|
|
536
|
+
// Complex DTOs with circular references
|
|
537
|
+
export class UserDto {
|
|
538
|
+
id: number;
|
|
539
|
+
name: string;
|
|
540
|
+
email: string;
|
|
541
|
+
role: UserRole; // Enum
|
|
542
|
+
address: AddressDto; // Nested
|
|
543
|
+
posts: PostDto[]; // Circular reference
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export class PostDto {
|
|
547
|
+
id: number;
|
|
548
|
+
title: string;
|
|
549
|
+
content: string;
|
|
550
|
+
author: UserDto; // Circular reference
|
|
551
|
+
}
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
Run the demo to verify everything works perfectly.
|
|
555
|
+
|
|
556
|
+
## πΊοΈ Roadmap
|
|
557
|
+
|
|
558
|
+
- [ ] GraphQL support
|
|
559
|
+
- [ ] Custom mock data providers
|
|
560
|
+
- [ ] Authentication integration
|
|
561
|
+
- [ ] API versioning
|
|
562
|
+
- [ ] Performance optimizations
|
|
563
|
+
- [ ] Plugin system for custom analyzers
|
|
564
|
+
|
|
565
|
+
## π§ Troubleshooting
|
|
566
|
+
|
|
567
|
+
### Common Issues
|
|
568
|
+
|
|
569
|
+
#### 1. **"No controllers found" Warning**
|
|
570
|
+
|
|
571
|
+
If you see this warning on startup:
|
|
572
|
+
```
|
|
573
|
+
[Nest-Scramble] No controllers found in /src. Please check your sourcePath config.
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
**Solution:**
|
|
577
|
+
- Ensure your `sourcePath` option points to the correct directory containing your controllers
|
|
578
|
+
- Check that your controllers use the `@Controller()` decorator from `@nestjs/common`
|
|
579
|
+
- Verify your project structure matches the configured path
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
NestScrambleModule.forRoot({
|
|
583
|
+
sourcePath: 'src', // Make sure this matches your project structure
|
|
584
|
+
})
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
#### 2. **UI Not Loading / Blank Page at /docs**
|
|
588
|
+
|
|
589
|
+
**Solution:**
|
|
590
|
+
- Clear your browser cache and hard refresh (Ctrl+Shift+R / Cmd+Shift+R)
|
|
591
|
+
- Check browser console for errors
|
|
592
|
+
- Verify the `/docs-json` endpoint returns valid JSON
|
|
593
|
+
- Ensure you're using version 1.1.0 or higher: `npm list nest-scramble`
|
|
594
|
+
|
|
595
|
+
#### 3. **TypeScript Compilation Errors**
|
|
596
|
+
|
|
597
|
+
If you get errors like `Cannot find module 'nest-scramble'`:
|
|
598
|
+
|
|
599
|
+
**Solution:**
|
|
600
|
+
```bash
|
|
601
|
+
# Clear node_modules and reinstall
|
|
602
|
+
rm -rf node_modules package-lock.json
|
|
603
|
+
npm install
|
|
604
|
+
|
|
605
|
+
# Rebuild your project
|
|
606
|
+
npm run build
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
#### 4. **"Unauthorized" (401) Error on /docs Endpoint**
|
|
610
|
+
|
|
611
|
+
If you have a Global AuthGuard and get 401 Unauthorized when accessing `/docs` or `/docs-json`:
|
|
612
|
+
|
|
613
|
+
**Solution:**
|
|
614
|
+
|
|
615
|
+
Nest-Scramble automatically marks its documentation endpoints as public using `@SetMetadata('isPublic', true)`. However, your AuthGuard needs to respect this metadata.
|
|
616
|
+
|
|
617
|
+
Update your AuthGuard to check for the `isPublic` metadata:
|
|
618
|
+
|
|
619
|
+
```typescript
|
|
620
|
+
import { Injectable, ExecutionContext } from '@nestjs/common';
|
|
621
|
+
import { Reflector } from '@nestjs/core';
|
|
622
|
+
import { AuthGuard } from '@nestjs/passport';
|
|
623
|
+
|
|
624
|
+
@Injectable()
|
|
625
|
+
export class JwtAuthGuard extends AuthGuard('jwt') {
|
|
626
|
+
constructor(private reflector: Reflector) {
|
|
627
|
+
super();
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
canActivate(context: ExecutionContext) {
|
|
631
|
+
// Check if route is marked as public
|
|
632
|
+
const isPublic = this.reflector.getAllAndOverride<boolean>('isPublic', [
|
|
633
|
+
context.getHandler(),
|
|
634
|
+
context.getClass(),
|
|
635
|
+
]);
|
|
636
|
+
|
|
637
|
+
if (isPublic) {
|
|
638
|
+
return true; // Allow access to public routes
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return super.canActivate(context);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
**Alternative Solution - Exclude /docs path:**
|
|
647
|
+
|
|
648
|
+
```typescript
|
|
649
|
+
import { Module } from '@nestjs/common';
|
|
650
|
+
import { APP_GUARD } from '@nestjs/core';
|
|
651
|
+
|
|
652
|
+
@Module({
|
|
653
|
+
providers: [
|
|
654
|
+
{
|
|
655
|
+
provide: APP_GUARD,
|
|
656
|
+
useClass: JwtAuthGuard,
|
|
657
|
+
},
|
|
658
|
+
],
|
|
659
|
+
})
|
|
660
|
+
export class AppModule {}
|
|
661
|
+
|
|
662
|
+
// In your AuthGuard:
|
|
663
|
+
canActivate(context: ExecutionContext) {
|
|
664
|
+
const request = context.switchToHttp().getRequest();
|
|
665
|
+
|
|
666
|
+
// Skip authentication for documentation endpoints
|
|
667
|
+
if (request.url.startsWith('/docs')) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return super.canActivate(context);
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
#### 5. **pnpm Dependency Conflicts**
|
|
676
|
+
|
|
677
|
+
If using pnpm and getting peer dependency warnings:
|
|
678
|
+
|
|
679
|
+
**Solution:**
|
|
680
|
+
Nest-Scramble v1.1.0+ properly declares peer dependencies. Update to the latest version:
|
|
681
|
+
```bash
|
|
682
|
+
pnpm update nest-scramble
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
#### 6. **Controllers Not Being Scanned**
|
|
686
|
+
|
|
687
|
+
The scanner looks in your **host project's** `src` folder, not the library's folder.
|
|
688
|
+
|
|
689
|
+
**Diagnostic Steps:**
|
|
690
|
+
1. Check the startup logs - they show exactly where the scanner is looking:
|
|
691
|
+
```
|
|
692
|
+
[Nest-Scramble] Scanning directory: /path/to/your/project/src
|
|
693
|
+
[Nest-Scramble] Found X controller(s)
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
2. Ensure your controllers are in TypeScript files (`.ts`) not JavaScript (`.js`)
|
|
697
|
+
|
|
698
|
+
3. Verify your `tsconfig.json` exists in the project root
|
|
699
|
+
|
|
700
|
+
#### 7. **Mock Endpoints Not Working**
|
|
701
|
+
|
|
702
|
+
If `/scramble-mock/*` returns 404:
|
|
703
|
+
|
|
704
|
+
**Solution:**
|
|
705
|
+
- Ensure `enableMock: true` in your configuration
|
|
706
|
+
- The middleware applies to all routes matching `/scramble-mock/*`
|
|
707
|
+
- Example: `http://localhost:3000/scramble-mock/users/123`
|
|
708
|
+
|
|
709
|
+
#### 8. **OpenAPI Spec is Empty or Incomplete**
|
|
710
|
+
|
|
711
|
+
**Solution:**
|
|
712
|
+
- Ensure your DTOs are TypeScript classes or interfaces (not plain objects)
|
|
713
|
+
- Check that your controller methods have proper return type annotations
|
|
714
|
+
- Verify decorators are imported from `@nestjs/common`
|
|
715
|
+
|
|
716
|
+
```typescript
|
|
717
|
+
// β
Good - Explicit return type
|
|
718
|
+
@Get(':id')
|
|
719
|
+
getUser(@Param('id') id: string): UserDto {
|
|
720
|
+
return this.userService.findOne(id);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// β Bad - No return type
|
|
724
|
+
@Get(':id')
|
|
725
|
+
getUser(@Param('id') id: string) {
|
|
726
|
+
return this.userService.findOne(id);
|
|
727
|
+
}
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
### Getting Help
|
|
731
|
+
|
|
732
|
+
If you're still experiencing issues:
|
|
733
|
+
|
|
734
|
+
1. **Check the logs** - Nest-Scramble provides detailed diagnostic output on startup
|
|
735
|
+
2. **Verify your version** - Run `npm list nest-scramble` (should be 1.1.0+)
|
|
736
|
+
3. **Open an issue** - [GitHub Issues](https://github.com/Eng-MMustafa/nest-scramble/issues)
|
|
737
|
+
|
|
738
|
+
When reporting issues, please include:
|
|
739
|
+
- Nest-Scramble version
|
|
740
|
+
- NestJS version
|
|
741
|
+
- Package manager (npm/yarn/pnpm)
|
|
742
|
+
- Startup logs
|
|
743
|
+
- Sample controller code
|
|
744
|
+
|
|
745
|
+
## π€ Contributing
|
|
746
|
+
|
|
747
|
+
We welcome contributions! Please:
|
|
748
|
+
|
|
749
|
+
1. Fork the repository
|
|
750
|
+
2. Create a feature branch
|
|
751
|
+
3. Add tests for new features
|
|
752
|
+
4. Submit a pull request
|
|
753
|
+
|
|
754
|
+
## π License
|
|
755
|
+
|
|
756
|
+
MIT License - see [LICENSE](LICENSE) file.
|
|
757
|
+
|
|
758
|
+
## βπ» About the Author
|
|
759
|
+
|
|
760
|
+

|
|
761
|
+
|
|
762
|
+
Mohamed Mustafa is a passionate full-stack developer with a deep love for TypeScript and modern web frameworks. His mission is to build tools that enhance developer experience and eliminate repetitive tasks. When he's not crafting open-source libraries, you'll find him exploring new technologies, contributing to the developer community, or sharing insights through technical writing.
|
|
763
|
+
|
|
764
|
+
- [GitHub](https://github.com/Eng-MMustafa)
|
|
765
|
+
- [LinkedIn](https://www.linkedin.com/in/engmohammedmustafa/)
|