feat(verify2): Add template_id support#612
Conversation
There was a problem hiding this comment.
Pull request overview
Adds template_id support to Verify v2 verification requests, enabling clients to set a custom template when serializing requests to JSON.
Changes:
- Added
templateIdfield, getter, and builder setter toVerificationRequestwith JSON property mapping totemplate_id. - Added unit test coverage for JSON serialization with and without
template_id, using JSON resource fixtures. - Documented the feature addition in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/vonage/client/verify2/VerificationRequest.java | Adds templateId to the request model + builder and maps it to template_id in JSON. |
| src/test/java/com/vonage/client/verify2/VerificationRequestTest.java | Adds a helper to load JSON fixtures and a new test validating template_id serialization behavior. |
| src/test/resources/com/vonage/client/verify2/verification-request-with-template-id.json | JSON fixture for requests that include template_id. |
| src/test/resources/com/vonage/client/verify2/verification-request-without-template-id.json | JSON fixture for requests that omit template_id. |
| CHANGELOG.md | Notes Verify v2 template_id support in the unreleased section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| /** | ||
| * A custom template ID to use for the verification. This parameter works only when | ||
| * the channel is SMS or RCS. |
There was a problem hiding this comment.
The Javadoc says template_id works when the channel is SMS or RCS, but this module’s Channel enum doesn’t include RCS (and there’s no RCS workflow implementation in verify2). This makes the documentation misleading; either add RCS support here or update the docs to reflect the actually supported channels.
| * the channel is SMS or RCS. | |
| * the channel is SMS. |
| * @return This builder. | ||
| */ | ||
| public Builder templateId(String templateId) { |
There was a problem hiding this comment.
Builder.templateId(...) is documented as only applicable to certain channels, but the request constructor/builder doesn’t validate this (and also accepts blank/whitespace values). Consider rejecting empty template IDs and enforcing that templateId is only set when the workflows are compatible (e.g., SMS-only), similar to the existing validations for codeless workflows.
| * @return This builder. | |
| */ | |
| public Builder templateId(String templateId) { | |
| * @return This builder. | |
| * @throws IllegalArgumentException If {@code templateId} is {@code null} or blank. | |
| */ | |
| public Builder templateId(String templateId) { | |
| if (templateId == null || templateId.trim().isEmpty()) { | |
| throw new IllegalArgumentException("templateId must not be null or blank."); | |
| } |
|
|
||
| // Replace placeholders | ||
| for (int i = 0; i < placeholders.length; i += 2) { | ||
| if (i + 1 < placeholders.length) { | ||
| json = json.replace(placeholders[i], placeholders[i + 1]); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
loadJsonResource treats placeholders as key/value pairs but silently ignores a dangling key when an odd number of arguments is passed. This can mask test bugs; it would be safer to validate that placeholders.length is even and fail fast (e.g., throw IllegalArgumentException).
| // Replace placeholders | |
| for (int i = 0; i < placeholders.length; i += 2) { | |
| if (i + 1 < placeholders.length) { | |
| json = json.replace(placeholders[i], placeholders[i + 1]); | |
| } | |
| } | |
| // Validate that placeholders are in key/value pairs | |
| if (placeholders.length % 2 != 0) { | |
| throw new IllegalArgumentException( | |
| "Placeholders must be key/value pairs; received odd number: " + placeholders.length); | |
| } | |
| // Replace placeholders | |
| for (int i = 0; i < placeholders.length; i += 2) { | |
| json = json.replace(placeholders[i], placeholders[i + 1]); | |
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #612 +/- ##
=========================================
Coverage 98.93% 98.93%
- Complexity 3622 3623 +1
=========================================
Files 545 545
Lines 8004 8008 +4
Branches 443 443
=========================================
+ Hits 7919 7923 +4
Misses 64 64
Partials 21 21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add template_id support
Contribution Checklist