[capital] Code generation: update services and models - #525
[capital] Code generation: update services and models#525AdyenAutomationBot wants to merge 1 commit into
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 updates 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 auto-generated code for the capital service. The generated code is largely functional, but I've identified a few areas for improvement that likely stem from the OpenAPI generator configuration or templates.
The most significant issue is that API methods return struct values instead of pointers. This is not idiomatic Go and can lead to incorrect handling of error cases. I've recommended changing these to return pointers.
Additionally, I've found some unexported and unused validation functions (isValid...) in the model files, which are dead code and should be removed. There are also minor formatting issues in some comments that affect readability.
Addressing these issues in the generator templates will improve the quality and maintainability of the generated code.
| func (a *GrantAccountsApi) GetGrantAccountInformation(ctx context.Context, r GrantAccountsApiGetGrantAccountInformationInput) (GrantAccount, *http.Response, error) { | ||
| res := &GrantAccount{} | ||
| path := "/grantAccounts/{id}" | ||
| path = strings.Replace(path, "{"+"id"+"}", url.PathEscape(common.ParameterValueToString(r.id, "id")), -1) | ||
| queryParams := url.Values{} | ||
| headerParams := make(map[string]string) | ||
| httpRes, err := common.SendAPIRequest( | ||
| ctx, | ||
| a.Client, | ||
| nil, | ||
| res, | ||
| http.MethodGet, | ||
| a.BasePath()+path, | ||
| queryParams, | ||
| headerParams, | ||
| ) | ||
|
|
||
| return *res, httpRes, err | ||
| } |
There was a problem hiding this comment.
The function GetGrantAccountInformation returns a struct value GrantAccount instead of a pointer *GrantAccount. In Go, it's idiomatic for functions that can fail to return a pointer type for structs. This allows returning nil on error, making it clear to the caller that the returned object is invalid.
Currently, if an error occurs, this function returns a zero-value GrantAccount struct along with the error. A caller might mistakenly use this zero-value struct without checking the error.
It is recommended to change the function signature to return (*GrantAccount, *http.Response, error) and return nil for the GrantAccount on error.
| func (a *GrantOffersApi) GetAllGrantOffers(ctx context.Context, r GrantOffersApiGetAllGrantOffersInput) (GrantOffers, *http.Response, error) { | ||
| res := &GrantOffers{} | ||
| path := "/grantOffers" | ||
| queryParams := url.Values{} | ||
| headerParams := make(map[string]string) | ||
| if r.accountHolderId != nil { | ||
| common.ParameterAddToQuery(queryParams, "accountHolderId", r.accountHolderId, "") | ||
| } | ||
| httpRes, err := common.SendAPIRequest( | ||
| ctx, | ||
| a.Client, | ||
| nil, | ||
| res, | ||
| http.MethodGet, | ||
| a.BasePath()+path, | ||
| queryParams, | ||
| headerParams, | ||
| ) | ||
|
|
||
| return *res, httpRes, err | ||
| } |
There was a problem hiding this comment.
The function GetAllGrantOffers returns a struct value GrantOffers instead of a pointer *GrantOffers. In Go, it's idiomatic for functions that can fail to return a pointer type for structs. This allows returning nil on error, making it clear to the caller that the returned object is invalid.
Currently, if an error occurs, this function returns a zero-value GrantOffers struct along with the error. A caller might mistakenly use this zero-value struct without checking the error.
It is recommended to change the function signature to return (*GrantOffers, *http.Response, error) and return nil for the GrantOffers on error. This recommendation also applies to GetGrantOffer in this file.
| func (a *GrantsApi) GetAllGrantDisbursements(ctx context.Context, r GrantsApiGetAllGrantDisbursementsInput) (Disbursements, *http.Response, error) { | ||
| res := &Disbursements{} | ||
| path := "/grants/{grantId}/disbursements" | ||
| path = strings.Replace(path, "{"+"grantId"+"}", url.PathEscape(common.ParameterValueToString(r.grantId, "grantId")), -1) | ||
| queryParams := url.Values{} | ||
| headerParams := make(map[string]string) | ||
| httpRes, err := common.SendAPIRequest( | ||
| ctx, | ||
| a.Client, | ||
| nil, | ||
| res, | ||
| http.MethodGet, | ||
| a.BasePath()+path, | ||
| queryParams, | ||
| headerParams, | ||
| ) | ||
|
|
||
| return *res, httpRes, err | ||
| } |
There was a problem hiding this comment.
The function GetAllGrantDisbursements returns a struct value Disbursements instead of a pointer *Disbursements. In Go, it's idiomatic for functions that can fail to return a pointer type for structs. This allows returning nil on error, making it clear to the caller that the returned object is invalid.
Currently, if an error occurs, this function returns a zero-value Disbursements struct along with the error. A caller might mistakenly use this zero-value struct without checking the error.
It is recommended to change the function signature to return (*Disbursements, *http.Response, error) and return nil for the Disbursements on error. This recommendation applies to all API methods in this file that return a struct value.
|
|
||
| /* | ||
| Prepare a request for GetGrantDisbursement | ||
| @param grantId The unique identifier of the grant reference.@param disbursementId The unique identifier of the disbursement. |
There was a problem hiding this comment.
There's a formatting issue in the comment. The descriptions for @param grantId and @param disbursementId are concatenated without a space or newline, which makes it harder to read. This should be fixed for better documentation clarity. A similar issue exists on line 273.
| @param grantId The unique identifier of the grant reference.@param disbursementId The unique identifier of the disbursement. | |
| @param grantId The unique identifier of the grant reference. @param disbursementId The unique identifier of the disbursement. |
| func (o *GrantOffer) isValidContractType() bool { | ||
| var allowedEnumValues = []string{"cashAdvance", "loan"} | ||
| for _, allowed := range allowedEnumValues { | ||
| if o.GetContractType() == allowed { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
There was a problem hiding this comment.
The function isValidContractType is unexported and appears to be unused within the codebase. This constitutes dead code, which can increase maintenance overhead and cause confusion. It should be removed if it's not intended to be used. A similar unused function isValidCode exists in model_status.go.
0f630fc to
cc12f8e
Compare
7a5a54f to
40b2723
Compare
4d5af33 to
728a61c
Compare
5d54866 to
ff132da
Compare
f53d69c to
c453642
Compare
4050bb9 to
ef82008
Compare
bbaf2f8 to
b3581bb
Compare
21f247f to
9735718
Compare
602874f to
6d49e4b
Compare
6acd6e5 to
9779a09
Compare
d7d8287 to
1593bb2
Compare
db85eab to
b0280fa
Compare
4b163be to
e4a62e9
Compare
ad89b29 to
d2ab79e
Compare
8709d3b to
edc05df
Compare
This PR contains the automated changes for the
capitalservice.The commit history of this PR reflects the
adyen-openapicommits that have been applied.