Skip to content

Commit

Permalink
Add support for dashboard listing pagination parameters (#2165)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Sep 6, 2023
1 parent 584ab4a commit 6d5f22d
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 4 deletions.
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.5",
"regenerated": "2023-09-05 15:12:49.676642",
"spec_repo_commit": "eb534d74"
"regenerated": "2023-09-06 11:51:26.107168",
"spec_repo_commit": "c59cafad"
},
"v2": {
"apigentools_version": "1.6.5",
"regenerated": "2023-09-05 15:12:49.689828",
"spec_repo_commit": "eb534d74"
"regenerated": "2023-09-06 11:51:26.121714",
"spec_repo_commit": "c59cafad"
}
}
}
19 changes: 19 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20836,6 +20836,21 @@ paths:
required: false
schema:
type: boolean
- description: The maximum number of dashboards returned in the list.
in: query
name: count
required: false
schema:
default: 100
format: int64
type: integer
- description: The specific offset to use as the beginning of the returned response.
in: query
name: start
required: false
schema:
format: int64
type: integer
responses:
'200':
content:
Expand All @@ -20859,6 +20874,10 @@ paths:
summary: Get all dashboards
tags:
- Dashboards
x-pagination:
limitParam: count
pageOffsetParam: start
resultsPath: dashboards
patch:
description: Restore dashboards using the specified IDs. If there are any failures,
no dashboards will be restored (partial success is not allowed).
Expand Down
70 changes: 70 additions & 0 deletions api/datadogV1/api_dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ func (a *DashboardsApi) GetPublicDashboardInvitations(ctx _context.Context, toke
type ListDashboardsOptionalParameters struct {
FilterShared *bool
FilterDeleted *bool
Count *int64
Start *int64
}

// NewListDashboardsOptionalParameters creates an empty struct for parameters.
Expand All @@ -707,6 +709,18 @@ func (r *ListDashboardsOptionalParameters) WithFilterDeleted(filterDeleted bool)
return r
}

// WithCount sets the corresponding parameter name and returns the struct.
func (r *ListDashboardsOptionalParameters) WithCount(count int64) *ListDashboardsOptionalParameters {
r.Count = &count
return r
}

// WithStart sets the corresponding parameter name and returns the struct.
func (r *ListDashboardsOptionalParameters) WithStart(start int64) *ListDashboardsOptionalParameters {
r.Start = &start
return r
}

// ListDashboards Get all dashboards.
// Get all dashboards.
//
Expand Down Expand Up @@ -743,6 +757,12 @@ func (a *DashboardsApi) ListDashboards(ctx _context.Context, o ...ListDashboards
if optionalParams.FilterDeleted != nil {
localVarQueryParams.Add("filter[deleted]", datadog.ParameterToString(*optionalParams.FilterDeleted, ""))
}
if optionalParams.Count != nil {
localVarQueryParams.Add("count", datadog.ParameterToString(*optionalParams.Count, ""))
}
if optionalParams.Start != nil {
localVarQueryParams.Add("start", datadog.ParameterToString(*optionalParams.Start, ""))
}
localVarHeaderParams["Accept"] = "application/json"

datadog.SetAuthKeys(
Expand Down Expand Up @@ -794,6 +814,56 @@ func (a *DashboardsApi) ListDashboards(ctx _context.Context, o ...ListDashboards
return localVarReturnValue, localVarHTTPResponse, nil
}

// ListDashboardsWithPagination provides a paginated version of ListDashboards returning a channel with all items.
func (a *DashboardsApi) ListDashboardsWithPagination(ctx _context.Context, o ...ListDashboardsOptionalParameters) (<-chan datadog.PaginationResult[DashboardSummaryDefinition], func()) {
ctx, cancel := _context.WithCancel(ctx)
pageSize_ := int64(100)
if len(o) == 0 {
o = append(o, ListDashboardsOptionalParameters{})
}
if o[0].Count != nil {
pageSize_ = *o[0].Count
}
o[0].Count = &pageSize_

items := make(chan datadog.PaginationResult[DashboardSummaryDefinition], pageSize_)
go func() {
for {
resp, _, err := a.ListDashboards(ctx, o...)
if err != nil {
var returnItem DashboardSummaryDefinition
items <- datadog.PaginationResult[DashboardSummaryDefinition]{returnItem, err}
break
}
respDashboards, ok := resp.GetDashboardsOk()
if !ok {
break
}
results := *respDashboards

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

// RestoreDashboards Restore deleted dashboards.
// Restore dashboards using the specified IDs. If there are any failures, no dashboards will be restored (partial success is not allowed).
func (a *DashboardsApi) RestoreDashboards(ctx _context.Context, body DashboardRestoreRequest) (*_nethttp.Response, error) {
Expand Down
29 changes: 29 additions & 0 deletions examples/v1/dashboards/ListDashboards_1062671515.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Get all dashboards 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/datadogV1"
)

func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
resp, _ := api.ListDashboardsWithPagination(ctx, *datadogV1.NewListDashboardsOptionalParameters().WithCount(2))

for paginationResult := range resp {
if paginationResult.Error != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.ListDashboards`: %v\n", paginationResult.Error)
}
responseContent, _ := json.MarshalIndent(paginationResult.Item, "", " ")
fmt.Fprintf(os.Stdout, "%s\n", responseContent)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-09-04T12:26:51.389Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: GET
url: https://api.datadoghq.com/api/v1/dashboard?count=2
response:
body: '{"dashboards":[{"id":"5vp-fxm-s4j","title":"PCF Testing","description":null,"layout_type":"ordered","url":"/dashboard/5vp-fxm-s4j/pcf-testing","is_read_only":false,"created_at":"2022-06-08T10:40:29.941695+00:00","modified_at":"2023-07-27T12:26:28.359080+00:00","author_handle":"frog@datadoghq.com","deleted_at":null},{"id":"ubf-m9i-gms","title":"OpenStack
Controller Overview","description":"## OpenStack Controller - Overview\n\nPreset
dashboard for the OpenStack Controller integration. Used for OpenStack deployments
v13 and higher. \n\n[See integration docs for more details](https://docs.datadoghq.com/integrations/openstack_controller/)","layout_type":"ordered","url":"/dashboard/ubf-m9i-gms/openstack-controller-overview","is_read_only":false,"created_at":"2023-04-28T19:16:35.964720+00:00","modified_at":"2023-08-07T13:53:31.924789+00:00","author_handle":"frog@datadoghq.com","deleted_at":null}]}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: GET
url: https://api.datadoghq.com/api/v1/dashboard?count=2&start=2
response:
body: '{"dashboards":[{"id":"ja7-nhx-7zs","title":"OpenStack Controller Overview
[Default Microversion]","description":"## OpenStack Controller - Overview\n\nPreset
dashboard for the OpenStack Controller integration. Used for OpenStack deployments
v13 and higher. \n\n[See integration docs for more details](https://docs.datadoghq.com/integrations/openstack_controller/)","layout_type":"ordered","url":"/dashboard/ja7-nhx-7zs/openstack-controller-overview-default-microversion","is_read_only":false,"created_at":"2023-08-29T19:56:15.999851+00:00","modified_at":"2023-08-29T20:12:33.385536+00:00","author_handle":"frog@datadoghq.com","deleted_at":null}]}
'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
8 changes: 8 additions & 0 deletions tests/scenarios/features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,14 @@ Feature: Dashboards
And the response "dashboards[0].title" has the same value as "dashboard.title"
And the response "dashboards[0].id" has the same value as "dashboard.id"

@replay-only @skip-validation @team:DataDog/dashboards-backend @with-pagination
Scenario: Get all dashboards returns "OK" response with pagination
Given new "ListDashboards" request
And request contains "count" parameter with value 2
When the request with pagination is sent
Then the response status is 200 OK
And the response has 3 items

@generated @skip @team:DataDog/dashboards-backend
Scenario: Get all invitations for a shared dashboard returns "Not Found" response
Given new "GetPublicDashboardInvitations" request
Expand Down

0 comments on commit 6d5f22d

Please sign in to comment.