[configurationwebhooks] Code generation: update services and models#1799
[configurationwebhooks] Code generation: update services and models#1799AdyenAutomationBot wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello, 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 introduces new data models and webhook handling logic to support mandate notifications, specifically focusing on BACS Direct Debit. It also updates the description of the Highlights
🧠 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. Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces new models and webhook handling for Mandate notifications. The changes include adding MandateNotificationRequest, Mandate, MandateBankAccount, MandateBankAccountAccountIdentification, MandateNotificationData, MandatePartyIdentification, and UKLocalMandateAccountIdentification classes. Additionally, the ConfigurationWebhooksHandler has been updated to include a method for processing MandateNotificationRequest.
My review identified several areas for improvement related to error handling consistency and code efficiency, particularly in how enum values are validated and how null values are managed during deserialization. Addressing these points will enhance the robustness and maintainability of the new code.
| // TODO: there is no validation against JSON schema constraints | ||
| // (min, max, enum, pattern...), this does not perform a strict JSON | ||
| // validation, which means the 'match' count may be higher than it should be. | ||
| match++; |
There was a problem hiding this comment.
The TODO comment highlights a significant limitation: strict JSON schema constraints (e.g., min, max, enum, pattern) are not validated during deserialization. This can lead to incorrect data interpretation or unexpected behavior if the input JSON partially matches multiple oneOf schemas. Implementing more robust validation is crucial for data integrity.
| for (var value : MandateNotificationRequest.TypeEnum.values()) { | ||
| if (value.equals(optionalMandateNotificationRequest.get().getType())) { | ||
| // found matching event type | ||
| return optionalMandateNotificationRequest; | ||
| } | ||
| } |
There was a problem hiding this comment.
The explicit loop to verify the event type is redundant. If optionalMandateNotificationRequest.get().getType() is not null, it means the deserialization was successful and the type is a valid enum value. The fromValue method within the enum itself handles the validation of the string value. A simpler check for null is sufficient here.
if (optionalMandateNotificationRequest.isPresent() && optionalMandateNotificationRequest.get().getType() != null) {
return optionalMandateNotificationRequest;
}| public static StatusEnum fromValue(String value) { | ||
| for (StatusEnum b : StatusEnum.values()) { | ||
| if (b.value.equals(value)) { | ||
| return b; | ||
| } | ||
| } | ||
| // handling unexpected value | ||
| LOG.warning( | ||
| "StatusEnum: unexpected enum value '" | ||
| + value | ||
| + "' - Supported values are " | ||
| + Arrays.toString(StatusEnum.values())); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Returning null from the fromValue method for an unexpected enum value can lead to NullPointerException at the call site if not explicitly handled. It is generally safer and clearer to throw an IllegalArgumentException to indicate an invalid input. This makes the contract of the method more explicit and prevents silent failures.
| public static StatusEnum fromValue(String value) { | |
| for (StatusEnum b : StatusEnum.values()) { | |
| if (b.value.equals(value)) { | |
| return b; | |
| } | |
| } | |
| // handling unexpected value | |
| LOG.warning( | |
| "StatusEnum: unexpected enum value '" | |
| + value | |
| + "' - Supported values are " | |
| + Arrays.toString(StatusEnum.values())); | |
| return null; | |
| } | |
| @JsonCreator | |
| public static StatusEnum fromValue(String value) { | |
| for (StatusEnum b : StatusEnum.values()) { | |
| if (b.value.equals(value)) { | |
| return b; | |
| } | |
| } | |
| LOG.warning( | |
| "StatusEnum: unexpected enum value '" | |
| + value | |
| + "' - Supported values are " | |
| + Arrays.toString(StatusEnum.values())); | |
| throw new IllegalArgumentException("Unexpected value '" + value + "'"); | |
| } |
| for (TypeEnum b : TypeEnum.values()) { | ||
| if (b.value.equals(value)) { | ||
| return b; | ||
| } | ||
| } | ||
| // handling unexpected value | ||
| LOG.warning( | ||
| "TypeEnum: unexpected enum value '" | ||
| + value | ||
| + "' - Supported values are " | ||
| + Arrays.toString(TypeEnum.values())); | ||
| return null; | ||
| } | ||
| } |
There was a problem hiding this comment.
Similar to the StatusEnum, returning null from the fromValue method for an unexpected enum value can lead to NullPointerException. Throwing an IllegalArgumentException is a more robust approach to signal invalid input.
@JsonCreator
public static TypeEnum fromValue(String value) {
for (TypeEnum b : TypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
LOG.warning(
"TypeEnum: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(TypeEnum.values()));
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}| throw new IOException( | ||
| String.format( | ||
| "Failed deserialization for MandateBankAccountAccountIdentification: %d classes match result, expected 1", | ||
| match)); |
There was a problem hiding this comment.
There's an inconsistency in how null values are handled. The getNullValue method explicitly throws a JsonMappingException if null is encountered, suggesting null is an invalid state. However, the deserialize method returns null if no matching schema is found. This discrepancy can lead to confusing error handling paths. Consider aligning the strategy for null values to ensure consistent behavior.
| LOG.warning( | ||
| "TypeEnum: unexpected enum value '" | ||
| + value | ||
| + "' - Supported values are " | ||
| + Arrays.toString(TypeEnum.values())); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Similar to other enums, returning null from the fromValue method for an unexpected enum value can lead to NullPointerException. Throwing an IllegalArgumentException is a more robust approach to signal invalid input.
@JsonCreator
public static TypeEnum fromValue(String value) {
for (TypeEnum b : TypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
LOG.warning(
"TypeEnum: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(TypeEnum.values()));
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}| LOG.warning( | ||
| "TypeEnum: unexpected enum value '" | ||
| + value | ||
| + "' - Supported values are " | ||
| + Arrays.toString(TypeEnum.values())); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Similar to other enums, returning null from the fromValue method for an unexpected enum value can lead to NullPointerException. Throwing an IllegalArgumentException is a more robust approach to signal invalid input.
@JsonCreator
public static TypeEnum fromValue(String value) {
for (TypeEnum b : TypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
LOG.warning(
"TypeEnum: unexpected enum value '"
+ value
+ "' - Supported values are "
+ Arrays.toString(TypeEnum.values()));
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}
This PR contains the automated changes for the
configurationwebhooksservice.The commit history of this PR reflects the
adyen-openapicommits that have been applied.