Skip to content

Commit 554857b

Browse files
CLOUDP-297946: removes the x-sunset=9999-12-31 from the openapi spec
1 parent b402dad commit 554857b

File tree

4 files changed

+406
-0
lines changed

4 files changed

+406
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func DefaultFilters(oas *openapi3.T, metadata *Metadata) []Filter {
7777
&HiddenEnvsFilter{oas: oas, metadata: metadata},
7878
&TagsFilter{oas: oas},
7979
&OperationsFilter{oas: oas},
80+
&SunsetFilter{oas: oas},
8081
}
8182
}
8283

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
package filter
1516

1617
import (
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package filter
16+
17+
import (
18+
"github.com/getkin/kin-openapi/openapi3"
19+
"strings"
20+
)
21+
22+
const sunsetToBeDecided = "9999-12-31"
23+
24+
// SunsetFilter removes the sunsetToBeDecided from the openapi specification
25+
type SunsetFilter struct {
26+
oas *openapi3.T
27+
}
28+
29+
func (f *SunsetFilter) ValidateMetadata() error {
30+
return nil
31+
}
32+
33+
func (f *SunsetFilter) Apply() error {
34+
if f.oas.Paths == nil {
35+
return nil
36+
}
37+
38+
for _, pathItem := range f.oas.Paths.Map() {
39+
for _, operation := range pathItem.Operations() {
40+
if operation.Responses == nil {
41+
continue
42+
}
43+
44+
applyOnOperation(operation)
45+
}
46+
}
47+
return nil
48+
}
49+
50+
func applyOnOperation(op *openapi3.Operation) {
51+
//newResponses := make(map[string]*openapi3.ResponseRef, 1)
52+
for key, response := range op.Responses.Map() {
53+
if !strings.HasPrefix(key, "20") {
54+
continue
55+
}
56+
57+
for _, content := range response.Value.Content {
58+
if v, ok := content.Extensions["x-sunset"]; ok {
59+
if v != sunsetToBeDecided {
60+
continue
61+
}
62+
63+
delete(content.Extensions, "x-sunset")
64+
//newResponses[key] = response
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)