Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#1648)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored Apr 3, 2024
1 parent 7ba1742 commit 34791b4
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 201 deletions.
117 changes: 40 additions & 77 deletions accounts/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ type Member struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []MemberRole `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberUser `json:"user,required"`
JSON memberJSON `json:"-"`
Roles []Role `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 @@ -136,35 +136,6 @@ 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 MemberPermission `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 @@ -265,9 +236,9 @@ type MemberWithCode struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []MemberWithCodeRole `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithCodeUser `json:"user,required"`
Roles []Role `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 @@ -292,36 +263,6 @@ 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 MemberPermission `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 @@ -365,7 +306,7 @@ type MemberListResponse struct {
// Member Name.
Name string `json:"name,required,nullable"`
// Roles assigned to this Member.
Roles []Role `json:"roles,required"`
Roles []MemberListResponseRole `json:"roles,required"`
// A member's status in the organization.
Status MemberListResponseStatus `json:"status,required"`
JSON memberListResponseJSON `json:"-"`
Expand All @@ -391,6 +332,37 @@ 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 @@ -549,22 +521,13 @@ func (r MemberNewResponseEnvelopeSuccess) IsKnown() bool {
type MemberUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
// Roles assigned to this member.
Roles param.Field[[]MemberUpdateParamsRole] `json:"roles,required"`
Roles param.Field[[]RoleParam] `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 []MemberUpdateResponseEnvelopeErrors `json:"errors,required"`
Messages []MemberUpdateResponseEnvelopeMessages `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.MemberUpdateParamsRole{{
Roles: cloudflare.F([]accounts.RoleParam{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
Expand Down
53 changes: 46 additions & 7 deletions accounts/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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[Role], err error) {
func (r *RoleService) List(ctx context.Context, query RoleListParams, opts ...option.RequestOption) (res *pagination.SinglePage[RoleListResponse], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
Expand All @@ -53,7 +53,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[Role] {
func (r *RoleService) ListAutoPaging(ctx context.Context, query RoleListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[RoleListResponse] {
return pagination.NewSinglePageAutoPager(r.List(ctx, query, opts...))
}

Expand Down Expand Up @@ -106,11 +106,10 @@ 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"`
// Access permissions for this User.
Permissions []string `json:"permissions,required"`
JSON roleJSON `json:"-"`
// Role name.
Name string `json:"name,required"`
Permissions MemberPermission `json:"permissions,required"`
JSON roleJSON `json:"-"`
}

// roleJSON contains the JSON metadata for the struct [Role]
Expand All @@ -131,6 +130,46 @@ 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
}

// Union satisfied by [accounts.RoleGetResponseUnknown] or [shared.UnionString].
type RoleGetResponse interface {
ImplementsAccountsRoleGetResponse()
Expand Down
Loading

0 comments on commit 34791b4

Please sign in to comment.