Skip to content

Commit 368055f

Browse files
authored
CLOUDP-299959: sunset apis should be ignored from autogenerated commands (#3631)
1 parent c2ed520 commit 368055f

File tree

4 files changed

+8600
-1
lines changed

4 files changed

+8600
-1
lines changed

.github/workflows/autoupdate-spec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
./tools/api-generator/spec.yaml
2525
- run: make gen-api-commands
2626
if: steps.verify-changed-files.outputs.files_changed == 'true'
27+
- run: make gen-docs
28+
if: steps.verify-changed-files.outputs.files_changed == 'true'
2729
- name: Find JIRA ticket
2830
id: find
2931
if: steps.verify-changed-files.outputs.files_changed == 'true'
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
// This code was autogenerated using `make gen-L1-commands`
16+
// Don't make any manual changes to this file.
17+
package api
18+
19+
import "net/http"
20+
21+
var Commands = GroupedAndSortedCommands{
22+
{
23+
Name: `Clusters`,
24+
Description: `Returns, adds, edits, and removes database deployments. Changes to cluster configurations can affect costs. This resource requires your Project ID.`,
25+
Commands: []Command{
26+
{
27+
OperationID: `listClusters`,
28+
Aliases: nil,
29+
Description: `Returns the details for all clusters in the specific project to which you have access. Clusters contain a group of hosts that maintain the same data set. The response includes clusters with asymmetrically-sized shards. To use this resource, the requesting API Key must have the Project Read Only role. This feature is not available for serverless clusters.
30+
31+
This command is invoking the endpoint with OperationID: 'listClusters'.
32+
For more information about flags, format of --file and examples, see: https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Clusters/operation/listClusters`,
33+
RequestParameters: RequestParameters{
34+
URL: `/api/atlas/v2/groups/{groupId}/clusters`,
35+
QueryParameters: []Parameter{
36+
{
37+
Name: `envelope`,
38+
Description: `Flag that indicates whether Application wraps the response in an envelope JSON object. Some API clients cannot access the HTTP response headers or status code. To remediate this, set envelope=true in the query. Endpoints that return a list of results use the results object as an envelope. Application adds the status parameter to the response body.`,
39+
Short: ``,
40+
Required: false,
41+
Type: ParameterType{
42+
IsArray: false,
43+
Type: `bool`,
44+
},
45+
},
46+
{
47+
Name: `includeCount`,
48+
Description: `Flag that indicates whether the response returns the total number of items (totalCount) in the response.`,
49+
Short: ``,
50+
Required: false,
51+
Type: ParameterType{
52+
IsArray: false,
53+
Type: `bool`,
54+
},
55+
},
56+
{
57+
Name: `itemsPerPage`,
58+
Description: `Number of items that the response returns per page.`,
59+
Short: ``,
60+
Required: false,
61+
Type: ParameterType{
62+
IsArray: false,
63+
Type: `int`,
64+
},
65+
},
66+
{
67+
Name: `pageNum`,
68+
Description: `Number of the page that displays the current set of the total objects that the response returns.`,
69+
Short: ``,
70+
Required: false,
71+
Type: ParameterType{
72+
IsArray: false,
73+
Type: `int`,
74+
},
75+
},
76+
{
77+
Name: `pretty`,
78+
Description: `Flag that indicates whether the response body should be in the prettyprint format.`,
79+
Short: ``,
80+
Required: false,
81+
Type: ParameterType{
82+
IsArray: false,
83+
Type: `bool`,
84+
},
85+
},
86+
{
87+
Name: `includeDeletedWithRetainedBackups`,
88+
Description: `Flag that indicates whether to return Clusters with retain backups.`,
89+
Short: ``,
90+
Required: false,
91+
Type: ParameterType{
92+
IsArray: false,
93+
Type: `bool`,
94+
},
95+
},
96+
},
97+
URLParameters: []Parameter{
98+
{
99+
Name: `groupId`,
100+
Description: `Unique 24-hexadecimal digit string that identifies your project. Use the /groups endpoint to retrieve all projects to which the authenticated user has access.
101+
102+
103+
NOTE: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.`,
104+
Short: ``,
105+
Required: true,
106+
Type: ParameterType{
107+
IsArray: false,
108+
Type: `string`,
109+
},
110+
},
111+
},
112+
Verb: http.MethodGet,
113+
},
114+
Versions: []Version{
115+
{
116+
Version: `2023-01-01`,
117+
RequestContentType: ``,
118+
ResponseContentTypes: []string{
119+
`json`,
120+
},
121+
},
122+
{
123+
Version: `2023-02-01`,
124+
RequestContentType: ``,
125+
ResponseContentTypes: []string{
126+
`json`,
127+
},
128+
},
129+
{
130+
Version: `2024-08-05`,
131+
RequestContentType: ``,
132+
ResponseContentTypes: []string{
133+
`json`,
134+
},
135+
},
136+
},
137+
},
138+
},
139+
},
140+
}
141+

tools/api-generator/convert.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"regexp"
2121
"sort"
2222
"strconv"
23+
"time"
2324

2425
"github.com/getkin/kin-openapi/openapi3"
2526
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/api"
@@ -78,6 +79,16 @@ func specToCommands(spec *openapi3.T) (api.GroupedAndSortedCommands, error) {
7879
return sortedGroups, nil
7980
}
8081

82+
func extractSunsetDate(operation *openapi3.Operation) *time.Time {
83+
if sSunset, ok := operation.Extensions["x-sunset"].(string); ok && sSunset != "" {
84+
if sunset, err := time.Parse("2006-01-02", sSunset); err == nil {
85+
return &sunset
86+
}
87+
}
88+
89+
return nil
90+
}
91+
8192
func extractExtensionsFromOperation(operation *openapi3.Operation) (bool, string, []string) {
8293
skip := false
8394
operationID := operation.OperationID
@@ -108,7 +119,8 @@ func extractExtensionsFromOperation(operation *openapi3.Operation) (bool, string
108119

109120
func operationToCommand(path, verb string, operation *openapi3.Operation) (*api.Command, error) {
110121
skip, operationID, aliases := extractExtensionsFromOperation(operation)
111-
if skip {
122+
sunset := extractSunsetDate(operation)
123+
if skip || (sunset != nil && sunset.Before(time.Now())) {
112124
return nil, nil
113125
}
114126

0 commit comments

Comments
 (0)