Skip to content

RegistrationRequest.User omitempty ineffective #77

@andrius4669

Description

@andrius4669

hello.
when i use RegisterWithContext func for the purpose of https://fusionauth.io/docs/v1/tech/apis/registrations#create-a-user-registration-for-an-existing-user such as

	res, errs, err := faClient.RegisterWithContext(
		ctx, userID, fusionauth.RegistrationRequest{
			GenerateAuthenticationToken: true,
			Registration: fusionauth.UserRegistration{
				ApplicationId: applicationID,
				Id:            rID,
				Username:      uname,
			},
			SkipRegistrationVerification: true,
		})

it always fails with errs.FieldErrors of map[user.email:[{Code:[blank]user.email Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] user.password:[{Code:[blank]user.password Data:map[] Message:You must specify the [user.password] property.}] user.username:[{Code:[blank]user.username Data:map[] Message:You must specify either the [user.email] or [user.username] property. If you are emailing the user you must specify the [user.email].}] userId:[{Code:[duplicate]userId Data:map[] Message:A User with Id [2bc3b58e-762a-40f8-b4cf-6dcc99ec09c8] already exists.}]]
which basically means that it simultaneously complains about user.email/user.password/user.username being empty and userId already existing (not a surprise, I didn't intend to create a new user).
however, when I do:

type faReg struct {
	DisableDomainBlock           bool                        `json:"disableDomainBlock"`
	GenerateAuthenticationToken  bool                        `json:"generateAuthenticationToken"`
	Registration                 fusionauth.UserRegistration `json:"registration,omitempty"`
	SendSetPasswordEmail         bool                        `json:"sendSetPasswordEmail"`
	SkipRegistrationVerification bool                        `json:"skipRegistrationVerification"`
	SkipVerification             bool                        `json:"skipVerification"`
}

func faDoReg(faClient *fusionauth.FusionAuthClient, ctx context.Context, userId string, request faReg) (*fusionauth.RegistrationResponse, *fusionauth.Errors, error) {
	var resp fusionauth.RegistrationResponse
	var errors fusionauth.Errors

	restClient := faClient.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/registration").
		WithUriSegment(userId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do(ctx)
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}

//...
	res, errs, err := faDoReg(
		faClient, ctx, userID, faReg{
			GenerateAuthenticationToken: true,
			Registration: fusionauth.UserRegistration{
				ApplicationId: applicationID,
				Id:            rID,
				Username:      uname,
			},
			SkipRegistrationVerification: true,
		})
//...

it works without issues, because User field was not included.

please consider making fusionauth.RegistrationRequest User field a pointer type so that omitempty works, as it is ineffective for structs, and the existence of omitempty here means that it was intended to be omittable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions