Conversation
…closes #59) Replace two concrete type assertions in cmd/server/main.go with interface checks: 1. svc.(*module.OpenAPIGenerator) → svc.(interfaces.SchemaRegistrar) - Define SchemaRegistrar in interfaces/ with Name(), RegisterAdminSchemas(), ApplySchemas() methods - Add RegisterAdminSchemas() method to *OpenAPIGenerator that delegates to the package-level RegisterAdminSchemas function - Add compile-time check: var _ interfaces.SchemaRegistrar = (*OpenAPIGenerator)(nil) 2. svc.(*module.WorkflowRegistry) → svc.(interfaces.WorkflowStoreProvider) - Define WorkflowStoreProvider in interfaces/ with Name() and WorkflowStore() any - Add WorkflowStore() any method to *WorkflowRegistry returning the store opaquely (avoids interfaces→module circular import) - Add compile-time check: var _ interfaces.WorkflowStoreProvider = (*WorkflowRegistry)(nil) No behaviour is changed; only the mechanism for identifying capable services is updated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces capability interfaces to decouple server startup code from concrete module types, replacing 2 of the 15+ type assertions mentioned in issue #59. The change establishes a pattern where modules opt into interfaces rather than having the server depend on specific concrete types, improving plugin isolation and modularity.
Changes:
- Adds two new capability interfaces (
SchemaRegistrarandWorkflowStoreProvider) in theinterfaces/package - Updates
OpenAPIGeneratorandWorkflowRegistrymodules to satisfy these interfaces with compile-time assertions - Replaces concrete type assertions in
cmd/server/main.gowith interface-based checks
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| interfaces/registry.go | Defines new SchemaRegistrar and WorkflowStoreProvider capability interfaces for decoupling server from concrete module types |
| module/openapi_generator.go | Adds RegisterAdminSchemas() method and compile-time assertion to satisfy SchemaRegistrar interface |
| module/workflow_registry.go | Adds WorkflowStore() method and compile-time assertion to satisfy WorkflowStoreProvider interface |
| cmd/server/main.go | Replaces concrete type assertions with interface checks for OpenAPIGenerator and WorkflowRegistry |
Comments suppressed due to low confidence (2)
cmd/server/main.go:503
- The WorkflowStore() method can return nil if the WorkflowRegistry hasn't been started yet or if Start() failed. This code should check for nil before attempting the type assertion to *module.V1Store. Consider adding a nil check:
if provider, ok := svc.(interfaces.WorkflowStoreProvider); ok {
workflowStore := provider.WorkflowStore()
if workflowStore == nil {
continue
}
if s, ok := workflowStore.(*module.V1Store); ok {
store = s
logger.Info("Using WorkflowRegistry store", "module", provider.Name())
break
}
} if provider, ok := svc.(interfaces.WorkflowStoreProvider); ok {
if s, ok := provider.WorkflowStore().(*module.V1Store); ok {
interfaces/registry.go:34
- The WorkflowStore() documentation should mention that it may return nil if the store hasn't been initialized yet. This would help callers understand they need to perform nil checks. Consider updating the comment to:
"WorkflowStore returns the underlying workflow data store as an opaque value, or nil if the store has not been initialized. The caller is responsible for checking for nil and asserting the concrete type (typically *module.V1Store) when further operations are required."
// WorkflowStore returns the underlying workflow data store as an opaque
// value. The caller is responsible for asserting the concrete type
// (typically *module.V1Store) when further operations are required.
WorkflowStore() any
Summary
interfaces/package (SchemaRegistrarandWorkflowStoreProvider) that modules opt into, replacing direct concrete type assertions incmd/server/main.gosvc.(*module.OpenAPIGenerator)withsvc.(interfaces.SchemaRegistrar)— the server no longer needs to know the specific module type to enrich the OpenAPI specsvc.(*module.WorkflowRegistry)withsvc.(interfaces.WorkflowStoreProvider)— the server no longer needs to know the specific module type to discover the workflow data storeRegisterAdminSchemas()method to*OpenAPIGeneratorandWorkflowStore() anymethod to*WorkflowRegistryso they satisfy the new interfacesvar _ interfaces.X = (*ConcreteType)(nil)) in both module files to catch regressions earlyTest plan
go build ./...passesgo test ./...passes (all packages)golangci-lint runreports 0 issuescloses #59
🤖 Generated with Claude Code