[balanceplatform] Code generation: update services and models#523
[balanceplatform] Code generation: update services and models#523AdyenAutomationBot wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @AdyenAutomationBot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a comprehensive update to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces several new API services and models to the Balance Platform API. New API services include AuthorizedCardUsersApi for managing authorized users on cards, BalancesApi for configuring balance webhook settings, SCAAssociationManagementApi for approving, listing, and removing Strong Customer Authentication (SCA) device associations, SCADeviceManagementApi for initiating and completing SCA device registrations, and TransferLimitsBalanceAccountLevelApi and TransferLimitsBalancePlatformLevelApi for managing transfer limits at both account and platform levels. The AccountHoldersApi is updated to support filtering tax forms by legalEntityId, and the PaymentInstrumentsApi now includes functionality for network token provisioning and activation data. Numerous new models and enums are added to support these new functionalities, such as ApproveAssociationRequest, BalanceWebhookSettingInfo, CreateTransferLimitRequest, NetworkTokenActivationDataRequest, ScaDevice, ScaEntityType, LimitStatus, and TransferType. Existing models like AdditionalBankIdentification, BulkAddress, Card, CardConfiguration, CardInfo, DeviceInfo, SweepConfigurationV2, TransactionRule, TransactionRuleInfo, TransferRoute, and VerificationError have been updated with new fields, enum values, or clarified descriptions. The main APIClient is also updated to integrate these new services. Review comments highlight issues with the NewBalanceWebhookSetting constructor in model_balance_webhook_setting.go due to incorrect field initialization, and a recurring pattern of deprecated ioutil.ReadAll usage and unhandled errors in API service files, suggesting refactoring to use io.ReadAll and consolidated switch statements for error handling.
| func NewBalanceWebhookSetting(currency string, id string, status string, target Target, type_ SettingType) *BalanceWebhookSetting { | ||
| this := BalanceWebhookSetting{} | ||
| this.Currency = currency | ||
| this.Id = id | ||
| this.Status = status | ||
| this.Target = target | ||
| this.Type = type_ | ||
| return &this | ||
| } |
There was a problem hiding this comment.
The NewBalanceWebhookSetting constructor attempts to initialize fields (Currency, Id, Status, Target, Type) that are not part of the BalanceWebhookSetting struct. This will cause a compilation error.
It seems the intention was for BalanceWebhookSetting to embed the WebhookSetting struct, which contains these fields. The code generator appears to have produced incorrect code.
To make this compile, the assignments should be removed. However, this leaves the constructor with unused parameters and indicates a deeper issue with the struct definition that should be addressed in the code generator.
func NewBalanceWebhookSetting(currency string, id string, status string, target Target, type_ SettingType) *BalanceWebhookSetting {
this := BalanceWebhookSetting{}
return &this
}| var serviceError common.RestServiceError | ||
| if httpRes.StatusCode == 400 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return httpRes, decodeError | ||
| } | ||
| return httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 401 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return httpRes, decodeError | ||
| } | ||
| return httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 403 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return httpRes, decodeError | ||
| } | ||
| return httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 422 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return httpRes, decodeError | ||
| } | ||
| return httpRes, serviceError | ||
| } |
There was a problem hiding this comment.
The error handling logic in this block has several issues that are repeated across many new API methods in this pull request:
- Use of deprecated function:
ioutil.ReadAllhas been deprecated since Go 1.16. It should be replaced withio.ReadAll. - Ignored error: The error returned from
ReadAllis ignored (body, _ := ...). If reading the response body fails, this can lead to silent failures or panics. This error must be handled. - Code duplication: The same block of code is repeated for each HTTP status code check. This can be refactored into a
switchstatement to improve readability and maintainability.
Here is a suggested refactoring that addresses these points. Note that you will need to add "io" to your imports.
var serviceError common.RestServiceError
switch httpRes.StatusCode {
case 400, 401, 403, 422:
body, err := io.ReadAll(httpRes.Body)
if err != nil {
return httpRes, err
}
decodeError := json.Unmarshal(body, &serviceError)
if decodeError != nil {
return httpRes, decodeError
}
return httpRes, serviceError
}| var serviceError common.RestServiceError | ||
| if httpRes.StatusCode == 400 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 401 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 403 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 404 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 422 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 500 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } |
There was a problem hiding this comment.
The error handling logic in this block has several issues:
- Use of deprecated function:
ioutil.ReadAllhas been deprecated since Go 1.16. It should be replaced withio.ReadAll. - Ignored error: The error returned from
ReadAllis ignored (body, _ := ...). This can lead to silent failures or panics. This error must be handled. - Code duplication: The same block of code is repeated for each HTTP status code check. This can be refactored into a
switchstatement to improve readability and maintainability.
This pattern is present in multiple new API files in this PR. Here is a suggested refactoring. Note that you will need to add "io" to your imports.
var serviceError common.RestServiceError
switch httpRes.StatusCode {
case 400, 401, 403, 404, 422, 500:
body, err := io.ReadAll(httpRes.Body)
if err != nil {
return *res, httpRes, err
}
decodeError := json.Unmarshal(body, &serviceError)
if decodeError != nil {
return *res, httpRes, decodeError
}
return *res, httpRes, serviceError
}| var serviceError common.RestServiceError | ||
| if httpRes.StatusCode == 400 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 401 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 403 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 422 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } | ||
| if httpRes.StatusCode == 500 { | ||
| body, _ := ioutil.ReadAll(httpRes.Body) | ||
| decodeError := json.Unmarshal([]byte(body), &serviceError) | ||
| if decodeError != nil { | ||
| return *res, httpRes, decodeError | ||
| } | ||
| return *res, httpRes, serviceError | ||
| } |
There was a problem hiding this comment.
The error handling logic in this block has several issues:
- Use of deprecated function:
ioutil.ReadAllhas been deprecated since Go 1.16. It should be replaced withio.ReadAll. - Ignored error: The error returned from
ReadAllis ignored (body, _ := ...). This can lead to silent failures or panics. This error must be handled. - Code duplication: The same block of code is repeated for each HTTP status code check. This can be refactored into a
switchstatement to improve readability and maintainability.
This pattern is present in multiple new API files in this PR. Here is a suggested refactoring. Note that you will need to add "io" to your imports.
var serviceError common.RestServiceError
switch httpRes.StatusCode {
case 400, 401, 403, 422, 500:
body, err := io.ReadAll(httpRes.Body)
if err != nil {
return *res, httpRes, err
}
decodeError := json.Unmarshal(body, &serviceError)
if decodeError != nil {
return *res, httpRes, decodeError
}
return *res, httpRes, serviceError
}5459a80 to
1d2ac93
Compare
1d2ac93 to
358c668
Compare
358c668 to
b90f556
Compare
This PR contains the automated changes for the
balanceplatformservice.The commit history of this PR reflects the
adyen-openapicommits that have been applied.