This document summarizes the implementation of OpenAPI/Swagger documentation for the Scopeon Server API, enabling frontend developers to have comprehensive API documentation and contract specifications.
route-first-openapi-architecture.md for the new approach.
File: src/web/api/openapi.rs (Legacy)
- utoipa crate integration for automatic OpenAPI generation
- Comprehensive API documentation structure with proper metadata
- Security schemes for both session-based (frontend) and API key (desktop agents) authentication
- Response templates for standardized error handling
- Pagination support for list endpoints
File: src/web/api/handlers/health.rs
All health check endpoints now include complete OpenAPI annotations:
GET /health- Basic health checkGET /health/detailed- Detailed service statusGET /health/ready- Kubernetes readiness probeGET /health/live- Kubernetes liveness probe
File: src/web/auth.rs
REST API authentication endpoints with full documentation:
POST /auth/api/login- User login with credentialsPOST /auth/api/logout- User logoutGET /auth/api/me- Current user information
Files: src/domain/*/models.rs
Updated core domain models with ToSchema annotations:
- User Management:
User,UserRole,UserStatus - Health Models:
HealthResponse,ServiceStatus,ServiceHealth - API Models:
ApiResponse<T>,ApiError,PaginationInfo
Files: src/web/auth.rs, src/web/api/models.rs
Documented data transfer objects:
- Authentication:
LoginForm,LoginResponse,UserInfo - Generic API responses with proper typing and validation schemas
File: src/web/routing.rs
Added OpenAPI endpoints to the server with HTTPS support:
- Swagger UI:
https://localhost:8080/swagger-ui/(default HTTPS) orhttp://localhost:8080/swagger-ui/(when TLS disabled) - OpenAPI JSON:
https://localhost:8080/api-docs/openapi.json(default HTTPS) orhttp://localhost:8080/api-docs/openapi.json(when TLS disabled)
File: src/infrastructure/tls.rs
TLS/HTTPS support with security features:
- Self-signed certificate generation for development
- Custom certificate loading for production
- Secure session cookies with HttpOnly, SameSite=Lax, Secure flags
- CORS configuration compliant with credential security requirements
Enhanced server startup logs to include documentation URLs, authentication information, and TLS status.
https://localhost:8080/swagger-ui/ (Default - HTTPS with TLS enabled)
http://localhost:8080/swagger-ui/ (Fallback - HTTP when ENABLE_TLS=false)
Features:
- Interactive API exploration
- Request/response testing
- Schema visualization
- Authentication testing interface
- Secure HTTPS access with session cookies
https://localhost:8080/api-docs/openapi.json (Default HTTPS)
http://localhost:8080/api-docs/openapi.json (HTTP when TLS disabled)
Features:
- Machine-readable API contract
- Complete schema definitions
- Authentication schemes
- Endpoint specifications
- Cookie-based session management
- Login/logout endpoints
- User information retrieval
- Role-based authorization
- Header-based API key authentication
- WebSocket connection support
- Programmatic access patterns
- Development: Self-signed certificates generated automatically
- Production: Custom certificate loading with proper validation
- Session Security: HttpOnly, SameSite=Lax, Secure cookies for HTTPS
- CORS Security: Credential-safe CORS configuration with specific origins
- session_auth: Cookie-based authentication for Angular frontend
- api_key: Header-based authentication for desktop agents
- Credentials Enabled: Supports session cookies for frontend authentication
- Allowed Origins: Specific origins (localhost:4200) instead of wildcard for security
- Allowed Methods: GET, POST, PUT, DELETE, PATCH, OPTIONS
- Allowed Headers: Authorization, Content-Type, X-Requested-With, Accept, Origin, X-CSRF-Token
- HostOwner: Basic host management
- SecurityAnalyst: Vulnerability analysis
- SecurityManager: Security oversight
- SystemAdmin: Full system access
The OpenAPI configuration is prepared for future endpoint documentation:
- User Management: CRUD operations for user management
- Host Management: Host registration, status, and monitoring
- Vulnerability Management: CVE analysis and reporting
- Software Inventory: Software detection and management
- Report Generation: Security report creation and export
- Add endpoint handler with
#[utoipa::path]annotations - Include handler in
ApiDocpaths section - Add response/request models to schemas section
- Update routing configuration
- Clear API contracts and specifications
- Interactive testing environment
- Automatic client library generation support
- Real-time API exploration
- Automatic documentation generation
- Schema validation enforcement
- Standardized response formats
- Development-time API contract verification
- Interactive API testing interface
- Clear endpoint specifications
- Authentication flow documentation
- Response format validation
# Login request (HTTPS when enabled)
curl -X POST https://localhost:8080/auth/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin_password"}' \
--insecure # Only for self-signed certificates in development
# Get current user info
curl https://localhost:8080/auth/api/me \
-H "Cookie: session=<session_token>" \
--insecure # Only for self-signed certificates in development# Basic health check (HTTPS when enabled)
curl https://localhost:8080/health --insecure
# Detailed health status (adjust protocol based on ENABLE_TLS)
curl https://localhost:8080/health --insecureThe OpenAPI documentation system is now fully operational and provides:
✅ Complete API Documentation - All current endpoints documented with schemas
✅ Interactive Testing - Swagger UI for development and testing
✅ HTTPS Security - TLS encryption with secure session management
✅ CORS Compliance - Credential-safe CORS configuration
✅ Authentication Integration - Both session and API key auth documented
✅ Extensible Architecture - Ready for future endpoint additions
✅ Developer Experience - Clear contracts for frontend development
✅ Standardized Responses - Consistent API response formats
This implementation enables the frontend team to begin development with clear API specifications while the backend continues to evolve, supporting the co-development strategy outlined in the project architecture.
- Co-located Documentation: Routes and OpenAPI docs are defined together
- Automatic Synchronization: No more manual maintenance of two separate systems
- Compile-time Safety: Impossible to have routes without documentation
- Modular Organization: Each API domain is self-contained
- Legacy Documentation:
/swagger-ui/(existing endpoints) - New Architecture Demo:
/swagger-ui-modular/(migrated modules) - Legacy JSON:
/api-docs/openapi.json - New JSON:
/api-docs/openapi-modular.json
See route-first-openapi-architecture.md for complete details on the new architecture and migration strategy.