Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/autoupdate-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
./tools/api-generator/spec.yaml
- run: make gen-api-commands
if: steps.verify-changed-files.outputs.files_changed == 'true'
- run: make gen-docs
if: steps.verify-changed-files.outputs.files_changed == 'true'
- name: Find JIRA ticket
id: find
if: steps.verify-changed-files.outputs.files_changed == 'true'
Expand Down
141 changes: 141 additions & 0 deletions tools/api-generator/.snapshots/07-sunset.yaml.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// Copyright 2025 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// This code was autogenerated using `make gen-L1-commands`
// Don't make any manual changes to this file.
package api

import "net/http"

var Commands = GroupedAndSortedCommands{
{
Name: `Clusters`,
Description: `Returns, adds, edits, and removes database deployments. Changes to cluster configurations can affect costs. This resource requires your Project ID.`,
Commands: []Command{
{
OperationID: `listClusters`,
Aliases: nil,
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.

This command is invoking the endpoint with OperationID: 'listClusters'.
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`,
RequestParameters: RequestParameters{
URL: `/api/atlas/v2/groups/{groupId}/clusters`,
QueryParameters: []Parameter{
{
Name: `envelope`,
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.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `bool`,
},
},
{
Name: `includeCount`,
Description: `Flag that indicates whether the response returns the total number of items (totalCount) in the response.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `bool`,
},
},
{
Name: `itemsPerPage`,
Description: `Number of items that the response returns per page.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `int`,
},
},
{
Name: `pageNum`,
Description: `Number of the page that displays the current set of the total objects that the response returns.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `int`,
},
},
{
Name: `pretty`,
Description: `Flag that indicates whether the response body should be in the prettyprint format.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `bool`,
},
},
{
Name: `includeDeletedWithRetainedBackups`,
Description: `Flag that indicates whether to return Clusters with retain backups.`,
Short: ``,
Required: false,
Type: ParameterType{
IsArray: false,
Type: `bool`,
},
},
},
URLParameters: []Parameter{
{
Name: `groupId`,
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.


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.`,
Short: ``,
Required: true,
Type: ParameterType{
IsArray: false,
Type: `string`,
},
},
},
Verb: http.MethodGet,
},
Versions: []Version{
{
Version: `2023-01-01`,
RequestContentType: ``,
ResponseContentTypes: []string{
`json`,
},
},
{
Version: `2023-02-01`,
RequestContentType: ``,
ResponseContentTypes: []string{
`json`,
},
},
{
Version: `2024-08-05`,
RequestContentType: ``,
ResponseContentTypes: []string{
`json`,
},
},
},
},
},
},
}

14 changes: 13 additions & 1 deletion tools/api-generator/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"regexp"
"sort"
"strconv"
"time"

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

func extractSunsetDate(operation *openapi3.Operation) *time.Time {
if sSunset, ok := operation.Extensions["x-sunset"].(string); ok && sSunset != "" {
if sunset, err := time.Parse("2006-01-02", sSunset); err == nil {
return &sunset
}
}

return nil
}

func extractExtensionsFromOperation(operation *openapi3.Operation) (bool, string, []string) {
skip := false
operationID := operation.OperationID
Expand Down Expand Up @@ -108,7 +119,8 @@ func extractExtensionsFromOperation(operation *openapi3.Operation) (bool, string

func operationToCommand(path, verb string, operation *openapi3.Operation) (*api.Command, error) {
skip, operationID, aliases := extractExtensionsFromOperation(operation)
if skip {
sunset := extractSunsetDate(operation)
if skip || (sunset != nil && sunset.Before(time.Now())) {
return nil, nil
}

Expand Down
Loading
Loading