-
Notifications
You must be signed in to change notification settings - Fork 122
[Checkout] Skip serialisation of attributes with default values #1170
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @gcatanese, 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 optimizes the serialization process for Checkout API models by ensuring that attributes with default values are not redundantly included in the request payload. This was achieved by modifying the code generation template to initialize optional parameters to null
and regenerating the affected models. The changes are validated with new and updated unit tests, and the SessionResultResponse
model also received an update with new fields.
Highlights
- Serialization Optimization: The core intent of this PR is to prevent attributes with default values from being included in the serialized API request payload unless they are explicitly set. This reduces redundant data sent to the API backend, aligning with OpenAPI specifications.
- Code Generation Template Update: The
modelGeneric.mustache
template, used for C# code generation, has been updated. It now initializes optional constructor parameters withnull
(if they have a default value and are not required) instead of their literal default values. This ensures that these fields are only serialized when a non-null value is explicitly assigned. - Checkout Model Regeneration: All Checkout API models have been regenerated to reflect the changes introduced by the updated code generation template. This results in numerous modifications to model constructors across various
Adyen/Model/Checkout/*.cs
files. - Unit Test Enhancements: New unit tests have been added to
SerializerTest.cs
to specifically verify that attributes with default values (e.g.,mode
,splitCardFundingSources
,threeDSAuthenticationOnly
) are correctly omitted from the serialized JSON when not explicitly set by the user. - Existing Test Adjustments: Existing unit tests in
PaymentMethodDetailsTest.cs
were updated to explicitly set theType
enum for various payment methods. This adjustment was necessary because the template change now initializes these optionalType
fields tonull
by default, whereas previously they might have implicitly taken on a default enum value. SessionResultResponse
Model Expansion: TheSessionResultResponse
model has been expanded to include new properties:AdditionalData
,Payments
, andReference
. This update also includes corresponding changes to its constructor,ToString()
,Equals()
, andGetHashCode()
methods.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
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 .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
Warning Gemini encountered an error creating the review. You can try again by commenting |
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively reduces the size of API request payloads by preventing attributes with default values from being serialized unless explicitly set. The changes include modifications to the Mustache template, regeneration of Checkout models, and addition of unit tests to verify the new behavior. The existing tests in PaymentMethodDetailsTest
were also updated to explicitly set the payment method type
.
@@ -61,7 +61,7 @@ public enum TypeEnum | |||
/// <param name="recurringDetailReference">This is the `recurringDetailReference` returned in the response when you created the token..</param> | |||
/// <param name="storedPaymentMethodId">This is the `recurringDetailReference` returned in the response when you created the token..</param> | |||
/// <param name="type">**rakutenpay** (default to TypeEnum.Rakutenpay).</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is now set to null
, can we find a way to initialize TypeEnum.Rakutenpay
in the constructor or as a separate field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we confirm that the backend defaults to the first enum value (e.g. Rakutenpay)?
@@ -11,6 +11,7 @@ public void TestAchPaymentMethod() | |||
{ | |||
var achDetails = new AchDetails | |||
{ | |||
Type = AchDetails.TypeEnum.Ach, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked as a breaking change - Developers will have to add this property after this change.
Suggestion: Can we make auto-populate this property? It seems like it could only have one possible value.
@@ -1,6 +1,7 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
|
|||
<PropertyGroup> | |||
<RootNamespace>Adyen</RootNamespace> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, it would take the Adyen
-.csproj as default
@Kwok-he-Chu Given the impact on existing integrations we will address this within the upgrade of the OpenAPI Generator |
Description
This PR prevents attributes with default values from being included in the serialised API request payload unless explicitly set. This avoids sending redundant fields that already handled by the API backend (matching the defaults defined in the OpenAPI spec).
Changes
Updated the
Mustache
template to skip initialising constructor parameters with default values.From
to
Note: if the constructor parameter is required then then it is initialised with the default value (if provided)
Regenerated Checkout models to reflect the change (other models will be handled by the SDK Automation Bot).
Added unit tests to verify the behaviour.
Note: existing tests in
PaymentMethodDetailsTest
have been updated to set explicitly the payment methodtype
. Although not required in the OpenAPI spec, applications are expected to set the value when performing a payment.