Quick Start
Generate Spec File
app/ directory and generates openapi.json.
Serve Swagger UI
http://localhost:8080/docs.
Runtime Integration
CLI Commands
fuego openapi generate
Generate an OpenAPI specification file from your routes. Usage:| Flag | Short | Default | Description |
|---|---|---|---|
--output | -o | openapi.json | Output file path |
--format | -f | json | Output format (json or yaml) |
--title | Project name | API title | |
--version | 1.0.0 | API version | |
--description | API description | ||
--server | Server URL (e.g., http://localhost:3000) | ||
--app-dir | -d | app | App directory to scan |
--openapi30 | false | Use OpenAPI 3.0.3 instead of 3.1.0 | |
--json | false | JSON output for tooling |
fuego openapi serve
Start a local server with Swagger UI for interactive API exploration. Usage:| Flag | Short | Default | Description |
|---|---|---|---|
--port | -p | 8080 | Port to serve on |
--spec | Use existing spec file | ||
--app-dir | -d | app | App directory to scan |
--title | Project name | API title | |
--version | 1.0.0 | API version |
Runtime API
ServeOpenAPI
Add OpenAPI endpoints to your running application.Automatic Documentation
Fuego extracts documentation from your code automatically:From Comments
Add comments above handler functions for operation summaries and descriptions:- Summary:
"Get returns a user by ID" - Description:
"Retrieves a single user from the database..."
- First line → Summary (short description)
- Remaining lines → Description (detailed explanation)
- Blank lines separate summary from description
From File Structure
Tags are automatically derived from your directory structure:| File Path | Generated Tags |
|---|---|
app/api/users/route.go | ["users"] |
app/api/admin/settings/route.go | ["admin"] |
app/api/v2/products/route.go | ["products"] |
app/api/posts/[id]/route.go | ["posts"] |
[id] and route groups like (admin) are ignored when deriving tags.
From URL Parameters
Path parameters are automatically detected from dynamic segments:Request Bodies
For POST, PUT, and PATCH methods, Fuego automatically adds request body schemas:Response Status Codes
Default responses are added based on the HTTP method:| Method | Status Codes |
|---|---|
GET | 200 (Success), 404 (Not Found for paths with params) |
POST | 200 (Success), 400 (Bad Request) |
PUT | 200 (Success), 400 (Bad Request), 404 (Not Found) |
PATCH | 200 (Success), 400 (Bad Request), 404 (Not Found) |
DELETE | 200 (Success), 404 (Not Found) |
Generated Spec Example
Given this route structure:openapi.json:
Integration with Tools
Postman
Import the generatedopenapi.json directly into Postman:
- Open Postman
- Click Import
- Select your
openapi.jsonfile - Postman creates a collection with all routes
Code Generation
Generate client SDKs usingoapi-codegen:
API Gateways
Many API gateways support OpenAPI import:- AWS API Gateway - Import spec to create routes
- Kong - Use OpenAPI plugin for automatic configuration
- Azure API Management - Import spec directly
Documentation Sites
Host documentation with tools like:- Swagger UI - Interactive API explorer (built-in with
fuego openapi serve) - Redoc - Clean, responsive documentation
- Stoplight - API design and documentation platform
Configuration File
You can also configure OpenAPI generation infuego.yaml:
Best Practices
1. Add meaningful comments
1. Add meaningful comments
Write clear, concise comments above your handlers. The first line becomes the operation summary in Swagger UI.
2. Use descriptive function names
2. Use descriptive function names
Handler function names (Get, Post, etc.) map directly to HTTP methods, but your comments should describe what the operation does.
3. Regenerate on changes
3. Regenerate on changes
Always regenerate your spec before deployment:
4. Version your API
4. Version your API
Use semantic versioning and update the version in your spec:
5. Serve docs in development
5. Serve docs in development
Enable OpenAPI in development for easier testing:
Troubleshooting
OpenAPI spec is empty
OpenAPI spec is empty
Problem: Generated spec has no paths.Solution:
- Ensure
app/directory exists - Check that route files are named
route.go - Verify handler functions match HTTP method names (Get, Post, etc.)
- Run
fuego routesto see if routes are detected
Comments not appearing
Comments not appearing
Wrong tags generated
Wrong tags generated
Swagger UI not loading
Swagger UI not loading
Problem:
/docs endpoint returns blank page.Solution:- Check browser console for errors
- Ensure
/openapi.jsonendpoint returns valid JSON - Check CORS headers if accessing from different origin
//style comments (not/* */)