From 92d698c046f32d0392030e33f4804ef957451aab Mon Sep 17 00:00:00 2001 From: namratabhadauriya Date: Fri, 28 Apr 2023 03:05:21 +0530 Subject: [PATCH] fix(Example Service): re-gen service after traits schema change (#250) Signed-off-by: namratabhadauriya --- .../enterprise_management_v1.go | 23 ++++++++++- .../enterprise_management_v1_test.go | 40 +++++++++++++++---- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/enterprisemanagementv1/enterprise_management_v1.go b/enterprisemanagementv1/enterprise_management_v1.go index 86dbf1a2..7366b27e 100644 --- a/enterprisemanagementv1/enterprise_management_v1.go +++ b/enterprisemanagementv1/enterprise_management_v1.go @@ -1486,7 +1486,7 @@ type CreateAccountOptions struct { // The traits object can be used to opt-out of Multi-Factor Authentication setting when creating a child account in the // enterprise. This is an optional field. - Traits map[string]interface{} `json:"traits,omitempty"` + Traits *CreateAccountRequestTraits `json:"traits,omitempty"` // Allows users to set headers on API requests Headers map[string]string @@ -1520,7 +1520,7 @@ func (_options *CreateAccountOptions) SetOwnerIamID(ownerIamID string) *CreateAc } // SetTraits : Allow user to set Traits -func (_options *CreateAccountOptions) SetTraits(traits map[string]interface{}) *CreateAccountOptions { +func (_options *CreateAccountOptions) SetTraits(traits *CreateAccountRequestTraits) *CreateAccountOptions { _options.Traits = traits return _options } @@ -1531,6 +1531,25 @@ func (options *CreateAccountOptions) SetHeaders(param map[string]string) *Create return options } +// CreateAccountRequestTraits : The traits object can be used to opt-out of Multi-Factor Authentication setting when creating a child account in the +// enterprise. This is an optional field. +type CreateAccountRequestTraits struct { + // By default MFA will be set on the account. To opt out, pass the traits object with the mfa field set to empty + // string. + Mfa *string `json:"mfa,omitempty"` +} + +// UnmarshalCreateAccountRequestTraits unmarshals an instance of CreateAccountRequestTraits from the specified map of raw messages. +func UnmarshalCreateAccountRequestTraits(m map[string]json.RawMessage, result interface{}) (err error) { + obj := new(CreateAccountRequestTraits) + err = core.UnmarshalPrimitive(m, "mfa", &obj.Mfa) + if err != nil { + return + } + reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj)) + return +} + // CreateAccountResponse : A newly-created account. type CreateAccountResponse struct { // The ID of the account entity that was created. diff --git a/enterprisemanagementv1/enterprise_management_v1_test.go b/enterprisemanagementv1/enterprise_management_v1_test.go index 2e1ee17a..ac377f3c 100644 --- a/enterprisemanagementv1/enterprise_management_v1_test.go +++ b/enterprisemanagementv1/enterprise_management_v1_test.go @@ -1178,12 +1178,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + // Construct an instance of the CreateAccountOptions model createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) createAccountOptionsModel.Parent = core.StringPtr("testString") createAccountOptionsModel.Name = core.StringPtr("testString") createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") - createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"} + createAccountOptionsModel.Traits = createAccountRequestTraitsModel createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Expect response parsing to fail since we are receiving a text/plain response result, response, operationErr := enterpriseManagementService.CreateAccount(createAccountOptionsModel) @@ -1248,12 +1252,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(enterpriseManagementService).ToNot(BeNil()) enterpriseManagementService.EnableRetries(0, 0) + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + // Construct an instance of the CreateAccountOptions model createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) createAccountOptionsModel.Parent = core.StringPtr("testString") createAccountOptionsModel.Name = core.StringPtr("testString") createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") - createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"} + createAccountOptionsModel.Traits = createAccountRequestTraitsModel createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with a Context to test a timeout error @@ -1326,12 +1334,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(response).To(BeNil()) Expect(result).To(BeNil()) + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + // Construct an instance of the CreateAccountOptions model createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) createAccountOptionsModel.Parent = core.StringPtr("testString") createAccountOptionsModel.Name = core.StringPtr("testString") createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") - createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"} + createAccountOptionsModel.Traits = createAccountRequestTraitsModel createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with valid options model (positive test) @@ -1349,12 +1361,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + // Construct an instance of the CreateAccountOptions model createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) createAccountOptionsModel.Parent = core.StringPtr("testString") createAccountOptionsModel.Name = core.StringPtr("testString") createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") - createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"} + createAccountOptionsModel.Traits = createAccountRequestTraitsModel createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation with empty URL (negative test) err := enterpriseManagementService.SetServiceURL("") @@ -1393,12 +1409,16 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(serviceErr).To(BeNil()) Expect(enterpriseManagementService).ToNot(BeNil()) + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + // Construct an instance of the CreateAccountOptions model createAccountOptionsModel := new(enterprisemanagementv1.CreateAccountOptions) createAccountOptionsModel.Parent = core.StringPtr("testString") createAccountOptionsModel.Name = core.StringPtr("testString") createAccountOptionsModel.OwnerIamID = core.StringPtr("testString") - createAccountOptionsModel.Traits = map[string]interface{}{"anyKey": "anyValue"} + createAccountOptionsModel.Traits = createAccountRequestTraitsModel createAccountOptionsModel.Headers = map[string]string{"x-custom-header": "x-custom-value"} // Invoke operation @@ -3127,6 +3147,12 @@ var _ = Describe(`EnterpriseManagementV1`, func() { Expect(createAccountGroupOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewCreateAccountOptions successfully`, func() { + // Construct an instance of the CreateAccountRequestTraits model + createAccountRequestTraitsModel := new(enterprisemanagementv1.CreateAccountRequestTraits) + Expect(createAccountRequestTraitsModel).ToNot(BeNil()) + createAccountRequestTraitsModel.Mfa = core.StringPtr("testString") + Expect(createAccountRequestTraitsModel.Mfa).To(Equal(core.StringPtr("testString"))) + // Construct an instance of the CreateAccountOptions model createAccountOptionsParent := "testString" createAccountOptionsName := "testString" @@ -3135,13 +3161,13 @@ var _ = Describe(`EnterpriseManagementV1`, func() { createAccountOptionsModel.SetParent("testString") createAccountOptionsModel.SetName("testString") createAccountOptionsModel.SetOwnerIamID("testString") - createAccountOptionsModel.SetTraits(map[string]interface{}{"anyKey": "anyValue"}) + createAccountOptionsModel.SetTraits(createAccountRequestTraitsModel) createAccountOptionsModel.SetHeaders(map[string]string{"foo": "bar"}) Expect(createAccountOptionsModel).ToNot(BeNil()) Expect(createAccountOptionsModel.Parent).To(Equal(core.StringPtr("testString"))) Expect(createAccountOptionsModel.Name).To(Equal(core.StringPtr("testString"))) Expect(createAccountOptionsModel.OwnerIamID).To(Equal(core.StringPtr("testString"))) - Expect(createAccountOptionsModel.Traits).To(Equal(map[string]interface{}{"anyKey": "anyValue"})) + Expect(createAccountOptionsModel.Traits).To(Equal(createAccountRequestTraitsModel)) Expect(createAccountOptionsModel.Headers).To(Equal(map[string]string{"foo": "bar"})) }) It(`Invoke NewCreateEnterpriseOptions successfully`, func() {