[transferwebhooks] Code generation: update services and models#1726
[transferwebhooks] Code generation: update services and models#1726AdyenAutomationBot wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @AdyenAutomationBot, 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 delivers an automated update to 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. Changelog
Activity
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. 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
|
There was a problem hiding this comment.
Code Review
This pull request appears to be auto-generated, updating services and models for transferwebhooks. The changes introduce a new InterchangeData model, update several enums, and modify deserialization logic to support the new model. My review identifies a few areas for improvement in the generated code, focusing on robustness, correctness, and maintainability. These suggestions might be best addressed by updating the underlying generator templates.
| public static TypeEnum fromValue(String 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.
Returning null for an unknown enum value can lead to NullPointerExceptions in consuming code if not handled carefully. It's generally safer to fail fast by throwing an exception for unknown values. Consider throwing an IllegalArgumentException instead.
public static TypeEnum fromValue(String value) {
for (TypeEnum b : TypeEnum.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "' for TypeEnum");
}| public enum TypeEnum { | ||
| ACCOUNTING(String.valueOf("accounting")), | ||
|
|
||
| TRACING(String.valueOf("tracing")), |
There was a problem hiding this comment.
With the addition of the TRACING enum member, the Javadoc for TypeEnum on line 475 is now outdated and could mislead developers. Please update it to include tracing as a possible value.
Suggested Javadoc:
/** The type of the transfer event. Possible values: **accounting**, **tracing**, **tracking**. */| boolean attemptParsing = true; | ||
| if (attemptParsing) { | ||
| // Checks if the unique type of the oneOf json matches any of the object TypeEnum values | ||
| boolean typeMatch = false; | ||
| if (tree.findValue("type") != null) { | ||
| typeMatch = | ||
| Arrays.stream(InterchangeData.TypeEnum.values()) | ||
| .anyMatch((t) -> t.getValue().equals(tree.findValue("type").asText())); | ||
| } | ||
|
|
||
| if (typeMatch) { | ||
| deserialized = tree.traverse(jp.getCodec()).readValueAs(InterchangeData.class); | ||
| // 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++; | ||
| log.log(Level.FINER, "Input data matches schema 'InterchangeData'"); | ||
| } | ||
| } |
There was a problem hiding this comment.
This deserialization logic can be made more robust and efficient.
- The
attemptParsingvariable and itsifcheck are redundant and can be removed. tree.findValue("type")is called twice and searches recursively, which can be inefficient and may not be what is intended for a discriminator field. Usingtree.get("type")is safer as it only looks at the top level of the JSON object.- It's good practice to check if the node is textual before calling
asText().
Since this code is likely auto-generated, this feedback may be best applied to the generator template. Here is a suggested improvement:
// Checks if the unique type of the oneOf json matches any of the object TypeEnum values
JsonNode typeNode = tree.get("type");
if (typeNode != null && typeNode.isTextual()) {
String typeValue = typeNode.asText();
boolean typeMatch =
Arrays.stream(InterchangeData.TypeEnum.values())
.anyMatch((t) -> t.getValue().equals(typeValue));
if (typeMatch) {
deserialized = tree.traverse(jp.getCodec()).readValueAs(InterchangeData.class);
// 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++;
log.log(Level.FINER, "Input data matches schema 'InterchangeData'");
}
}
This PR contains the automated changes for the
transferwebhooksservice.The commit history of this PR reflects the
adyen-openapicommits that have been applied.