feat(sdk): add SetVersion method for release integration

Add version field to SDK struct and SetVersion method that updates both
the internal version and the config's Package.Version. This enables the
release system to pass version information to SDK generators.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Snider 2026-01-29 03:15:08 +00:00
parent 6ac40d93ac
commit eaa35fb718
2 changed files with 40 additions and 0 deletions

View file

@ -53,6 +53,7 @@ type PublishConfig struct {
type SDK struct {
config *Config
projectDir string
version string
}
// New creates a new SDK instance.
@ -66,6 +67,15 @@ func New(projectDir string, config *Config) *SDK {
}
}
// SetVersion sets the SDK version for generation.
// This updates both the internal version field and the config's Package.Version.
func (s *SDK) SetVersion(version string) {
s.version = version
if s.config != nil {
s.config.Package.Version = version
}
}
// DefaultConfig returns sensible defaults for SDK configuration.
func DefaultConfig() *Config {
return &Config{

30
pkg/sdk/sdk_test.go Normal file
View file

@ -0,0 +1,30 @@
package sdk
import (
"testing"
)
func TestSDK_Good_SetVersion(t *testing.T) {
s := New("/tmp", nil)
s.SetVersion("v1.2.3")
if s.version != "v1.2.3" {
t.Errorf("expected version v1.2.3, got %s", s.version)
}
}
func TestSDK_Good_VersionPassedToGenerator(t *testing.T) {
config := &Config{
Languages: []string{"typescript"},
Output: "sdk",
Package: PackageConfig{
Name: "test-sdk",
},
}
s := New("/tmp", config)
s.SetVersion("v2.0.0")
if s.config.Package.Version != "v2.0.0" {
t.Errorf("expected config version v2.0.0, got %s", s.config.Package.Version)
}
}