[legalentitymanagement] Code generation: update services and models#1715
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates numerous model files in the Legal Entity Management module to improve enum handling during serialization and deserialization, specifically adding fallback logic for unknown values. Review feedback identifies a critical risk of NullReferenceException in the enum conversion operators across several files. Additionally, the updated logic in BankAccountInfoAccountIdentification was flagged for potentially breaking forward compatibility with the API and introducing unnecessary performance overhead due to redundant string conversions and lookups.
| if (value == TypeEnum.AuLocal) | ||
| return "auLocal"; | ||
|
|
||
| return null; | ||
| return value.Value; |
There was a problem hiding this comment.
The conversion operator is missing a null check for the value parameter. If value is null, the equality check value == TypeEnum.AuLocal will be false, and the subsequent access to value.Value will throw a NullReferenceException. This will cause crashes during serialization of any object where this enum property is null. This pattern appears to be repeated across all model files in this pull request.
if (value == TypeEnum.AuLocal)
return "auLocal";
return value?.Value;| if (aULocalAccountIdentification?.Type != null && AULocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)aULocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(aULocalAccountIdentification); | ||
|
|
||
| if (cALocalAccountIdentification?.Type != null) | ||
| if (cALocalAccountIdentification?.Type != null && CALocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)cALocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(cALocalAccountIdentification); | ||
|
|
||
| if (cZLocalAccountIdentification?.Type != null) | ||
| if (cZLocalAccountIdentification?.Type != null && CZLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)cZLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(cZLocalAccountIdentification); | ||
|
|
||
| if (dKLocalAccountIdentification?.Type != null) | ||
| if (dKLocalAccountIdentification?.Type != null && DKLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)dKLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(dKLocalAccountIdentification); | ||
|
|
||
| if (hKLocalAccountIdentification?.Type != null) | ||
| if (hKLocalAccountIdentification?.Type != null && HKLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)hKLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(hKLocalAccountIdentification); | ||
|
|
||
| if (hULocalAccountIdentification?.Type != null) | ||
| if (hULocalAccountIdentification?.Type != null && HULocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)hULocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(hULocalAccountIdentification); | ||
|
|
||
| if (ibanAccountIdentification?.Type != null) | ||
| if (ibanAccountIdentification?.Type != null && IbanAccountIdentification.TypeEnum.FromStringOrDefault((string?)ibanAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(ibanAccountIdentification); | ||
|
|
||
| if (nOLocalAccountIdentification?.Type != null) | ||
| if (nOLocalAccountIdentification?.Type != null && NOLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)nOLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(nOLocalAccountIdentification); | ||
|
|
||
| if (nZLocalAccountIdentification?.Type != null) | ||
| if (nZLocalAccountIdentification?.Type != null && NZLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)nZLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(nZLocalAccountIdentification); | ||
|
|
||
| if (numberAndBicAccountIdentification?.Type != null) | ||
| if (numberAndBicAccountIdentification?.Type != null && NumberAndBicAccountIdentification.TypeEnum.FromStringOrDefault((string?)numberAndBicAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(numberAndBicAccountIdentification); | ||
|
|
||
| if (pLLocalAccountIdentification?.Type != null) | ||
| if (pLLocalAccountIdentification?.Type != null && PLLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)pLLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(pLLocalAccountIdentification); | ||
|
|
||
| if (sELocalAccountIdentification?.Type != null) | ||
| if (sELocalAccountIdentification?.Type != null && SELocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)sELocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(sELocalAccountIdentification); | ||
|
|
||
| if (sGLocalAccountIdentification?.Type != null) | ||
| if (sGLocalAccountIdentification?.Type != null && SGLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)sGLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(sGLocalAccountIdentification); | ||
|
|
||
| if (uKLocalAccountIdentification?.Type != null) | ||
| if (uKLocalAccountIdentification?.Type != null && UKLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)uKLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(uKLocalAccountIdentification); | ||
|
|
||
| if (uSLocalAccountIdentification?.Type != null) | ||
| if (uSLocalAccountIdentification?.Type != null && USLocalAccountIdentification.TypeEnum.FromStringOrDefault((string?)uSLocalAccountIdentification.Type) != null) | ||
| return new BankAccountInfoAccountIdentification(uSLocalAccountIdentification); |
There was a problem hiding this comment.
The logic for identifying the correct account identification type has become significantly more restrictive and computationally expensive. By checking FromStringOrDefault(...) != null, the code now explicitly rejects any 'unknown' enum values that might be sent by the API for forward compatibility. If the API introduces a new type that should map to one of these classes but isn't yet in the SDK's hardcoded list, deserialization will now fail with a JsonException instead of potentially succeeding with an 'unknown' enum value. Additionally, performing a string conversion and a dictionary lookup for every single type check in a long if-else chain is inefficient.
This PR contains the automated changes for the
legalentitymanagementservice.The commit history of this PR reflects the
adyen-openapicommits that have been applied.