Skip to content

Commit a3a6ff2

Browse files
feat(prod): Add support for custom budges for preview APIs (#979)
1 parent 7674b5c commit a3a6ff2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tools/cli/internal/openapi/filter/bump.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@ type BumpFilter struct {
2626
metadata *Metadata
2727
}
2828

29+
type State struct {
30+
Label string `json:"label"`
31+
Color string `json:"color"`
32+
}
33+
2934
const (
30-
stateFieldName = "x-state"
31-
stateFieldValueUpcoming = "UPCOMING"
32-
stateFieldValuePreview = "PREVIEW"
33-
betaFieldName = "x-beta"
34-
description = `This API is in preview. Breaking changes might be introduced before it is released. Don't use preview APIs in production.
35+
stateFieldName = "x-state"
36+
stateFieldValueUpcoming = "UPCOMING"
37+
stateFieldValuePreview = "PREVIEW"
38+
stateFieldValuePreviewColor = "#B89D09" // Yellow
39+
betaFieldName = "x-beta"
40+
description = `This API is in preview. Breaking changes might be introduced ` +
41+
`before it is released. Don't use preview APIs in production.
3542
3643
`
3744
)
@@ -71,7 +78,10 @@ func (f *BumpFilter) includeBumpFieldForPreview() error {
7178
if op.Extensions == nil {
7279
op.Extensions = map[string]any{}
7380
}
74-
op.Extensions[stateFieldName] = stateFieldValuePreview
81+
op.Extensions[stateFieldName] = State{
82+
Label: stateFieldValuePreview,
83+
Color: stateFieldValuePreviewColor,
84+
}
7585
op.Extensions[betaFieldName] = true
7686
op.Description = description + " " + op.Description
7787
}

tools/cli/internal/openapi/filter/bump_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ func TestBumpFilter_Apply_Preview(t *testing.T) {
6767

6868
op := testPath.Get
6969
assert.Contains(t, op.Extensions, "x-state")
70-
assert.Equal(t, stateFieldValuePreview, op.Extensions["x-state"])
70+
stateProp := op.Extensions["x-state"].(State)
71+
assert.Equal(t, stateFieldValuePreview, stateProp.Label)
72+
assert.Equal(t, stateFieldValuePreviewColor, stateProp.Color)
7173
assert.Contains(t, op.Extensions, "x-beta")
7274
assert.Equal(t, true, op.Extensions["x-beta"])
7375
assert.Contains(t, op.Description, description)

0 commit comments

Comments
 (0)