🚀 Add New Service
Overview
Only 2 simple steps to add a new API service to the documentation:
- ✅ Add configuration to
.envfile - ✅ Run 1 single command
Step 1: Configure in .env
Open the .env file (if it doesn't exist, copy from .env.example) and add configuration for the new service:
# Replace YOURSERVICE with service name (e.g., AUTH, REWARDS, CORE)
YOURSERVICE_SWAGGER_JSON_URL=https://backend-dev.nomion.io/yourservice/swagger/json
USERNAME_YOURSERVICE=admin
PASSWORD_YOURSERVICE=your-password
YOURSERVICE_BASE_PATH=/yourservice # Optional - auto-detect from URL
YOURSERVICE_LABEL=Your Service API # Optional - auto-generate from name
Real Example
# Add Auth API
AUTH_SWAGGER_JSON_URL=https://backend-dev.nomion.io/auth/swagger/json
USERNAME_AUTH=admin
PASSWORD_AUTH=secret123
AUTH_BASE_PATH=/auth
AUTH_LABEL=Authentication API
# Add Rewards API
REWARDS_SWAGGER_JSON_URL=https://backend-dev.nomion.io/reward/swagger/doc.json
USERNAME_REWARDS=admin
PASSWORD_REWARDS=nomion@123
REWARDS_BASE_PATH=/reward
REWARDS_LABEL=Rewards API
Step 2: Run Update Command
yarn docs:update
Or if you want to clean everything and rebuild:
yarn docs:rebuild
System Automatically Performs
When you run yarn docs:update, the system will automatically:
- ✅ Fetch swagger JSON from URL (with basic authentication)
- ✅ Enhance swagger file:
- Set correct host, basePath, schemes
- Remove endpoint-level security
- Add global security (Bearer token)
- Fix missing summary/operationId
- ✅ Generate complete API documentation
- ✅ Create tag overview pages for each API group
- ✅ Fix sidebar structure automatically
- ✅ Update navbar menu (auto-detect from examples/)
Result
After completion, the new service will appear:
- 📁 Swagger file:
examples/yourservice.swagger.json - 📚 Docs folder:
docs/api/yourservice/ - 🔗 Navbar menu: Automatically added menu item
- 🔒 Authentication: Full Bearer token support
- 📖 Tag pages: Auto-created overview for each tag
View Result
yarn start
Open browser and visit: http://localhost:3000
Troubleshooting
❌ Error: "No swagger sources found in .env"
Cause: .env file doesn't exist or has no service configuration
Solution:
- Ensure
.envfile exists (copy from.env.example) - Check there's at least 1 service with format:
{NAME}_SWAGGER_JSON_URL
❌ Error: "HTTP 401 Unauthorized" when fetching
Cause: Incorrect username/password
Solution:
- Check if
USERNAME_{SERVICE}andPASSWORD_{SERVICE}are correct - Try logging into swagger URL via browser to verify
❌ API doesn't show Authorization button
Cause: Swagger file hasn't been enhanced
Solution:
yarn swagger:enhance
yarn gen-all-docs
❌ API returns 404 when testing
Cause: Incorrect basePath
Solution:
- Check
{SERVICE}_BASE_PATHin.env - Or leave empty to auto-detect from URL
- Regenerate:
yarn docs:rebuild
❌ Navbar doesn't show new service
Cause: Cache or docs haven't been generated
Solution:
yarn clear
yarn start
Important Notes
✅ Naming Convention
- Service name: Always use UPPERCASE (e.g.,
AUTH, notauth) - File output: Auto-lowercase (e.g.,
auth.swagger.json) - Docs folder: Auto-lowercase (e.g.,
docs/api/auth/)
✅ Bearer Token Format
When testing API in docs, enter token with format:
Bearer your-token-here
Note: Must include "Bearer" prefix with a space before token!
✅ Base Path Detection
If {SERVICE}_BASE_PATH is not set in .env, system will auto-extract from URL:
- URL:
https://backend-dev.nomion.io/auth/swagger/json - Auto basePath:
/auth✅
✅ Clean Cache
If encountering strange errors, always try clearing cache first:
yarn clear
# Or
rm -rf .docusaurus node_modules/.cache
Commands Reference
# Only fetch swagger files
yarn swagger:fetch
# Only enhance swagger files
yarn swagger:enhance
# Fetch + enhance
yarn swagger:update
# Generate docs for all APIs
yarn gen-all-docs
# Clean all API docs
yarn clean-all-docs
# Fix sidebars + create tag pages
yarn sidebar:fix
# Update everything (recommended)
yarn docs:update
# Clean + update + build production
yarn docs:rebuild
Next Steps
After successfully adding a new service:
- ✅ Check API docs in browser
- ✅ Test Authorization with Bearer token
- ✅ Test some endpoints
- ✅ Commit changes to Git (remember to
.gitignorethe.envfile)
Made with ❤️ by Phygital Labs