From eaa35fb718adc6d5c3998873502f3ac295f591a2 Mon Sep 17 00:00:00 2001 From: Snider Date: Thu, 29 Jan 2026 03:15:08 +0000 Subject: [PATCH] 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 --- pkg/sdk/sdk.go | 10 ++++++++++ pkg/sdk/sdk_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 pkg/sdk/sdk_test.go diff --git a/pkg/sdk/sdk.go b/pkg/sdk/sdk.go index 710c8786..1ed43fc1 100644 --- a/pkg/sdk/sdk.go +++ b/pkg/sdk/sdk.go @@ -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{ diff --git a/pkg/sdk/sdk_test.go b/pkg/sdk/sdk_test.go new file mode 100644 index 00000000..24cc7005 --- /dev/null +++ b/pkg/sdk/sdk_test.go @@ -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) + } +}