README
ΒΆ
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
- π CORS Proxy: Built-in proxy server to bypass CORS restrictions when testing API endpoints
- π― Development Focus: Designed specifically for local development workflow
Installation
Prerequisites
- Go 1.25 or later
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-rootflag) - 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 indicatorsGET /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 serviceGET /api/specs/{service}/swagger.json- Raw JSON file for serviceGET|POST|PUT|PATCH|DELETE /proxy?url={encoded-url}- CORS proxy endpoint for API requests
CORS Proxy
The built-in CORS proxy allows you to test API endpoints directly from Swagger UI without encountering CORS (Cross-Origin Resource Sharing) restrictions. This is especially useful when:
- Testing APIs hosted on different domains
- Working with APIs that don't have CORS headers configured
- Making requests to production/test servers from your local environment
How it works:
- When you make a request from Swagger UI to an external API, the request is automatically intercepted
- The request is proxied through the WebSwags server at
/proxy?url={target-url} - The server makes the request on your behalf (server-to-server, no CORS restrictions)
- The response is returned to your browser with appropriate CORS headers
Usage:
The proxy is transparent - just use the "Try it out" feature in Swagger UI normally. The application automatically routes external requests through the proxy.
You can also use the proxy directly:
# Direct proxy usage
curl "http://localhost:8085/proxy?url=https%3A%2F%2Fapi.example.com%2Fendpoint"
Note: The proxy adds Access-Control-Allow-Origin: * headers to all responses, allowing the Swagger UI to function properly.
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
handleIndexfunction - Discovery Logic: Update the
discoverSwaggerSpecsfunction - 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:orswagger: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
portconstant inmain.go - Update the Makefile accordingly
Documentation
ΒΆ
There is no documentation for this package.