diff --git a/internal/simplebuild/build.go b/internal/simplebuild/build.go index 37d73c5b..8b5cc42e 100644 --- a/internal/simplebuild/build.go +++ b/internal/simplebuild/build.go @@ -337,7 +337,7 @@ func (vs VersionSet) Annotate() { op.Operation.Extensions[vervet.ExtSnykApiVersion] = op.Version.String() op.Operation.Extensions[vervet.ExtSnykApiReleases] = releases op.Operation.Extensions[vervet.ExtSnykApiLifecycle] = op.Version.LifecycleAt(time.Time{}).String() - op.Operation.Extensions[vervet.ExtApiStabilityLevel] = op.Version.Stability.String() + op.Operation.Extensions[vervet.ExtApiStabilityLevel] = MapStabilityLevel(op.Version.Stability) op.Operation.Extensions[vervet.ExtSnykApiStability] = op.Version.Stability.String() if idx < (count - 1) { @@ -355,6 +355,18 @@ func (vs VersionSet) Annotate() { } } +// MapStabilityLevel maps the vervet stability level to the x-API stability level header. +func MapStabilityLevel(s vervet.Stability) string { + switch s { + case vervet.StabilityGA: + return "stable" + case vervet.StabilityBeta: + return "beta" + default: + return "" + } +} + func CheckBreakingChanges(docs DocSet) error { for i := 1; i < len(docs); i++ { prevDoc := docs[i-1] diff --git a/internal/simplebuild/build_test.go b/internal/simplebuild/build_test.go index 98fde81b..b2a70993 100644 --- a/internal/simplebuild/build_test.go +++ b/internal/simplebuild/build_test.go @@ -700,3 +700,34 @@ func compareDocs(a, b simplebuild.VersionedDoc) int { func compareDates(a, b time.Time) int { return a.Compare(b) } + +func TestMapStabilityLevel(t *testing.T) { + tests := []struct { + name string + args vervet.Stability + want string + }{ + { + name: "stable", + args: vervet.StabilityGA, + want: "stable", + }, + { + name: "beta", + args: vervet.StabilityBeta, + want: "beta", + }, + { + name: "defaults to blank", + args: vervet.StabilityExperimental, + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := simplebuild.MapStabilityLevel(tt.args); got != tt.want { + t.Errorf("MapStabilityLevel() = %v, want %v", got, tt.want) + } + }) + } +}