Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): update via SDK Studio #1671

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 130 additions & 94 deletions accounts/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (r *MemberService) New(ctx context.Context, params MemberNewParams, opts ..
}

// Modify an account member.
func (r *MemberService) Update(ctx context.Context, memberID string, params MemberUpdateParams, opts ...option.RequestOption) (res *Member, err error) {
func (r *MemberService) Update(ctx context.Context, memberID string, params MemberUpdateParams, opts ...option.RequestOption) (res *MemberUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
var env MemberUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%v/members/%s", params.AccountID, memberID)
Expand Down Expand Up @@ -98,7 +98,7 @@ func (r *MemberService) Delete(ctx context.Context, memberID string, params Memb
}

// Get information about a specific member of an account.
func (r *MemberService) Get(ctx context.Context, memberID string, query MemberGetParams, opts ...option.RequestOption) (res *Member, err error) {
func (r *MemberService) Get(ctx context.Context, memberID string, query MemberGetParams, opts ...option.RequestOption) (res *MemberGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env MemberGetResponseEnvelope
path := fmt.Sprintf("accounts/%v/members/%s", query.AccountID, memberID)
Expand All @@ -111,21 +111,22 @@ func (r *MemberService) Get(ctx context.Context, memberID string, query MemberGe
}

type Member struct {
// Membership identifier tag.
// Role 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:"-"`
// Description of role's permissions.
Description string `json:"description,required"`
// Role name.
Name string `json:"name,required"`
Permissions user.Permission `json:"permissions,required"`
JSON memberJSON `json:"-"`
}

// memberJSON contains the JSON metadata for the struct [Member]
type memberJSON struct {
ID apijson.Field
Roles apijson.Field
Status apijson.Field
User apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
Expand All @@ -138,36 +139,48 @@ func (r memberJSON) RawJSON() string {
return r.raw
}

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

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

type MemberWithInviteCode struct {
// Membership 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:"-"`
// Roles assigned to this member.
Roles []Member `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithInviteCodeUser `json:"user,required"`
// The unique activation code for the account membership.
Code string `json:"code"`
JSON memberWithInviteCodeJSON `json:"-"`
}

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

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

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

type MemberUser struct {
type MemberWithInviteCodeUser struct {
// The contact email address of the user.
Email string `json:"email,required"`
// Identifier
Expand All @@ -178,12 +191,13 @@ type MemberUser struct {
LastName string `json:"last_name,nullable"`
// Indicates whether two-factor authentication is enabled for the user account.
// Does not apply to API authentication.
TwoFactorAuthenticationEnabled bool `json:"two_factor_authentication_enabled"`
JSON memberUserJSON `json:"-"`
TwoFactorAuthenticationEnabled bool `json:"two_factor_authentication_enabled"`
JSON memberWithInviteCodeUserJSON `json:"-"`
}

// memberUserJSON contains the JSON metadata for the struct [MemberUser]
type memberUserJSON struct {
// memberWithInviteCodeUserJSON contains the JSON metadata for the struct
// [MemberWithInviteCodeUser]
type memberWithInviteCodeUserJSON struct {
Email apijson.Field
ID apijson.Field
FirstName apijson.Field
Expand All @@ -193,77 +207,44 @@ type memberUserJSON struct {
ExtraFields map[string]apijson.Field
}

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

func (r memberUserJSON) RawJSON() string {
func (r memberWithInviteCodeUserJSON) RawJSON() string {
return r.raw
}

type MemberWithInviteCode struct {
type MemberUpdateResponse struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []MemberWithInviteCodeRole `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithInviteCodeUser `json:"user,required"`
// The unique activation code for the account membership.
Code string `json:"code"`
JSON memberWithInviteCodeJSON `json:"-"`
Roles []Member `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberUpdateResponseUser `json:"user,required"`
JSON memberUpdateResponseJSON `json:"-"`
}

// memberWithInviteCodeJSON contains the JSON metadata for the struct
// [MemberWithInviteCode]
type memberWithInviteCodeJSON struct {
// memberUpdateResponseJSON contains the JSON metadata for the struct
// [MemberUpdateResponse]
type memberUpdateResponseJSON struct {
ID apijson.Field
Roles apijson.Field
Status apijson.Field
User apijson.Field
Code apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type MemberWithInviteCodeRole 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 memberWithInviteCodeRoleJSON `json:"-"`
}

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

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

func (r memberWithInviteCodeRoleJSON) RawJSON() string {
func (r memberUpdateResponseJSON) RawJSON() string {
return r.raw
}

type MemberWithInviteCodeUser struct {
type MemberUpdateResponseUser struct {
// The contact email address of the user.
Email string `json:"email,required"`
// Identifier
Expand All @@ -275,12 +256,12 @@ type MemberWithInviteCodeUser struct {
// Indicates whether two-factor authentication is enabled for the user account.
// Does not apply to API authentication.
TwoFactorAuthenticationEnabled bool `json:"two_factor_authentication_enabled"`
JSON memberWithInviteCodeUserJSON `json:"-"`
JSON memberUpdateResponseUserJSON `json:"-"`
}

// memberWithInviteCodeUserJSON contains the JSON metadata for the struct
// [MemberWithInviteCodeUser]
type memberWithInviteCodeUserJSON struct {
// memberUpdateResponseUserJSON contains the JSON metadata for the struct
// [MemberUpdateResponseUser]
type memberUpdateResponseUserJSON struct {
Email apijson.Field
ID apijson.Field
FirstName apijson.Field
Expand All @@ -290,11 +271,11 @@ type memberWithInviteCodeUserJSON struct {
ExtraFields map[string]apijson.Field
}

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

func (r memberWithInviteCodeUserJSON) RawJSON() string {
func (r memberUpdateResponseUserJSON) RawJSON() string {
return r.raw
}

Expand Down Expand Up @@ -370,6 +351,70 @@ func (r memberDeleteResponseJSON) RawJSON() string {
return r.raw
}

type MemberGetResponse struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []Member `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberGetResponseUser `json:"user,required"`
JSON memberGetResponseJSON `json:"-"`
}

// memberGetResponseJSON contains the JSON metadata for the struct
// [MemberGetResponse]
type memberGetResponseJSON struct {
ID apijson.Field
Roles apijson.Field
Status apijson.Field
User apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type MemberGetResponseUser struct {
// The contact email address of the user.
Email string `json:"email,required"`
// Identifier
ID string `json:"id"`
// User's first name
FirstName string `json:"first_name,nullable"`
// User's last name
LastName string `json:"last_name,nullable"`
// Indicates whether two-factor authentication is enabled for the user account.
// Does not apply to API authentication.
TwoFactorAuthenticationEnabled bool `json:"two_factor_authentication_enabled"`
JSON memberGetResponseUserJSON `json:"-"`
}

// memberGetResponseUserJSON contains the JSON metadata for the struct
// [MemberGetResponseUser]
type memberGetResponseUserJSON struct {
Email apijson.Field
ID apijson.Field
FirstName apijson.Field
LastName apijson.Field
TwoFactorAuthenticationEnabled apijson.Field
raw string
ExtraFields map[string]apijson.Field
}

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

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

type MemberNewParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
// The contact email address of the user.
Expand Down Expand Up @@ -444,26 +489,17 @@ 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[[]MemberParam] `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"`
Result Member `json:"result,required"`
Result MemberUpdateResponse `json:"result,required"`
// Whether the API call was successful
Success MemberUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON memberUpdateResponseEnvelopeJSON `json:"-"`
Expand Down Expand Up @@ -635,7 +671,7 @@ type MemberGetParams struct {
type MemberGetResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Result Member `json:"result,required"`
Result MemberGetResponse `json:"result,required"`
// Whether the API call was successful
Success MemberGetResponseEnvelopeSuccess `json:"success,required"`
JSON memberGetResponseEnvelopeJSON `json:"-"`
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.MemberParam{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
Expand Down
Loading