Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions tools/cli/internal/openapi/filter/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ type BumpFilter struct {
metadata *Metadata
}

type State struct {
Label string `json:"label"`
Color string `json:"color"`
}

const (
stateFieldName = "x-state"
stateFieldValueUpcoming = "UPCOMING"
stateFieldValuePreview = "PREVIEW"
betaFieldName = "x-beta"
description = `This API is in preview. Breaking changes might be introduced before it is released. Don't use preview APIs in production.
stateFieldName = "x-state"
stateFieldValueUpcoming = "UPCOMING"
stateFieldValuePreview = "PREVIEW"
stateFieldValuePreviewColor = "#B89D09" // Yellow
betaFieldName = "x-beta"
description = `This API is in preview. Breaking changes might be introduced ` +
`before it is released. Don't use preview APIs in production.

`
)
Expand Down Expand Up @@ -71,7 +78,10 @@ func (f *BumpFilter) includeBumpFieldForPreview() error {
if op.Extensions == nil {
op.Extensions = map[string]any{}
}
op.Extensions[stateFieldName] = stateFieldValuePreview
op.Extensions[stateFieldName] = State{
Label: stateFieldValuePreview,
Color: stateFieldValuePreviewColor,
}
op.Extensions[betaFieldName] = true
op.Description = description + " " + op.Description
}
Expand Down
4 changes: 3 additions & 1 deletion tools/cli/internal/openapi/filter/bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ func TestBumpFilter_Apply_Preview(t *testing.T) {

op := testPath.Get
assert.Contains(t, op.Extensions, "x-state")
assert.Equal(t, stateFieldValuePreview, op.Extensions["x-state"])
stateProp := op.Extensions["x-state"].(State)
assert.Equal(t, stateFieldValuePreview, stateProp.Label)
assert.Equal(t, stateFieldValuePreviewColor, stateProp.Color)
assert.Contains(t, op.Extensions, "x-beta")
assert.Equal(t, true, op.Extensions["x-beta"])
assert.Contains(t, op.Description, description)
Expand Down
Loading