APIVersionManager Concept
TheAPIVersionManager coordinates multiple API versions, each with its own:
- APIRegistry — stores endpoints and generates OpenAPI specs
- ASTParser — analyzes Go source for that version’s handlers
- SchemaGenerator — generates component schemas
- Configuration — title, description, status, public Swagger access
Each version gets a separate OpenAPI 3.0.3 spec. Component schemas are pruned per-version — only schemas referenced by that version’s endpoints are included.
VersionedAPIRouter Usage
TheVersionedAPIRouter wraps PocketBase’s router and provides version-aware route registration. It automatically:
- Registers routes to both the runtime router and the documentation registry
- Tracks request/response schemas via AST analysis
- Handles middleware binding (
.Bind()and.BindFunc()) - Extracts path parameters from route patterns
Basic Example
GET, POST, PUT, PATCH, DELETE) returns a *VersionedRouteChain that supports middleware binding.
Managing Multiple API Versions
Version Configurations
APIDocsConfig holds version-specific settings:
Version Status Levels
Real Example from routes.go
Here’s how the demo app initializes a versioned system:Server Registration
The version manager must be registered with the PocketBase app to serve endpoints:- All version routes (e.g.,
/api/v1/todos,/api/v2/time) - Version listing endpoint (
/api/docs/versions) - Per-version OpenAPI endpoints (
/api/docs/v1,/api/docs/v2) - Public Swagger UI endpoints (if
PublicSwagger: true) - Debug AST endpoint (
/api/docs/debug/ast)
Public vs Private Swagger Access
Public Swagger (PublicSwagger: true)
Exposes two endpoints without authentication:
Ideal for public APIs where you want developers to explore the documentation without creating an account.
Private Swagger (PublicSwagger: false)
Requires superuser authentication to access:
Version Endpoints Reference
List All Versions
Response Example
Response Example
Get Version-Specific OpenAPI Spec
Access Swagger UI
PublicSwagger: true. Returns an HTML page with embedded Swagger UI (dark mode CSS included).
Advanced Configuration
Dynamic Server URLs
The system automatically constructs server URLs based on the request:If
BaseURL is not localhost, the configured value is used. This ensures production specs use the correct domain.Custom Version Validation
Version strings are validated when registering:v1, v2, v1.0, v2.0.0, etc.
Migration Workflow
When introducing a new API version:1
Create new version config
Set
Status: "testing" and PublicSwagger: false initially.2
Register routes
Create a new
registerV2Routes() function and add it to the version manager.3
Test internally
Use the authenticated OpenAPI endpoint to validate the spec.
4
Enable public access
Set
PublicSwagger: true and Status: "stable" when ready.5
Deprecate old version
Update v1 to
Status: "deprecated" and add a sunset date to the description.Next Steps
Route Registration
Learn manual and CRUD registration patterns
Annotations Reference
Complete guide to source file directives