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 #1672

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
196 changes: 65 additions & 131 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 *MemberUpdateResponse, err error) {
func (r *MemberService) Update(ctx context.Context, memberID string, params MemberUpdateParams, opts ...option.RequestOption) (res *Member, 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 *MemberGetResponse, err error) {
func (r *MemberService) Get(ctx context.Context, memberID string, query MemberGetParams, opts ...option.RequestOption) (res *Member, err error) {
opts = append(r.Options[:], opts...)
var env MemberGetResponseEnvelope
path := fmt.Sprintf("accounts/%v/members/%s", query.AccountID, memberID)
Expand All @@ -111,22 +111,21 @@ func (r *MemberService) Get(ctx context.Context, memberID string, query MemberGe
}

type Member struct {
// Role identifier tag.
// 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 memberJSON `json:"-"`
// Roles assigned to this member.
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]
type memberJSON struct {
ID apijson.Field
Description apijson.Field
Name apijson.Field
Permissions apijson.Field
Roles apijson.Field
Status apijson.Field
User apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
Expand All @@ -139,20 +138,45 @@ func (r memberJSON) RawJSON() string {
return r.raw
}

type MemberParam struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
type MemberUser 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 memberUserJSON `json:"-"`
}

func (r MemberParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
// memberUserJSON contains the JSON metadata for the struct [MemberUser]
type memberUserJSON 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 *MemberUser) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}

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

type MemberWithInviteCode struct {
// Membership identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []Member `json:"roles,required"`
Roles []Role `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberWithInviteCodeUser `json:"user,required"`
// The unique activation code for the account membership.
Expand Down Expand Up @@ -215,68 +239,42 @@ func (r memberWithInviteCodeUserJSON) RawJSON() string {
return r.raw
}

type MemberUpdateResponse struct {
// Membership identifier tag.
type Role struct {
// Role identifier tag.
ID string `json:"id,required"`
// Roles assigned to this member.
Roles []Member `json:"roles,required"`
Status interface{} `json:"status,required"`
User MemberUpdateResponseUser `json:"user,required"`
JSON memberUpdateResponseJSON `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 roleJSON `json:"-"`
}

// memberUpdateResponseJSON contains the JSON metadata for the struct
// [MemberUpdateResponse]
type memberUpdateResponseJSON struct {
// roleJSON contains the JSON metadata for the struct [Role]
type roleJSON 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
}

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

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

type MemberUpdateResponseUser 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 memberUpdateResponseUserJSON `json:"-"`
}

// memberUpdateResponseUserJSON contains the JSON metadata for the struct
// [MemberUpdateResponseUser]
type memberUpdateResponseUserJSON 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 *MemberUpdateResponseUser) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
type RoleParam struct {
// Role identifier tag.
ID param.Field[string] `json:"id,required"`
}

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

type MemberListResponse struct {
Expand Down Expand Up @@ -351,70 +349,6 @@ 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 @@ -489,7 +423,7 @@ func (r MemberNewResponseEnvelopeSuccess) IsKnown() bool {
type MemberUpdateParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
// Roles assigned to this member.
Roles param.Field[[]MemberParam] `json:"roles,required"`
Roles param.Field[[]RoleParam] `json:"roles,required"`
}

func (r MemberUpdateParams) MarshalJSON() (data []byte, err error) {
Expand All @@ -499,7 +433,7 @@ func (r MemberUpdateParams) MarshalJSON() (data []byte, err error) {
type MemberUpdateResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Result MemberUpdateResponse `json:"result,required"`
Result Member `json:"result,required"`
// Whether the API call was successful
Success MemberUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON memberUpdateResponseEnvelopeJSON `json:"-"`
Expand Down Expand Up @@ -671,7 +605,7 @@ type MemberGetParams struct {
type MemberGetResponseEnvelope struct {
Errors []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"errors,required"`
Messages []shared.UnnamedSchemaRef3248f24329456e19dfa042fff9986f72 `json:"messages,required"`
Result MemberGetResponse `json:"result,required"`
Result Member `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.MemberParam{{
Roles: cloudflare.F([]accounts.RoleParam{{
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
}, {
ID: cloudflare.F("3536bcfad5faccb999b47003c79917fb"),
Expand Down
9 changes: 9 additions & 0 deletions accounts/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ 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 RoleListParams struct {
AccountID param.Field[interface{}] `path:"account_id,required"`
}
Expand Down
Loading