Skip to content

Dotnet/patch/32.2.2#102

Draft
galesky-a wants to merge 26 commits intomainfrom
dotnet/patch/32.2.2
Draft

Dotnet/patch/32.2.2#102
galesky-a wants to merge 26 commits intomainfrom
dotnet/patch/32.2.2

Conversation

@galesky-a
Copy link
Contributor

@galesky-a galesky-a commented Feb 11, 2026

Description

This PR introduces a "graceful fail" mechanism for enum deserialization. It ensures that when the Adyen API adds new enum values, the SDK remains functional by treating unknown values as null rather than throwing a JsonSerializationException.

Related PRs and runs:

  • Generated code triggered by this action
  • SDK Automation to target this branch and skip unsupported fields (ex: oneOf, allOf). Note that the only change from 31.1.3 is that LEM was bumped from V3 to V4.
  • Tests run for Dotnet 8.0 and 6.0

Key Changes

  • Added SafeStringEnumConverter, which extends StringEnumConverter. It catches serialization exceptions for unknown enum members and returns null for nullable enum types.
  • Registered the new converter in JsonOperation.Deserialize() to apply it across all SDK operations.
  • Modified modelGeneric.mustache to ensure all generated enum properties and constructor arguments are nullable, regardless of whether they are "required" in the API specification.. This is the most impactful change, this should always have been the case, it's the behavior the API was modeled to have, hence this change is considered a bugfix

Testing Infrastructure:

  • Added test suite (SafeStringEnumConverterTest.cs) to verify that unknown enum values deserialize to null while known values continue to work as expected.

How to verify

  • Run the new test suite: Adyen.Test/SafeStringEnumConverterTest.cs.
  • Observe that providing an unknown string to a nullable enum field no longer crashes the JsonConvert process.

@gemini-code-assist
Copy link

Summary of Changes

Hello @galesky-a, 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 refines the build process for the .NET SDK by introducing several automation steps. It ensures a consistent OpenAPI specification version is used, proactively removes problematic discriminator schemas that might cause issues during .NET code generation, and enhances the robustness of enum serialization in the generated C# models by applying a safer converter.

Highlights

  • OpenAPI Spec Pinning: The OpenAPI specification used for code generation is now pinned to a specific Git commit (a9d350f) and cloned with a shallow history since a specific date, ensuring consistent spec versions.
  • Discriminator Schema Removal for .NET: A new build step has been introduced specifically for the .NET project to automatically identify and remove OpenAPI schemas that use discriminators, along with any other schemas or API paths that reference them, prior to code generation. This addresses potential issues with discriminator patterns in the generated .NET SDK.
  • Safe Enum Converter Post-processing: A post-processing step has been added to replace StringEnumConverter with Adyen.Util.SafeStringEnumConverter in all generated C# model files for the .NET SDK, enhancing the robustness of enum serialization and deserialization.

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

Changelog
  • build.gradle
    • Updated the specs task to use --shallow-since for cloning and added a git checkout command to pin the OpenAPI spec to a specific commit.
  • buildSrc/src/main/groovy/adyen.sdk-automation-conventions.gradle
    • Added a new removeDiscriminatorSchemas task that identifies and removes OpenAPI schemas with discriminators and their references for the .NET project.
    • Linked this new task as a dependency for the generate tasks.
  • dotnet/build.gradle
    • Introduced a postProcess task to replace StringEnumConverter with SafeStringEnumConverter in generated C# model files.
    • Updated the deployModels task to depend on the new postProcess task.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/gradle.yml
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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

  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

@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 updates the build process for the dotnet project. It pins the OpenAPI specification to a specific commit, adds a new task to remove schemas with discriminators before code generation for dotnet, and adds another post-processing task to replace StringEnumConverter. My review focuses on potential issues with future dates in the git commands, improving the robustness of a new task, and making a regex more resilient. Overall, the changes are logical, but a few adjustments are recommended for correctness and maintainability.

build.gradle Outdated
group 'setup'
description 'Clone OpenAPI spec (and apply local patches).'
commandLine 'git', 'clone', '--depth', '2', uri, specsDir
commandLine 'git', 'clone', '--shallow-since=2025-10-23', uri, specsDir

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The date 2025-09-01 used in --shallow-since is in the future. This is likely a typo and may cause git clone to behave unexpectedly (e.g., cloning the entire repository history or failing). Please use a past date to ensure the command works as intended.

doLast {
exec {
workingDir specsDir
commandLine 'git', 'checkout', 'a9d350f' // same date as .NET 32.1.3 , --before="2025-09-11 15:56:38 +0200"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment contains a future date 2025-09-11. This appears to be a typo. To avoid confusion, please correct the date in the comment.

if (newFound.isEmpty()) break
schemasToRemove.addAll(newFound)
iteration++
if (iteration > 10) break // Safety limit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The safety limit of 10 iterations is a good defensive measure. However, if this limit is reached, the loop will break silently. This could lead to an incomplete removal of schemas, which might be hard to debug. Consider logging a warning if the iteration limit is exceeded to make such a situation more visible.

if (iteration > 10) {
    println "WARNING: Schema removal for ${svc.name} for dotnet exceeded 10 iterations. The list of removed schemas may be incomplete."
    break // Safety limit
}

Comment on lines +43 to +44
/\[JsonConverter\(typeof\(StringEnumConverter\)\)\]/,
'[JsonConverter(typeof(Adyen.Util.SafeStringEnumConverter))]'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The regular expression used to find [JsonConverter(typeof(StringEnumConverter))] is quite specific and might break if there are any variations in whitespace, for example, if a code formatter is run on the generated files. Using a more flexible regex that allows for optional whitespace would make this script more robust.

                            /^\[\s*JsonConverter\s*\(\s*typeof\s*\(\s*StringEnumConverter\s*\)\s*\)\s*\]$/,
                            '[JsonConverter(typeof(Adyen.Util.SafeStringEnumConverter))]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant