diff --git a/.apigentools-info b/.apigentools-info index ab5abe54158..60c0c54e5ae 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -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" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 3276b321afa..495f32939eb 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -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: @@ -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). diff --git a/api/datadogV1/api_dashboards.go b/api/datadogV1/api_dashboards.go index 3031997ae7a..c49f888719a 100644 --- a/api/datadogV1/api_dashboards.go +++ b/api/datadogV1/api_dashboards.go @@ -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. @@ -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. // @@ -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( @@ -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) { diff --git a/examples/v1/dashboards/ListDashboards_1062671515.go b/examples/v1/dashboards/ListDashboards_1062671515.go new file mode 100644 index 00000000000..9cab238fa21 --- /dev/null +++ b/examples/v1/dashboards/ListDashboards_1062671515.go @@ -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) + } +} diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.freeze b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.freeze new file mode 100644 index 00000000000..180059c6b3d --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.freeze @@ -0,0 +1 @@ +2023-09-04T12:26:51.389Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.yaml b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.yaml new file mode 100644 index 00000000000..2eddb44ba99 --- /dev/null +++ b/tests/scenarios/cassettes/TestScenarios/v1/Feature_Dashboards/Scenario_Get_all_dashboards_returns_OK_response_with_pagination.yaml @@ -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 diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index f5899bf931f..89f45dbe1f9 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -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