Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Apr 5, 2024
1 parent 777334d commit 2566a69
Show file tree
Hide file tree
Showing 33 changed files with 2,028 additions and 5,416 deletions.
180 changes: 78 additions & 102 deletions accounts/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/user"
)

// MemberService contains methods and other services that help with interacting
Expand Down Expand Up @@ -113,10 +114,10 @@ type Member struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []Role `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberUser `json:"user,required"`
JSON memberJSON `json:"-"`
Roles []MemberRole `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberUser `json:"user,required"`
JSON memberJSON `json:"-"`
}

// memberJSON contains the JSON metadata for the struct [Member]
Expand All @@ -137,6 +138,35 @@ func (r memberJSON) RawJSON() string {
return r.raw
}

type MemberRole struct {
// Role identifier tag.
ID string `json:"id,required"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role name.
Name string `json:"name,required"`
Permissions user.Permission `json:"permissions,required"`
JSON memberRoleJSON `json:"-"`
}

// memberRoleJSON contains the JSON metadata for the struct [MemberRole]
type memberRoleJSON struct {
ID apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *MemberRole) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r memberRoleJSON) RawJSON() string {
return r.raw
}

type MemberUser struct {
// The contact email address of the user.
Email string `json:"email,required"`
Expand Down Expand Up @@ -171,75 +201,13 @@ func (r memberUserJSON) RawJSON() string {
return r.raw
}

type MemberPermission struct {
Analytics PermissionGrant `json:"analytics"`
Billing PermissionGrant `json:"billing"`
CachePurge PermissionGrant `json:"cache_purge"`
DNS PermissionGrant `json:"dns"`
DNSRecords PermissionGrant `json:"dns_records"`
Lb PermissionGrant `json:"lb"`
Logs PermissionGrant `json:"logs"`
Organization PermissionGrant `json:"organization"`
SSL PermissionGrant `json:"ssl"`
WAF PermissionGrant `json:"waf"`
ZoneSettings PermissionGrant `json:"zone_settings"`
Zones PermissionGrant `json:"zones"`
JSON memberPermissionJSON `json:"-"`
}

// memberPermissionJSON contains the JSON metadata for the struct
// [MemberPermission]
type memberPermissionJSON struct {
Analytics apijson.Field
Billing apijson.Field
CachePurge apijson.Field
DNS apijson.Field
DNSRecords apijson.Field
Lb apijson.Field
Logs apijson.Field
Organization apijson.Field
SSL apijson.Field
WAF apijson.Field
ZoneSettings apijson.Field
Zones apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *MemberPermission) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r memberPermissionJSON) RawJSON() string {
return r.raw
}

type MemberPermissionParam struct {
Analytics param.Field[PermissionGrantParam] `json:"analytics"`
Billing param.Field[PermissionGrantParam] `json:"billing"`
CachePurge param.Field[PermissionGrantParam] `json:"cache_purge"`
DNS param.Field[PermissionGrantParam] `json:"dns"`
DNSRecords param.Field[PermissionGrantParam] `json:"dns_records"`
Lb param.Field[PermissionGrantParam] `json:"lb"`
Logs param.Field[PermissionGrantParam] `json:"logs"`
Organization param.Field[PermissionGrantParam] `json:"organization"`
SSL param.Field[PermissionGrantParam] `json:"ssl"`
WAF param.Field[PermissionGrantParam] `json:"waf"`
ZoneSettings param.Field[PermissionGrantParam] `json:"zone_settings"`
Zones param.Field[PermissionGrantParam] `json:"zones"`
}

func (r MemberPermissionParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberWithCode struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []Role `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithCodeUser `json:"user,required"`
Roles []MemberWithCodeRole `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithCodeUser `json:"user,required"`
// The unique activation code for the account membership.
Code string `json:"code"`
JSON memberWithCodeJSON `json:"-"`
Expand All @@ -264,6 +232,36 @@ func (r memberWithCodeJSON) RawJSON() string {
return r.raw
}

type MemberWithCodeRole struct {
// Role identifier tag.
ID string `json:"id,required"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role name.
Name string `json:"name,required"`
Permissions user.Permission `json:"permissions,required"`
JSON memberWithCodeRoleJSON `json:"-"`
}

// memberWithCodeRoleJSON contains the JSON metadata for the struct
// [MemberWithCodeRole]
type memberWithCodeRoleJSON struct {
ID apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *MemberWithCodeRole) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r memberWithCodeRoleJSON) RawJSON() string {
return r.raw
}

type MemberWithCodeUser struct {
// The contact email address of the user.
Email string `json:"email,required"`
Expand Down Expand Up @@ -307,7 +305,7 @@ type MemberListResponse struct {
// Member Name.
Name string `json:"name,required,nullable"`
// Roles assigned to this Member.
Roles []MemberListResponseRole `json:"roles,required"`
Roles []Role `json:"roles,required"`
// A member's status in the organization.
Status MemberListResponseStatus `json:"status,required"`
JSON memberListResponseJSON `json:"-"`
Expand All @@ -333,37 +331,6 @@ func (r memberListResponseJSON) RawJSON() string {
return r.raw
}

type MemberListResponseRole struct {
// Role identifier tag.
ID string `json:"id,required"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role Name.
Name string `json:"name,required"`
// Access permissions for this User.
Permissions []string `json:"permissions,required"`
JSON memberListResponseRoleJSON `json:"-"`
}

// memberListResponseRoleJSON contains the JSON metadata for the struct
// [MemberListResponseRole]
type memberListResponseRoleJSON struct {
ID apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *MemberListResponseRole) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r memberListResponseRoleJSON) RawJSON() string {
return r.raw
}

// A member's status in the organization.
type MemberListResponseStatus string

Expand Down Expand Up @@ -476,13 +443,22 @@ func (r MemberNewResponseEnvelopeSuccess) IsKnown() bool {
type MemberUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
// Roles assigned to this member.
Roles param.Field[[]RoleParam] `json:"roles,required"`
Roles param.Field[[]MemberUpdateParamsRole] `json:"roles,required"`
}

func (r MemberUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberUpdateParamsRole struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
}

func (r MemberUpdateParamsRole) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type MemberUpdateResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Expand Down
2 changes: 1 addition & 1 deletion accounts/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMemberUpdate(t *testing.T) {
"4536bcfad5faccb111b47003c79917fa",
accounts.MemberUpdateParams{
AccountID: cloudflare.F[any](map[string]interface{}{}),
Roles: cloudflare.F([]accounts.RoleParam{{
Roles: cloudflare.F([]accounts.MemberUpdateParamsRole{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
Expand Down
53 changes: 7 additions & 46 deletions accounts/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewRoleService(opts ...option.RequestOption) (r *RoleService) {
}

// Get all available roles for an account.
func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...option.RequestOption) (res *pagination.SinglePage[RoleListResponse], err error) {
func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...option.RequestOption) (res *pagination.SinglePage[Role], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
Expand All @@ -51,7 +51,7 @@ func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...op
}

// Get all available roles for an account.
func (r *RoleService) ListAutoPaging(ctx context.Context, query RoleListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[RoleListResponse] {
func (r *RoleService) ListAutoPaging(ctx context.Context, query RoleListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[Role] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}

Expand Down Expand Up @@ -104,10 +104,11 @@ type Role struct {
ID string `json:"id,required"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role name.
Name string `json:"name,required"`
Permissions MemberPermission `json:"permissions,required"`
JSON roleJSON `json:"-"`
// Role Name.
Name string `json:"name,required"`
// Access permissions for this User.
Permissions []string `json:"permissions,required"`
JSON roleJSON `json:"-"`
}

// roleJSON contains the JSON metadata for the struct [Role]
Expand All @@ -128,46 +129,6 @@ func (r roleJSON) RawJSON() string {
return r.raw
}

type RoleParam struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
}

func (r RoleParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

type RoleListResponse struct {
// Role identifier tag.
ID string `json:"id,required"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role Name.
Name string `json:"name,required"`
// Access permissions for this User.
Permissions []string `json:"permissions,required"`
JSON roleListResponseJSON `json:"-"`
}

// roleListResponseJSON contains the JSON metadata for the struct
// [RoleListResponse]
type roleListResponseJSON struct {
ID apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *RoleListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r roleListResponseJSON) RawJSON() string {
return r.raw
}

type RoleListParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
}
Expand Down
19 changes: 9 additions & 10 deletions alerting/destinationpagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (r *DestinationPagerdutyService) Delete(ctx context.Context, body Destinati
}

// Get a list of all configured PagerDuty services.
func (r *DestinationPagerdutyService) Get(ctx context.Context, query DestinationPagerdutyGetParams, opts ...option.RequestOption) (res *[]AlertingPagerduty, err error) {
func (r *DestinationPagerdutyService) Get(ctx context.Context, query DestinationPagerdutyGetParams, opts ...option.RequestOption) (res *[]Pagerduty, err error) {
opts = append(r.Options[:], opts...)
var env DestinationPagerdutyGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/alerting/v3/destinations/pagerduty", query.AccountID)
Expand All @@ -84,28 +84,27 @@ func (r *DestinationPagerdutyService) Link(ctx context.Context, tokenID string,
return
}

type AlertingPagerduty struct {
type Pagerduty struct {
// UUID
ID string `json:"id"`
// The name of the pagerduty service.
Name string `json:"name"`
JSON alertingPagerdutyJSON `json:"-"`
Name string `json:"name"`
JSON pagerdutyJSON `json:"-"`
}

// alertingPagerdutyJSON contains the JSON metadata for the struct
// [AlertingPagerduty]
type alertingPagerdutyJSON struct {
// pagerdutyJSON contains the JSON metadata for the struct [Pagerduty]
type pagerdutyJSON struct {
ID apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

func (r *AlertingPagerduty) UnmarshalJSON(data []byte) (err error) {
func (r *Pagerduty) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

func (r alertingPagerdutyJSON) RawJSON() string {
func (r pagerdutyJSON) RawJSON() string {
return r.raw
}

Expand Down Expand Up @@ -290,7 +289,7 @@ type DestinationPagerdutyGetParams struct {
type DestinationPagerdutyGetResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Result []AlertingPagerduty `json:"result,required,nullable"`
Result []Pagerduty `json:"result,required,nullable"`
// Whether the API call was successful
Success DestinationPagerdutyGetResponseEnvelopeSuccess `json:"success,required"`
ResultInfo DestinationPagerdutyGetResponseEnvelopeResultInfo `json:"result_info"`
Expand Down
Loading

0 comments on commit 2566a69

Please sign in to comment.