Overview
TheAPIVersionManager orchestrates versioned API documentation by maintaining isolated registries, parsers, and configurations for each API version. It enables side-by-side deployment of multiple API versions with automatic OpenAPI spec generation and Swagger UI support.
Type Definition
Each API version gets its own isolated
ASTParser, SchemaGenerator, and APIRegistry. This ensures complete separation between versions with independent component schemas and route registrations.Constructor Functions
NewAPIVersionManager
*APIVersionManager- New manager instance
NewAPIVersionManagerWithDefault
string
required
Version identifier to use as default (e.g., “v1”, “v2”)
Version Management
RegisterVersion
string
required
Version identifier (e.g., “v1”, “v2”, “beta”)
*APIDocsConfig
Version-specific configuration (can be nil for defaults)
error- Error if version already exists or validation fails
- Validates version string format
- Creates version-specific AST parser and schema generator
- Creates isolated API registry for the version
- Sets version-specific server URL in OpenAPI spec
- Automatically becomes default version if first registered
RemoveVersion
string
required
Version identifier to remove
GetVersionConfig
core/server/api/version_manager.go:198
GetVersionRegistry
core/server/api/version_manager.go:209
Route Registration
SetVersionRouteRegistrar
string
required
Version identifier
func(*VersionedAPIRouter)
required
Function that registers routes for this version
RegisterAllVersionRoutes
core/server/api/version_manager.go:300
RegisterAllVersionRoutesForDocs
core/server/api/version_manager.go:315
Version Information
GetDefaultVersion
SetDefaultVersion
GetAllVersions
GetVersionInfo
core/server/api/version_manager.go:650
HTTP Handlers
RegisterWithServer
GET /api/docs/versions- List all versions (requires auth)GET /api/docs/debug/ast- AST pipeline introspection (requires auth)GET /api/docs/{version}- Version-specific OpenAPI spec (requires auth)GET /api/docs/{version}/spec- Public OpenAPI spec (if PublicSwagger enabled)GET /api/docs/{version}/swagger- Swagger UI (if PublicSwagger enabled)GET /api/{version}/schema/config- Schema configuration (requires auth)
core/server/api/version_manager.go:706
VersionsHandler
core/server/api/version_manager.go:756
GetVersionOpenAPI
- Direct spec loading from disk (if available)
- Fallback to runtime registry generation
core/server/api/version_manager.go:827
ServeSwaggerUI
core/server/api/version_manager.go:898
Uses SwaggerDark theme by Amoenus (MIT License) for automatic dark mode support based on user’s system preferences.
Complete Example
Best Practices
- Version Naming: Use semantic versions (“v1”, “v2”) or descriptive names (“stable”, “beta”)
- Default Version: Always set a stable version as default
- Public Access: Only enable
PublicSwaggerfor stable, production-ready versions - Route Isolation: Use
SetPrefix()to namespace each version’s routes - Deprecation: Mark old versions with
Status: "deprecated"before removal - Testing: Use
RegisterAllVersionRoutesForDocs()for build-time spec generation
Related
- VersionedAPIRouter - Version-specific route registration
- APIRegistry - Per-version endpoint registry
- SpecGenerator - Build-time spec generation