Skip to content

Commit cbb874f

Browse files
committedFeb 11, 2025
feat(roles): enable correct pagination parameters (#3914)
1 parent f194ed8 commit cbb874f

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed
 

‎.stats.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
configured_endpoints: 1525
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-e4e4fe20b25c825f2c21322b8909758f1a84f25cfe0df7ce34571b8a2f2be1c1.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4c85e60ad7ca96a7ddadf88e1e3c7b62fb791d39d435bedfe6caac2c27081a48.yml

‎accounts/role.go

+20-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"errors"
88
"fmt"
99
"net/http"
10+
"net/url"
1011

1112
"github.com/cloudflare/cloudflare-go/v4/internal/apijson"
13+
"github.com/cloudflare/cloudflare-go/v4/internal/apiquery"
1214
"github.com/cloudflare/cloudflare-go/v4/internal/param"
1315
"github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
1416
"github.com/cloudflare/cloudflare-go/v4/option"
@@ -36,16 +38,16 @@ func NewRoleService(opts ...option.RequestOption) (r *RoleService) {
3638
}
3739

3840
// Get all available roles for an account.
39-
func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...option.RequestOption) (res *pagination.SinglePage[shared.Role], err error) {
41+
func (r *RoleService) List(ctx context.Context, params RoleListParams, opts ...option.RequestOption) (res *pagination.V4PagePaginationArray[shared.Role], err error) {
4042
var raw *http.Response
4143
opts = append(r.Options[:], opts...)
4244
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
43-
if query.AccountID.Value == "" {
45+
if params.AccountID.Value == "" {
4446
err = errors.New("missing required account_id parameter")
4547
return
4648
}
47-
path := fmt.Sprintf("accounts/%s/roles", query.AccountID)
48-
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, nil, &res, opts...)
49+
path := fmt.Sprintf("accounts/%s/roles", params.AccountID)
50+
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
4951
if err != nil {
5052
return nil, err
5153
}
@@ -58,8 +60,8 @@ func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...op
5860
}
5961

6062
// Get all available roles for an account.
61-
func (r *RoleService) ListAutoPaging(ctx context.Context, query RoleListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[shared.Role] {
62-
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
63+
func (r *RoleService) ListAutoPaging(ctx context.Context, params RoleListParams, opts ...option.RequestOption) *pagination.V4PagePaginationArrayAutoPager[shared.Role] {
64+
return pagination.NewV4PagePaginationArrayAutoPager(r.List(ctx, params, opts...))
6365
}
6466

6567
// Get information about a specific role for an account.
@@ -86,6 +88,18 @@ func (r *RoleService) Get(ctx context.Context, roleID string, query RoleGetParam
8688
type RoleListParams struct {
8789
// Account identifier tag.
8890
AccountID param.Field[string] `path:"account_id,required"`
91+
// Page number of paginated results.
92+
Page param.Field[float64] `query:"page"`
93+
// Number of roles per page.
94+
PerPage param.Field[float64] `query:"per_page"`
95+
}
96+
97+
// URLQuery serializes [RoleListParams]'s query parameters as `url.Values`.
98+
func (r RoleListParams) URLQuery() (v url.Values) {
99+
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
100+
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
101+
NestedFormat: apiquery.NestedQueryFormatDots,
102+
})
89103
}
90104

91105
type RoleGetParams struct {

‎accounts/role_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/cloudflare/cloudflare-go/v4/option"
1515
)
1616

17-
func TestRoleList(t *testing.T) {
17+
func TestRoleListWithOptionalParams(t *testing.T) {
1818
baseURL := "http://localhost:4010"
1919
if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
2020
baseURL = envURL
@@ -29,6 +29,8 @@ func TestRoleList(t *testing.T) {
2929
)
3030
_, err := client.Accounts.Roles.List(context.TODO(), accounts.RoleListParams{
3131
AccountID: cloudflare.F("eb78d65290b24279ba6f44721b3ea3c4"),
32+
Page: cloudflare.F(1.000000),
33+
PerPage: cloudflare.F(5.000000),
3234
})
3335
if err != nil {
3436
var apierr *cloudflare.Error

‎api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Methods:
7070

7171
Methods:
7272

73-
- <code title="get /accounts/{account_id}/roles">client.Accounts.Roles.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleListParams">RoleListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#SinglePage">SinglePage</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared#Role">Role</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
73+
- <code title="get /accounts/{account_id}/roles">client.Accounts.Roles.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleService.List">List</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, params <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleListParams">RoleListParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination">pagination</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/packages/pagination#V4PagePaginationArray">V4PagePaginationArray</a>[<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared#Role">Role</a>], <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
7474
- <code title="get /accounts/{account_id}/roles/{role_id}">client.Accounts.Roles.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleService.Get">Get</a>(ctx <a href="https://pkg.go.dev/context">context</a>.<a href="https://pkg.go.dev/context#Context">Context</a>, roleID <a href="https://pkg.go.dev/builtin#string">string</a>, query <a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts">accounts</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/accounts#RoleGetParams">RoleGetParams</a>) (<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared">shared</a>.<a href="https://pkg.go.dev/github.com/cloudflare/cloudflare-go/v4/shared#Role">Role</a>, <a href="https://pkg.go.dev/builtin#error">error</a>)</code>
7575

7676
## Subscriptions

0 commit comments

Comments
 (0)
Please sign in to comment.