Skip to content

Commit e025677

Browse files
fixes
1 parent ff8975d commit e025677

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/getkin/kin-openapi/openapi3"
1919
)
2020

21-
// BumpFilter modifies includes the fields "x-state" and "x-beta" to the "preview" and "upcoming" APIs Paths.
21+
// BumpFilter modifies includes the fields "x-state" and "x-beta" to the "preview" and "upcoming" APIs Operations.
2222
// The "x-state" and "x-beta" fields are bump.sh custom fields to include budges
2323
// Bump.sh feature: https://docs.bump.sh/help/specification-support/doc-badges/
2424
type BumpFilter struct {
@@ -51,22 +51,26 @@ func (f *BumpFilter) Apply() error {
5151

5252
func (f *BumpFilter) includeBumpFieldForUpcoming() error {
5353
for _, p := range f.oas.Paths.Map() {
54-
if p.Extensions == nil {
55-
p.Extensions = map[string]any{}
54+
for _, op := range p.Operations() {
55+
if op.Extensions == nil {
56+
op.Extensions = map[string]any{}
57+
}
58+
op.Extensions[stateFieldName] = stateFieldValueUpcoming
5659
}
57-
p.Extensions[stateFieldName] = stateFieldValueUpcoming
5860
}
5961

6062
return nil
6163
}
6264

6365
func (f *BumpFilter) includeBumpFieldForPreview() error {
6466
for _, p := range f.oas.Paths.Map() {
65-
if p.Extensions == nil {
66-
p.Extensions = map[string]any{}
67+
for _, op := range p.Operations() {
68+
if op.Extensions == nil {
69+
op.Extensions = map[string]any{}
70+
}
71+
op.Extensions[stateFieldName] = stateFieldValuePreview
72+
op.Extensions[betaFieldName] = true
6773
}
68-
p.Extensions[stateFieldName] = stateFieldValuePreview
69-
p.Extensions[betaFieldName] = true
7074
}
7175
return nil
7276
}

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ func TestBumpFilter_Apply_Preview(t *testing.T) {
6363
assert.Contains(t, oas.Paths.Map(), "test")
6464

6565
testPath := oas.Paths.Map()["test"]
66-
assert.Contains(t, testPath.Extensions, "x-state")
67-
assert.Equal(t, "Preview", testPath.Extensions["x-state"])
68-
assert.Contains(t, testPath.Extensions, "x-beta")
69-
assert.Equal(t, true, testPath.Extensions["x-beta"])
66+
assert.NotNil(t, testPath.Get)
67+
68+
op := testPath.Get
69+
assert.Contains(t, op.Extensions, "x-state")
70+
assert.Equal(t, "Preview", op.Extensions["x-state"])
71+
assert.Contains(t, op.Extensions, "x-beta")
72+
assert.Equal(t, true, op.Extensions["x-beta"])
7073
}
7174

7275
func TestBumpFilter_Apply_Upcoming(t *testing.T) {
@@ -106,9 +109,12 @@ func TestBumpFilter_Apply_Upcoming(t *testing.T) {
106109
assert.Contains(t, oas.Paths.Map(), "test")
107110

108111
testPath := oas.Paths.Map()["test"]
109-
assert.Contains(t, testPath.Extensions, "x-state")
110-
assert.Equal(t, "Upcoming", testPath.Extensions["x-state"])
111-
assert.NotContains(t, testPath.Extensions, "x-beta")
112+
assert.NotNil(t, testPath.Get)
113+
op := testPath.Get
114+
115+
assert.Contains(t, op.Extensions, "x-state")
116+
assert.Equal(t, "Upcoming", op.Extensions["x-state"])
117+
assert.NotContains(t, op.Extensions, "x-beta")
112118
}
113119

114120
func TestBumpFilter_Apply_Stable(t *testing.T) {
@@ -148,6 +154,9 @@ func TestBumpFilter_Apply_Stable(t *testing.T) {
148154
assert.Contains(t, oas.Paths.Map(), "test")
149155

150156
testPath := oas.Paths.Map()["test"]
151-
assert.NotContains(t, testPath.Extensions, "x-state")
152-
assert.NotContains(t, testPath.Extensions, "x-beta")
157+
assert.NotNil(t, testPath.Get)
158+
op := testPath.Get
159+
160+
assert.NotContains(t, op.Extensions, "x-state")
161+
assert.NotContains(t, op.Extensions, "x-beta")
153162
}

0 commit comments

Comments
 (0)