Context
In the generated JsonConverter for models with a required inner TypeEnum discriminator (e.g. CheckoutDelegatedAuthenticationAction, CheckoutThreeDS2Action, CheckoutRedirectAction), a JSON payload containing "type": null is not rejected as it should be. The current deserialization path:
- Reads
typeRawValue as null via utf8JsonReader.GetString()
- Calls
TypeEnum.FromStringOrDefault(null) → returns null
- Falls back to implicit cast
(TypeEnum)(string?)null → also returns null
- Stores
null in new Option<TypeEnum?>(null) — IsSet becomes true
- The required-field guard
if (!type.IsSet) passes silently
- Assigns
null to the non-nullable TypeEnum Type property via type.Value!
This violates the non-nullable contract on Type and can lead to a NullReferenceException downstream.
Proposed Change
In JsonConverter.mustache, when reading a required enum property, explicitly check for a null raw value before constructing the Option and throw a descriptive exception:
case "type":
string? typeRawValue = utf8JsonReader.GetString();
if (typeRawValue == null)
throw new JsonException("The 'type' property cannot be null for CheckoutDelegatedAuthenticationAction.");
type = new Option<TypeEnum?>(TypeEnum.FromStringOrDefault(typeRawValue) ?? (TypeEnum)typeRawValue);
break;
This pattern should be applied to all required enum fields in the template, not just discriminators.
Benefit
Prevents null from silently bypassing the required-field guard and being assigned to a non-nullable property, replacing a potential NullReferenceException at call-site with a clear JsonException at deserialization time.
Notes
Low priority issue.
The Adyen API will never send "type": null in a valid response, so the bug only affects malformed or manually crafted JSON payloads and edge cases in testing. When triggered, the consequence is a NullReferenceException at a later access site rather than a clear JsonException at deserialization time, making the failure harder to diagnose.
It would be a valid improvement but it doesn't affect the API behaviour.
Context
In the generated
JsonConverterfor models with a required innerTypeEnumdiscriminator (e.g.CheckoutDelegatedAuthenticationAction,CheckoutThreeDS2Action,CheckoutRedirectAction), a JSON payload containing"type": nullis not rejected as it should be. The current deserialization path:typeRawValueasnullviautf8JsonReader.GetString()TypeEnum.FromStringOrDefault(null)→ returnsnull(TypeEnum)(string?)null→ also returnsnullnullinnew Option<TypeEnum?>(null)—IsSetbecomestrueif (!type.IsSet)passes silentlynullto the non-nullableTypeEnum Typeproperty viatype.Value!This violates the non-nullable contract on
Typeand can lead to aNullReferenceExceptiondownstream.Proposed Change
In
JsonConverter.mustache, when reading a required enum property, explicitly check for a null raw value before constructing theOptionand throw a descriptive exception:This pattern should be applied to all required enum fields in the template, not just discriminators.
Benefit
Prevents
nullfrom silently bypassing the required-field guard and being assigned to a non-nullable property, replacing a potentialNullReferenceExceptionat call-site with a clearJsonExceptionat deserialization time.Notes
Low priority issue.
The Adyen API will never send
"type": nullin a valid response, so the bug only affects malformed or manually crafted JSON payloads and edge cases in testing. When triggered, the consequence is aNullReferenceExceptionat a later access site rather than a clearJsonExceptionat deserialization time, making the failure harder to diagnose.It would be a valid improvement but it doesn't affect the API behaviour.