Skip to content

Swagger API Documentation

LeafLock provides comprehensive OpenAPI 3.0 (Swagger) documentation for all REST API endpoints. This documentation is interactive, automatically generated from code annotations, and includes request/response examples.

Public Swagger UI

Production: https://leaflock.app/swagger

Local: http://localhost:8080/swagger

Browse and test API endpoints directly in your browser with the Swagger UI interface.

API Documentation

Production: https://leaflock.app/api/v1/docs

Local: http://localhost:8080/api/v1/docs

Alternative Swagger UI path under the /api/v1 prefix.

OpenAPI JSON (Public)

Production: https://leaflock.app/swagger/openapi.json

Local: http://localhost:8080/swagger/openapi.json

Machine-readable OpenAPI 3.0 specification for API clients and code generation tools.

OpenAPI JSON (API)

Production: https://leaflock.app/api/v1/docs/openapi.json

Local: http://localhost:8080/api/v1/docs/openapi.json

Alternative OpenAPI spec path under the /api/v1 prefix.

Primary URL: https://leaflock.app/swagger

Test API endpoints directly from the Swagger UI:

  1. Click on any endpoint
  2. Click “Try it out”
  3. Fill in request parameters
  4. Execute to see live responses

Authenticate your Swagger UI session:

  1. Click the Authorize button (top right)
  2. Enter: Bearer YOUR_JWT_TOKEN
  3. Click “Authorize”
  4. Your token is now included in all requests

View detailed schemas for:

  • Request bodies
  • Response bodies
  • Query parameters
  • Path parameters
  • Headers

Each endpoint includes:

  • Summary - Brief description
  • Description - Detailed explanation
  • Tags - Organized by functionality
  • Security - Authentication requirements
  • Examples - Sample requests and responses

Tag: Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Authenticate user
  • POST /auth/logout - End session
  • POST /auth/refresh - Refresh JWT token
  • GET /auth/mfa/status - Check MFA status
  • POST /auth/mfa/setup - Setup MFA
  • POST /auth/mfa/verify - Verify MFA code
  • POST /auth/mfa/disable - Disable MFA

The OpenAPI specification is available in multiple formats:

/api/v1/docs/openapi.json

Size: ~13KB Use: API clients, code generators, validation tools

/api/v1/docs/swagger.yaml

Size: ~5.7KB Use: Human-readable format, easier to diff

/api/v1/docs/swagger.json

Size: ~11.6KB Use: Tools that require Swagger 2.0 instead of OpenAPI 3.0

Generate API clients from the OpenAPI spec:

Terminal window
# Using openapi-generator-cli
npx @openapitools/openapi-generator-cli generate \
-i http://localhost:8080/api/v1/docs/openapi.json \
-g typescript-fetch \
-o ./generated-client

LeafLock uses swaggo/swag to generate Swagger documentation from code annotations:

// @Summary Register a new user
// @Description Register a new user with email and password
// @Tags Authentication
// @Accept json
// @Produce json
// @Param request body RegisterRequest true "Registration data"
// @Success 201 {object} RegisterResponse "User registered successfully"
// @Failure 400 {object} ErrorResponse "Invalid request"
// @Failure 409 {object} ErrorResponse "Email already exists"
// @Router /auth/register [post]
func (h *AuthHandler) Register(c *fiber.Ctx) error {
// Implementation
}

The Swagger UI is served at /api/v1/docs via embedded HTML:

backend/swagger.go
func swaggerUIHandler(c *fiber.Ctx) error {
const tpl = `<!doctype html>
<html>
<head>
<title>LeafLock API Docs</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
<script>
SwaggerUIBundle({
url: '/api/v1/docs/openapi.json',
dom_id: '#swagger-ui',
});
</script>
</body>
</html>`
// ...
}

To regenerate Swagger docs after adding/modifying endpoints:

Terminal window
cd backend
swag init --parseDependency --parseInternal --output ./docs/swagger

This scans all @ annotations in Go files and generates:

  • docs.go - Embedded docs for the Go binary
  • swagger.json - Swagger 2.0 format
  • swagger.yaml - YAML format
  • OpenAPI 3.0 conversion (via backend transformation)

The API uses JWT Bearer authentication:

securityDefinitions:
BearerAuth:
type: apiKey
name: Authorization
in: header
description: 'Type "Bearer" followed by a space and JWT token.'
  1. Obtain JWT token via POST /auth/login
  2. Click Authorize in Swagger UI
  3. Enter: Bearer eyJhbGciOiJIUzI1...
  4. Click Authorize

All subsequent requests will include the Authorization header automatically.

CodeMeaningWhen It Occurs
200OKSuccessful GET/PUT request
201CreatedSuccessful POST (resource created)
204No ContentSuccessful DELETE
400Bad RequestInvalid request body or parameters
401UnauthorizedMissing or invalid JWT token
403ForbiddenValid token but insufficient permissions
404Not FoundResource doesn’t exist
409ConflictDuplicate resource (e.g., email already registered)
500Internal Server ErrorServer-side error
Terminal window
# Get OpenAPI spec
curl http://localhost:8080/api/v1/docs/openapi.json
# Test endpoint with JWT
curl -H "Authorization: Bearer YOUR_TOKEN" \
http://localhost:8080/api/v1/notes

Validate the OpenAPI spec:

Terminal window
# Using swagger-cli
npx swagger-cli validate http://localhost:8080/api/v1/docs/openapi.json
# Using openapi-generator-cli
npx @openapitools/openapi-generator-cli validate \
-i http://localhost:8080/api/v1/docs/openapi.json
  1. Explore the API: Visit /api/v1/docs in your browser
  2. Generate a client: Use openapi-generator with your language of choice
  3. Integrate: Use the generated client in your application
  4. Contribute: Add annotations to new endpoints following existing patterns