Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page[size] and page[number] parameters to Downtime docs #2333

Merged
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
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-01-02 15:20:24.356679",
"spec_repo_commit": "415bb394"
"regenerated": "2024-01-02 15:59:38.177781",
"spec_repo_commit": "d5ac2418"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-01-02 15:20:24.377452",
"spec_repo_commit": "415bb394"
"regenerated": "2024-01-02 15:59:38.203975",
"spec_repo_commit": "d5ac2418"
}
}
}
14 changes: 14 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26896,6 +26896,16 @@ paths:
schema:
format: int64
type: integer
- $ref: '#/components/parameters/PageOffset'
- description: Maximum number of downtimes in the response.
example: 100
in: query
name: page[limit]
required: false
schema:
default: 30
format: int64
type: integer
responses:
'200':
content:
Expand All @@ -26920,6 +26930,10 @@ paths:
tags:
- Downtimes
x-codegen-request-body-name: body
x-pagination:
limitParam: page[limit]
pageOffsetParam: page[offset]
resultsPath: data
/api/v2/permissions:
get:
description: Returns a list of all permissions, including name, description,
Expand Down
90 changes: 89 additions & 1 deletion api/datadogV2/api_downtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,47 @@ func (a *DowntimesApi) ListDowntimesWithPagination(ctx _context.Context, o ...Li
return items, cancel
}

// ListMonitorDowntimesOptionalParameters holds optional parameters for ListMonitorDowntimes.
type ListMonitorDowntimesOptionalParameters struct {
PageOffset *int64
PageLimit *int64
}

// NewListMonitorDowntimesOptionalParameters creates an empty struct for parameters.
func NewListMonitorDowntimesOptionalParameters() *ListMonitorDowntimesOptionalParameters {
this := ListMonitorDowntimesOptionalParameters{}
return &this
}

// WithPageOffset sets the corresponding parameter name and returns the struct.
func (r *ListMonitorDowntimesOptionalParameters) WithPageOffset(pageOffset int64) *ListMonitorDowntimesOptionalParameters {
r.PageOffset = &pageOffset
return r
}

// WithPageLimit sets the corresponding parameter name and returns the struct.
func (r *ListMonitorDowntimesOptionalParameters) WithPageLimit(pageLimit int64) *ListMonitorDowntimesOptionalParameters {
r.PageLimit = &pageLimit
return r
}

// ListMonitorDowntimes Get active downtimes for a monitor.
// Get all active downtimes for the specified monitor.
func (a *DowntimesApi) ListMonitorDowntimes(ctx _context.Context, monitorId int64) (MonitorDowntimeMatchResponse, *_nethttp.Response, error) {
func (a *DowntimesApi) ListMonitorDowntimes(ctx _context.Context, monitorId int64, o ...ListMonitorDowntimesOptionalParameters) (MonitorDowntimeMatchResponse, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodGet
localVarPostBody interface{}
localVarReturnValue MonitorDowntimeMatchResponse
optionalParams ListMonitorDowntimesOptionalParameters
)

if len(o) > 1 {
return localVarReturnValue, nil, datadog.ReportError("only one argument of type ListMonitorDowntimesOptionalParameters is allowed")
}
if len(o) == 1 {
optionalParams = o[0]
}

localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.DowntimesApi.ListMonitorDowntimes")
if err != nil {
return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()}
Expand All @@ -447,6 +479,12 @@ func (a *DowntimesApi) ListMonitorDowntimes(ctx _context.Context, monitorId int6
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if optionalParams.PageOffset != nil {
localVarQueryParams.Add("page[offset]", datadog.ParameterToString(*optionalParams.PageOffset, ""))
}
if optionalParams.PageLimit != nil {
localVarQueryParams.Add("page[limit]", datadog.ParameterToString(*optionalParams.PageLimit, ""))
}
localVarHeaderParams["Accept"] = "application/json"

datadog.SetAuthKeys(
Expand Down Expand Up @@ -498,6 +536,56 @@ func (a *DowntimesApi) ListMonitorDowntimes(ctx _context.Context, monitorId int6
return localVarReturnValue, localVarHTTPResponse, nil
}

// ListMonitorDowntimesWithPagination provides a paginated version of ListMonitorDowntimes returning a channel with all items.
func (a *DowntimesApi) ListMonitorDowntimesWithPagination(ctx _context.Context, monitorId int64, o ...ListMonitorDowntimesOptionalParameters) (<-chan datadog.PaginationResult[MonitorDowntimeMatchResponseData], func()) {
ctx, cancel := _context.WithCancel(ctx)
pageSize_ := int64(30)
if len(o) == 0 {
o = append(o, ListMonitorDowntimesOptionalParameters{})
}
if o[0].PageLimit != nil {
pageSize_ = *o[0].PageLimit
}
o[0].PageLimit = &pageSize_

items := make(chan datadog.PaginationResult[MonitorDowntimeMatchResponseData], pageSize_)
go func() {
for {
resp, _, err := a.ListMonitorDowntimes(ctx, monitorId, o...)
if err != nil {
var returnItem MonitorDowntimeMatchResponseData
items <- datadog.PaginationResult[MonitorDowntimeMatchResponseData]{Item: returnItem, Error: err}
break
}
respData, ok := resp.GetDataOk()
if !ok {
break
}
results := *respData

for _, item := range results {
select {
case items <- datadog.PaginationResult[MonitorDowntimeMatchResponseData]{Item: item, Error: nil}:
case <-ctx.Done():
close(items)
return
}
}
if len(results) < int(pageSize_) {
break
}
if o[0].PageOffset == nil {
o[0].PageOffset = &pageSize_
} else {
pageOffset_ := *o[0].PageOffset + pageSize_
o[0].PageOffset = &pageOffset_
}
}
close(items)
}()
return items, cancel
}

// UpdateDowntime Update a downtime.
// Update a downtime by `downtime_id`.
func (a *DowntimesApi) UpdateDowntime(ctx _context.Context, downtimeId string, body DowntimeUpdateRequest) (DowntimeResponse, *_nethttp.Response, error) {
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/downtimes/ListMonitorDowntimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewDowntimesApi(apiClient)
resp, r, err := api.ListMonitorDowntimes(ctx, 35534610)
resp, r, err := api.ListMonitorDowntimes(ctx, 35534610, *datadogV2.NewListMonitorDowntimesOptionalParameters())

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.ListMonitorDowntimes`: %v\n", err)
Expand Down
29 changes: 29 additions & 0 deletions examples/v2/downtimes/ListMonitorDowntimes_3316718253.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Get active downtimes for a monitor returns "OK" response with pagination

package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)

func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewDowntimesApi(apiClient)
resp, _ := api.ListMonitorDowntimesWithPagination(ctx, 9223372036854775807, *datadogV2.NewListMonitorDowntimesOptionalParameters())

for paginationResult := range resp {
if paginationResult.Error != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.ListMonitorDowntimes`: %v\n", paginationResult.Error)
}
responseContent, _ := json.MarshalIndent(paginationResult.Item, "", " ")
fmt.Fprintf(os.Stdout, "%s\n", responseContent)
}
}
7 changes: 7 additions & 0 deletions tests/scenarios/features/v2/downtimes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ Feature: Downtimes
And the response "data" has length 1
And the response "data" has item with field "id" with value "aeefc6a8-15d8-11ee-a8ef-da7ad0900002"

@generated @skip @team:DataDog/monitor-app @with-pagination
Scenario: Get active downtimes for a monitor returns "OK" response with pagination
Given new "ListMonitorDowntimes" request
And request contains "monitor_id" parameter from "REPLACE.ME"
When the request with pagination is sent
Then the response status is 200 OK

@team:DataDog/monitor-app
Scenario: Get all downtimes for a monitor returns "Monitor Not Found error" response
Given new "ListMonitorDowntimes" request
Expand Down
Loading