feat(sdk): add Generator interface and Registry
Defines the common interface for SDK generators with: - Generate(), Available(), Install() methods - Registry for managing multiple generators Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c2b1e5dc61
commit
656ff728ff
1 changed files with 67 additions and 0 deletions
67
pkg/sdk/generators/generator.go
Normal file
67
pkg/sdk/generators/generator.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
// Package generators provides SDK code generators for different languages.
|
||||
package generators
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Options holds common generation options.
|
||||
type Options struct {
|
||||
// SpecPath is the path to the OpenAPI spec file.
|
||||
SpecPath string
|
||||
// OutputDir is where to write the generated SDK.
|
||||
OutputDir string
|
||||
// PackageName is the package/module name.
|
||||
PackageName string
|
||||
// Version is the SDK version.
|
||||
Version string
|
||||
}
|
||||
|
||||
// Generator defines the interface for SDK generators.
|
||||
type Generator interface {
|
||||
// Language returns the generator's target language identifier.
|
||||
Language() string
|
||||
|
||||
// Generate creates SDK from OpenAPI spec.
|
||||
Generate(ctx context.Context, opts Options) error
|
||||
|
||||
// Available checks if generator dependencies are installed.
|
||||
Available() bool
|
||||
|
||||
// Install returns instructions for installing the generator.
|
||||
Install() string
|
||||
}
|
||||
|
||||
// Registry holds available generators.
|
||||
type Registry struct {
|
||||
generators map[string]Generator
|
||||
}
|
||||
|
||||
// NewRegistry creates a registry with all available generators.
|
||||
func NewRegistry() *Registry {
|
||||
r := &Registry{
|
||||
generators: make(map[string]Generator),
|
||||
}
|
||||
// Generators will be registered in subsequent tasks
|
||||
return r
|
||||
}
|
||||
|
||||
// Get returns a generator by language.
|
||||
func (r *Registry) Get(lang string) (Generator, bool) {
|
||||
g, ok := r.generators[lang]
|
||||
return g, ok
|
||||
}
|
||||
|
||||
// Register adds a generator to the registry.
|
||||
func (r *Registry) Register(g Generator) {
|
||||
r.generators[g.Language()] = g
|
||||
}
|
||||
|
||||
// Languages returns all registered language identifiers.
|
||||
func (r *Registry) Languages() []string {
|
||||
langs := make([]string, 0, len(r.generators))
|
||||
for lang := range r.generators {
|
||||
langs = append(langs, lang)
|
||||
}
|
||||
return langs
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue