From 2745e9f609abecabb005071e82623852ec56afd3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 21:01:02 +0000 Subject: [PATCH] feat(api): OpenAPI spec update via Stainless API (#1810) --- api.md | 2 +- healthchecks/healthcheck.go | 24 +++++++++++++++++++----- healthchecks/healthcheck_test.go | 6 ++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/api.md b/api.md index 95928b81faa..63863d9193b 100644 --- a/api.md +++ b/api.md @@ -1851,7 +1851,7 @@ Methods: - client.Healthchecks.New(ctx context.Context, params healthchecks.HealthcheckNewParams) (healthchecks.Healthcheck, error) - client.Healthchecks.Update(ctx context.Context, healthcheckID string, params healthchecks.HealthcheckUpdateParams) (healthchecks.Healthcheck, error) -- client.Healthchecks.List(ctx context.Context, query healthchecks.HealthcheckListParams) (pagination.SinglePage[healthchecks.Healthcheck], error) +- client.Healthchecks.List(ctx context.Context, params healthchecks.HealthcheckListParams) (pagination.SinglePage[healthchecks.Healthcheck], error) - client.Healthchecks.Delete(ctx context.Context, healthcheckID string, params healthchecks.HealthcheckDeleteParams) (healthchecks.HealthcheckDeleteResponse, error) - client.Healthchecks.Edit(ctx context.Context, healthcheckID string, params healthchecks.HealthcheckEditParams) (healthchecks.Healthcheck, error) - client.Healthchecks.Get(ctx context.Context, healthcheckID string, query healthchecks.HealthcheckGetParams) (healthchecks.Healthcheck, error) diff --git a/healthchecks/healthcheck.go b/healthchecks/healthcheck.go index 867246819cf..1916c5b0d4b 100644 --- a/healthchecks/healthcheck.go +++ b/healthchecks/healthcheck.go @@ -6,9 +6,11 @@ import ( "context" "fmt" "net/http" + "net/url" "time" "github.com/cloudflare/cloudflare-go/v2/internal/apijson" + "github.com/cloudflare/cloudflare-go/v2/internal/apiquery" "github.com/cloudflare/cloudflare-go/v2/internal/pagination" "github.com/cloudflare/cloudflare-go/v2/internal/param" "github.com/cloudflare/cloudflare-go/v2/internal/requestconfig" @@ -63,12 +65,12 @@ func (r *HealthcheckService) Update(ctx context.Context, healthcheckID string, p } // List configured health checks. -func (r *HealthcheckService) List(ctx context.Context, query HealthcheckListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Healthcheck], err error) { +func (r *HealthcheckService) List(ctx context.Context, params HealthcheckListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Healthcheck], err error) { var raw *http.Response opts = append(r.Options, opts...) opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...) - path := fmt.Sprintf("zones/%s/healthchecks", query.ZoneID) - cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...) + path := fmt.Sprintf("zones/%s/healthchecks", params.ZoneID) + cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...) if err != nil { return nil, err } @@ -81,8 +83,8 @@ func (r *HealthcheckService) List(ctx context.Context, query HealthcheckListPara } // List configured health checks. -func (r *HealthcheckService) ListAutoPaging(ctx context.Context, query HealthcheckListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Healthcheck] { - return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...)) +func (r *HealthcheckService) ListAutoPaging(ctx context.Context, params HealthcheckListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Healthcheck] { + return pagination.NewSinglePageAutoPager(r.List(ctx, params, opts...)) } // Delete a health check. @@ -569,6 +571,18 @@ func (r HealthcheckUpdateResponseEnvelopeSuccess) IsKnown() bool { type HealthcheckListParams struct { // Identifier ZoneID param.Field[string] `path:"zone_id,required"` + // Page number of paginated results. + Page param.Field[interface{}] `query:"page"` + // Maximum number of results per page. Must be a multiple of 5. + PerPage param.Field[interface{}] `query:"per_page"` +} + +// URLQuery serializes [HealthcheckListParams]'s query parameters as `url.Values`. +func (r HealthcheckListParams) URLQuery() (v url.Values) { + return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{ + ArrayFormat: apiquery.ArrayQueryFormatRepeat, + NestedFormat: apiquery.NestedQueryFormatBrackets, + }) } type HealthcheckDeleteParams struct { diff --git a/healthchecks/healthcheck_test.go b/healthchecks/healthcheck_test.go index c74edc22035..3edde20e3d2 100644 --- a/healthchecks/healthcheck_test.go +++ b/healthchecks/healthcheck_test.go @@ -138,7 +138,7 @@ func TestHealthcheckUpdateWithOptionalParams(t *testing.T) { } } -func TestHealthcheckList(t *testing.T) { +func TestHealthcheckListWithOptionalParams(t *testing.T) { t.Skip("skipped: tests are disabled for the time being") baseURL := "http://localhost:4010" if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok { @@ -153,7 +153,9 @@ func TestHealthcheckList(t *testing.T) { option.WithAPIEmail("user@example.com"), ) _, err := client.Healthchecks.List(context.TODO(), healthchecks.HealthcheckListParams{ - ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"), + Page: cloudflare.F[any](map[string]interface{}{}), + PerPage: cloudflare.F[any](map[string]interface{}{}), }) if err != nil { var apierr *cloudflare.Error