Enhanced Express module generator with Mongoose models, Postman collections, and Swagger documentation
npm install @unknow69/leo-generator--file:true)
bash
npm install leo-generate --global
`
Or use with npx:
`bash
npx leo-generate
`
šÆ Quick Start
$3
`bash
Primary command (recommended)
leo-generate generate User name:string email:string age:number
Short alias
leo-generate g User name:string email:string
Legacy support (still works)
leo-generate User name:string email:string age:number
`
š Quick Command Reference
| Command | Purpose | Example |
|---------|---------|---------|
| generate | Create new module | leo-generate generate User name:string email:string |
| g | Short alias for generate | leo-generate g Product name:string price:number |
| update-docs | Update all documentation | leo-generate update-docs |
| docs | Short alias for update-docs | leo-generate docs |
| | Legacy syntax | leo-generate User name:string email:string |
$3
- --no-postman - Skip Postman collection generation
- --no-swagger - Skip Swagger documentation generation
- --postman-dir - Custom Postman output directory
- --swagger-file - Custom Swagger file path
- --modules-dir - Custom modules directory
This creates:
`
src/app/modules/user/
āāā user.interface.ts // Enhanced TypeScript interfaces
āāā user.model.ts // Mongoose model with validation
āāā user.controller.ts // Production-ready controllers
āāā user.service.ts // Enhanced service layer
āāā user.route.ts // RESTful routes
āāā user.validation.ts // Zod validation schemas
āāā user.constants.ts // Constants
postman/
āāā user.postman_collection.json // Auto-generated Postman collection
swagger.json // Updated with new endpoints
`
š ļø Commands
$3
`bash
leo-generate generate [fields...]
Options:
--no-postman # Skip Postman collection generation
--no-swagger # Skip Swagger documentation
--postman-dir # Custom Postman output directory
--swagger-file # Custom Swagger file path
--modules-dir # Custom modules directory
--modules-dir # Custom modules directory
--routes-file # Custom routes file
--file:true # Enable file upload support (generates cleanup helpers)
`
$3
`bash
Intelligently updates documentation for all existing modules
leo-generate update-docs
Aliases:
leo-generate docs
The system automatically:
ā
Scans all modules in your project
ā
Reads both interface and model files
ā
Extracts current field definitions
ā
Generates accurate Postman collections
ā
Updates Swagger documentation
ā
Handles complex nested structures
ā
Preserves enum values and references
Options:
--modules-dir # Path to modules directory
--no-postman # Skip Postman updates
--no-swagger # Skip Swagger updates
--postman-dir # Custom Postman output directory
--swagger-file # Custom Swagger file path
`
šļø Advanced Examples
$3
`bash
E-commerce Order with nested items
leo-generate generate Order \
customer:objectid:User \
items:array:object:name:string:price:number:quantity:number \
status:enum[pending,processing,shipped,delivered] \
shippingAddress:object:street:string:city:string:zipCode:string \
totalAmount:number \
createdAt:date
`
$3
`bash
Blog post with author reference and tags
leo-generate generate Post \
title!:string \
content!:string \
author:objectid:User \
tags:array:string \
status:enum[draft,published,archived] \
publishedAt?:date \
viewCount:number
`
$3
`bash
Product with multiple variants
leo-generate generate Product \
name!:string \
description:string \
category:enum[Electronics,Clothing,Books,Home] \
variants:array:object:size:string:color:string:price:number:stock:number \
images:array:string \
isActive:boolean
`
š Field Types & Syntax
$3
`bash
name:string # String field
age:number # Number field
isActive:boolean # Boolean field
createdAt:date # Date field
`
$3
`bash
name!:string # Required field
email?:string # Optional field
`
$3
`bash
status:enum[active,inactive,pending]
role:enum[admin,user,moderator]
`
$3
`bash
author:objectid:User # Single reference
categories:array:objectid:Category # Array of references
`
$3
`bash
Array of objects
items:array:object:name:string:price:number:quantity:number
Nested object
address:object:street:string:city:string:country:string
Mixed arrays
tags:array:string
scores:array:number
`
š® Generated API Features
$3
- ā
Pagination support with meta information
- š Search functionality across string fields
- š Sorting with customizable fields
- š”ļø Input validation and sanitization
- š File upload handling
- ā” Error handling with proper HTTP status codes
$3
- š ObjectId validation
- š Auto-population of references
- šļø Proper file cleanup on deletion
- š Optimized queries with lean()
- š Advanced search with regex
- š Aggregation support
$3
For a module named "Product":
`
POST /api/v1/products # Create product
GET /api/v1/products # Get all (with pagination, search, sort)
GET /api/v1/products/:id # Get single product
PATCH /api/v1/products/:id # Update product
DELETE /api/v1/products/:id # Delete product
Query Parameters for GET /api/v1/products:
?page=1&limit=10&search=keyword&sortBy=createdAt&sortOrder=desc
`
š® Postman Integration
$3
- š Complete CRUD operations
- š Sample request bodies with realistic data
- š Environment variables for base URL
- š Proper HTTP methods and headers
- šÆ Parameter examples for all endpoints
$3
`json
{
"info": {
"name": "Product API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create Product",
"request": {
"method": "POST",
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"sample_name\",\n \"price\": 123\n}"
}
}
}
]
}
`
š Swagger Integration
$3
- š OpenAPI 3.0 specification
- š·ļø Proper tags and descriptions
- š Request/response schemas
- š Parameter documentation
- ā
Validation rules included
- š Automatic updates on module changes
$3
`yaml
components:
schemas:
Product:
type: object
properties:
_id:
type: string
description: MongoDB ObjectId
name:
type: string
description: name field
price:
type: number
description: price field
createdAt:
type: string
format: date-time
required:
- _id
- name
`
āļø Configuration
$3
`json
{
"moduleGenerator": {
"modulesDir": "src/app/modules",
"routesFile": "src/routes/index.ts"
}
}
`
$3
`bash
leo-generate generate User name:string \
--modules-dir src/modules \
--routes-file src/routes.ts \
--postman-dir collections \
--swagger-file api-docs.json
`
š§ Enhanced Documentation Intelligence (v1.2.0)
$3
The enhanced system now intelligently analyzes your code changes:
`bash
Example: You modify an Order model
BEFORE: items had name, price, quantity
AFTER: items only have name (removed price, quantity)
Simply run:
leo-generate update-docs
The system will:
ā
Read your modified interface and model files
ā
Detect that items now only have 'name' field
ā
Update Postman collections: {"items": [{"name": "sample_name"}]}
ā
Update Swagger schemas to reflect current structure
ā
Handle ALL field types: enums, arrays, nested objects, references
`
$3
Every field type the generator can create is fully supported in updates:
| Syntax | Generated Sample | Update Support |
|--------|------------------|----------------|
| name:string | "name": "sample_name" | ā
Perfect |
| age:number | "age": 123 | ā
Perfect |
| tags:array:string | "tags": ["sample_item"] | ā
Perfect |
| scores:array:number | "scores": [123] | ā
Perfect |
| status:enum[active,inactive] | "status": "active" | ā
Perfect |
| author:objectid:User | "author": "507f1f77..." | ā
Perfect |
| items:array:object:name:string:price:number | "items": [{"name": "...", "price": 123}] | ā
Perfect |
š Migration from v1.1
The new version maintains backward compatibility:
`bash
Old way (still works)
leo-generate User name:string email:string
New way (recommended)
leo-generate generate User name:string email:string
Enhanced documentation updates
leo-generate update-docs
`
šÆ Best Practices
$3
1. Use singular names for modules (e.g., "User" not "Users")
2. Mark required fields with "!" suffix
3. Use descriptive field names
4. Group related fields logically
5. Consider using enums for status fields
$3
`bash
Good
leo-generate generate User name!:string email!:string status:enum[active,inactive]
Avoid
leo-generate generate Users NAME:string Email:string stat:string
`
$3
`bash
Prefer structured objects over loose data
leo-generate generate Order \
items:array:object:productId:objectid:Product:quantity:number:price:number \
# Instead of: items:array:string
`
š Performance Features
$3
- š Lean queries for list operations
- š Indexed search fields
- š Aggregation pipeline support
- š Efficient population of references
$3
- šŖ Service layer designed for caching integration
- š Consistent data access patterns
- ā” Optimized for Redis integration
š”ļø Security Features
$3
- ā
Zod schema validation
- š”ļø XSS protection ready
- š Sanitized inputs
- š Type-safe operations
$3
- š Proper file type validation
- šļø Automatic cleanup on errors
- š Size limit enforcement ready
š¤ Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
$3
`bash
git clone
cd leo-generator
npm install
npm run build
``