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) + } +}