WebSwags - API Documentation Server
WebSwags is a lightweight Go web server that provides a modern web interface for viewing OpenAPI/Swagger specifications in your projects.
Features
- π Auto-Discovery: Automatically discovers OpenAPI/Swagger files in
connector/*/spec/ directories
- π Dual Format Support: Supports both YAML (
.yaml, .yml) and JSON (.json) specifications
- π Modern UI: Clean, responsive interface using Swagger UI 5.x
- π·οΈ Format Indicators: Visual badges showing file format (YAML/JSON) for each service
- π Service Listing: Overview page showing all available API services with format information
- π Quick Access: Direct links to each service's documentation
- π― Development Focus: Designed specifically for local development workflow
Installation
Prerequisites
Setup
-
Clone the repository:
git clone https://github.com/Hossein-Roshandel/webswags.git
cd webswags
-
Install dependencies:
go mod download
-
(Optional) Set up development environment:
./setup-dev.sh
Usage
Start the Server
# Build and run
go run main.go -root /path/to/project/root
Command Line Options
-root <directory>: Root directory to search for swagger specifications (default: "..")
Example:
# Use current directory as root
go run main.go -root $(pwd)
# Use specific directory
go run main.go -root /home/user/my-project
Access the Documentation
- Open http://localhost:8085 in your browser
- Browse the list of available API services
- Click on any service to view its Swagger documentation
Architecture
File Structure
webswags/
βββ main.go # Main server application
βββ go.mod # Go module definition with dependencies
βββ go.sum # Dependency checksums
βββ discovery/
β βββ discovery.go # Spec discovery and parsing logic
βββ templates/
β βββ index.html # Main service listing page template
β βββ service.html # Individual service Swagger UI template
βββ README.md # This documentation
Discovery Logic
The server automatically scans for OpenAPI specifications:
- Path Pattern:
{root}/connector/*/spec/*.{yaml,yml,json} (root configurable via -root flag)
- Supported Formats: OpenAPI 3.x and Swagger 2.0 in both YAML and JSON
- Format Detection: Automatic format detection from file extension
- Extraction: Automatically extracts title, version, and description from both YAML and JSON files
API Endpoints
GET / - Main service listing page with format indicators
GET /service/{service} - Swagger UI for specific service (auto-detects format)
GET /api/specs - JSON API listing all discovered specifications (includes format field)
GET /api/specs/{service}/swagger.yaml - Raw YAML file for service
GET /api/specs/{service}/swagger.json - Raw JSON file for service
Development
Adding New Services
WebSwags automatically discovers new services when you add OpenAPI specifications to:
connector/{service-name}/spec/{service-name}.yaml
connector/{service-name}/spec/{service-name}.json
The service will appear in the listing on the next server restart with the appropriate format badge.
Customization
To customize the appearance or functionality:
- Styling: Modify the CSS in the
handleIndex function
- Discovery Logic: Update the
discoverSwaggerSpecs function
- UI Layout: Modify the HTML templates in the handlers
Dependencies
- Go 1.25+: Required for building and running
- gorilla/mux: HTTP router for handling requests
- kin-openapi: OpenAPI 3.x specification parsing
- go-openapi/spec: Swagger 2.0 specification parsing
- sigs.k8s.io/yaml: YAML processing utilities
- golang.org/x/text: Text processing and case conversion
- Swagger UI: Loaded via CDN (unpkg.com)
License
This project is licensed under the MIT License - see the LICENSE file for details.
No Services Found
If no services are discovered:
- Check that YAML files exist in
connector/*/spec/ directories
- Ensure YAML files contain valid
openapi: or swagger: declarations
- Verify file permissions allow reading
- Check server logs for parsing errors
Service Not Loading
If a specific service won't load:
- Verify the YAML file is valid OpenAPI/Swagger format
- Check the file path matches the pattern
connector/{service}/spec/{service}.yaml
- Look for parsing errors in server logs
Port Already in Use
If port 8085 is already in use:
- Stop other services using the port
- Or modify the
port constant in main.go
- Update the Makefile accordingly