apexswag
v1.0.5
Published
πΆοΈ Generate beautiful Swagger/OpenAPI documentation from Salesforce Apex REST classes with one command
Maintainers
Readme
ApexSwag πΆοΈ
Giving your Apex REST endpoints the swagger they deserve.
ApexSwag is a Salesforce CLI plugin that transforms your @RestResource classes into beautiful, interactive OpenAPI 3.0 documentation β with a single command.
Created by Nishant Mohapatra
Prerequisites
Before installing ApexSwag, make sure you have the following:
1. Node.js (v18 or higher)
Download and install from nodejs.org
# Verify installation
node --version # Should show v18.x.x or higher2. Salesforce CLI
The Salesforce CLI (sf) is required. Install it using npm:
# Install Salesforce CLI globally
npm install -g @salesforce/cli
# Verify installation
sf --versionOr download from Salesforce CLI Setup Guide
3. Salesforce Org Access
You need access to a Salesforce org with Apex REST classes. This can be:
- A Developer Edition org (free at developer.salesforce.com)
- A Sandbox org
- A Scratch org
Installation
# Install ApexSwag plugin
sf plugins install apexswagFrom Source (Development)
git clone https://github.com/nkmongit/apexswag.git
cd apexswag
npm install
npm run build
sf plugins link .First-Time Setup
If this is your first time using ApexSwag, follow these steps:
Step 1: Authenticate Your Salesforce Org
# Open browser to log in to your Salesforce org
sf org login webThis opens your browser. Log in to your Salesforce org and authorize the CLI.
Step 2: Verify Connection
# List connected orgs
sf org listYou should see your org in the list.
Step 3: Run ApexSwag
# Generate documentation
sf apexswag generateApexSwag will scan your org for @RestResource classes and open the documentation UI.
Features
| Feature | Description |
|---------|-------------|
| π Auto Discovery | Scans your Salesforce Org for @RestResource classes |
| π ApexDoc Parsing | Extracts @description, @param, @return, and @tag annotations |
| π Security Schemas | OAuth2 and Bearer authentication definitions |
| β οΈ Error Responses | Standard 400/401/403/404/500 response schemas |
| π Smart Examples | Auto-generated examples based on field names |
| π·οΈ Tag Grouping | Group endpoints using @tag annotations |
| π Dynamic Schemas | Fetch SObject field metadata including custom objects |
| π» Interactive UI | Modern React-based documentation interface |
| π¦ Postman Export | Export as Postman Collection v2.1 |
| πΎ OpenAPI Export | Export JSON spec for CI/CD pipelines |
| π Watch Mode | Auto-reload when classes change |
Usage
Quick Start
# Interactive mode - select org and classes
sf apexswag generate
# Specify org and port
sf apexswag generate -o my-org -p 8080
# Export OpenAPI spec
sf apexswag generate --export -f api-spec.json
# Export Postman collection
sf apexswag generate --postman -f collection.json
# Watch mode
sf apexswag generate --watch
# Dynamic SObject schemas
sf apexswag generate --dynamic-sobjectsCommand Flags
| Flag | Short | Description | Default |
|------|-------|-------------|---------|
| --target-org | -o | Target Salesforce Org | Interactive |
| --port | -p | Server port | 3000 |
| --export | -e | Export OpenAPI JSON | false |
| --postman | | Export Postman Collection | false |
| --output-file | -f | Output file path | openapi.json |
| --class-names | -c | Comma-separated class names | All |
| --watch | -w | Watch mode | false |
| --dynamic-sobjects | | Fetch SObject schemas | false |
| --no-security | | Exclude security definitions | false |
| --no-errors | | Exclude error responses | false |
| --no-examples | | Exclude example values | false |
ApexDoc Support
Annotations
/**
* @description Creates a new Widget
* @param name The widget name
* @param count Number of items
* @return The created Widget ID
* @tag Widgets
*/
@HttpPost
global static String createWidget(String name, Integer count) { ... }Inner Classes
global class RequestWrapper {
public String name;
public Integer age;
}
@HttpPost
global static void doPost(RequestWrapper req) { ... }Generates schema with smart examples:
{ "name": "Acme Corporation", "age": 25 }Troubleshooting
"No Salesforce orgs connected"
Run these commands:
sf org login web # Authenticate an org
sf org list # Verify it appears
sf apexswag generate # Try again"No @RestResource classes found"
Make sure your org has Apex classes with the @RestResource annotation:
@RestResource(urlMapping='/myEndpoint/*')
global class MyRestClass {
@HttpGet
global static String doGet() {
return 'Hello World';
}
}Port already in use
Specify a different port:
sf apexswag generate -p 8080Project Structure
apexswag/
βββ src/
β βββ commands/apexswag/ # CLI command
β βββ utils/ # Core utilities
β βββ parser.ts # Apex parsing
β βββ openapi.ts # OpenAPI generation
β βββ server.ts # Documentation server
β βββ sobjectService.ts # SObject schema fetching
βββ ui/ # React documentation UI
βββ test/ # Test suiteLicense
MIT Β© Nishant Mohapatra
Made with β€οΈ for the Salesforce community
