Skip to content

Commit feac427

Browse files
add support for team
1 parent 9a59569 commit feac427

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

tools/cli/internal/openapi/sunset.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import (
2222
const (
2323
sunsetExtensionName = "x-sunset"
2424
apiVersionExtensionName = "x-xgen-version"
25+
teamExtensionName = "x-xgen-owner-team"
2526
)
2627

2728
type Sunset struct {
2829
Operation string `json:"http_method" yaml:"http_method"`
2930
Path string `json:"path" yaml:"path"`
3031
Version string `json:"version" yaml:"version"`
3132
SunsetDate string `json:"sunset_date" yaml:"sunset_date"`
33+
Team string `json:"team" yaml:"team"`
3234
}
3335

3436
func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
@@ -37,6 +39,7 @@ func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
3739

3840
for path, pathBody := range paths.Map() {
3941
for operationName, operationBody := range pathBody.Operations() {
42+
teamName := newTeamNameFromOperation(operationBody)
4043
extensions := newExtensionsFrom2xxResponse(operationBody.Responses.Map())
4144
if extensions == nil {
4245
continue
@@ -57,6 +60,7 @@ func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
5760
Path: path,
5861
SunsetDate: sunsetExt.(string),
5962
Version: apiVersion.(string),
63+
Team: teamName,
6064
}
6165

6266
sunsets = append(sunsets, &sunset)
@@ -66,6 +70,13 @@ func NewSunsetListFromSpec(spec *load.SpecInfo) []*Sunset {
6670
return sunsets
6771
}
6872

73+
func newTeamNameFromOperation(op *openapi3.Operation) string {
74+
if value, ok := op.Extensions[teamExtensionName]; ok {
75+
return value.(string)
76+
}
77+
return ""
78+
}
79+
6980
func newExtensionsFrom2xxResponse(responsesMap map[string]*openapi3.ResponseRef) map[string]any {
7081
if val, ok := responsesMap["200"]; ok {
7182
return newExtensionsFromContent(val.Value.Content)

tools/cli/internal/openapi/sunset_test.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ func TestNewSunsetListFromSpec(t *testing.T) {
7474
expected: nil,
7575
},
7676
{
77-
name: "Multiple operations with extensions",
77+
name: "201 operations with extensions",
7878
specInfo: &load.SpecInfo{
7979
Spec: &openapi3.T{
8080
Paths: openapi3.NewPaths(
8181
openapi3.WithPath("/example1", &openapi3.PathItem{
8282
Get: &openapi3.Operation{
83-
Responses: openapi3.NewResponses(openapi3.WithName("200", &openapi3.Response{
83+
Responses: openapi3.NewResponses(openapi3.WithName("201", &openapi3.Response{
8484
Content: openapi3.Content{
8585
"application/json": &openapi3.MediaType{
8686
Extensions: map[string]any{
@@ -92,20 +92,6 @@ func TestNewSunsetListFromSpec(t *testing.T) {
9292
})),
9393
},
9494
}),
95-
openapi3.WithPath("/example2", &openapi3.PathItem{
96-
Post: &openapi3.Operation{
97-
Responses: openapi3.NewResponses(openapi3.WithName("201", &openapi3.Response{
98-
Content: openapi3.Content{
99-
"application/json": &openapi3.MediaType{
100-
Extensions: map[string]any{
101-
sunsetExtensionName: "2025-01-01",
102-
apiVersionExtensionName: "v1.5",
103-
},
104-
},
105-
},
106-
})),
107-
},
108-
}),
10995
),
11096
},
11197
},
@@ -116,12 +102,6 @@ func TestNewSunsetListFromSpec(t *testing.T) {
116102
Version: "v2.0",
117103
SunsetDate: "2024-06-15",
118104
},
119-
{
120-
Operation: "POST",
121-
Path: "/example2",
122-
Version: "v1.5",
123-
SunsetDate: "2025-01-01",
124-
},
125105
},
126106
},
127107
}

0 commit comments

Comments
 (0)