Skip to content

Commit 7a0b03e

Browse files
merged master
2 parents fca08bc + c657a6a commit 7a0b03e

File tree

3 files changed

+404
-0
lines changed

3 files changed

+404
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func DefaultFilters(oas *openapi3.T, metadata *Metadata) []Filter {
7878
&HiddenEnvsFilter{oas: oas, metadata: metadata},
7979
&TagsFilter{oas: oas},
8080
&OperationsFilter{oas: oas},
81+
&SunsetFilter{oas: oas},
8182
&SchemasFilter{oas: oas},
8283
}
8384
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
"strings"
19+
20+
"github.com/getkin/kin-openapi/openapi3"
21+
)
22+
23+
const sunsetToBeDecided = "9999-12-31"
24+
25+
// SunsetFilter removes the sunsetToBeDecided from the openapi specification.
26+
type SunsetFilter struct {
27+
oas *openapi3.T
28+
}
29+
30+
func (*SunsetFilter) ValidateMetadata() error {
31+
return nil
32+
}
33+
34+
func (f *SunsetFilter) Apply() error {
35+
if f.oas.Paths == nil {
36+
return nil
37+
}
38+
39+
for _, pathItem := range f.oas.Paths.Map() {
40+
for _, operation := range pathItem.Operations() {
41+
if operation.Responses == nil {
42+
continue
43+
}
44+
45+
applyOnOperation(operation)
46+
}
47+
}
48+
return nil
49+
}
50+
51+
func applyOnOperation(op *openapi3.Operation) {
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+
delete(content.Extensions, "x-sunset")
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)