Skip to content

[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

Closed
wants to merge 6 commits into from

Conversation

gcatanese
Copy link
Contributor

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

bool? threeDSAuthenticationOnly = false

to

bool? threeDSAuthenticationOnly = null

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 method type. Although not required in the OpenAPI spec, applications are expected to set the value when performing a payment.

@gcatanese gcatanese requested a review from a team as a code owner July 16, 2025 12:25
Copy link

@gemini-code-assist gemini-code-assist bot left a 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 with null (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 the Type enum for various payment methods. This adjustment was necessary because the template change now initializes these optional Type fields to null by default, whereas previously they might have implicitly taken on a default enum value.
  • SessionResultResponse Model Expansion: The SessionResultResponse model has been expanded to include new properties: AdditionalData, Payments, and Reference. This update also includes corresponding changes to its constructor, ToString(), Equals(), and GetHashCode() 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

  1. 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.

Copy link

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@gcatanese
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

@gcatanese gcatanese requested a review from Kwok-he-Chu August 6, 2025 11:52
@@ -61,7 +61,7 @@ public enum TypeEnum
/// <param name="recurringDetailReference">This is the &#x60;recurringDetailReference&#x60; returned in the response when you created the token..</param>
/// <param name="storedPaymentMethodId">This is the &#x60;recurringDetailReference&#x60; returned in the response when you created the token..</param>
/// <param name="type">**rakutenpay** (default to TypeEnum.Rakutenpay).</param>
Copy link
Member

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?

Copy link
Member

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,
Copy link
Member

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>
Copy link
Member

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

@gcatanese gcatanese self-assigned this Aug 11, 2025
@gcatanese
Copy link
Contributor Author

@Kwok-he-Chu Given the impact on existing integrations we will address this within the upgrade of the OpenAPI Generator

@gcatanese gcatanese closed this Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants