From 2bab995b8094305e09807384e3829874a79259a2 Mon Sep 17 00:00:00 2001 From: keigo habara <34413567+habara-k@users.noreply.github.com> Date: Wed, 30 Oct 2024 14:46:03 +0900 Subject: [PATCH] Fix bug: integer cannot be null (#496) * Fix bug: integer cannot be null * Refactor method name --- .../line/bot/generator/pebble/IsOmitEmptyFunction.java | 9 +++++++++ linebot/messaging_api/model_limit.go | 2 +- .../model_show_loading_animation_request.go | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/generator/src/main/java/line/bot/generator/pebble/IsOmitEmptyFunction.java b/generator/src/main/java/line/bot/generator/pebble/IsOmitEmptyFunction.java index bdcac172..a350ddaa 100644 --- a/generator/src/main/java/line/bot/generator/pebble/IsOmitEmptyFunction.java +++ b/generator/src/main/java/line/bot/generator/pebble/IsOmitEmptyFunction.java @@ -38,9 +38,18 @@ public Object execute(Map args, PebbleTemplate self, EvaluationC // such as imageBackgroundColor in ButtonsTemplate. return true; } + if (var.isInteger && isGreaterThanZero(var.minimum)) { + // For optional integer types with a minimum value greater than 0, + // it's acceptable to treat 0 as a null value + return true; + } if (var.isPrimitiveType) { return false; } return true; } + + private boolean isGreaterThanZero(String val) { + return val != null && Integer.parseInt(val) > 0; + } } diff --git a/linebot/messaging_api/model_limit.go b/linebot/messaging_api/model_limit.go index 1d6744f0..41cfecc7 100644 --- a/linebot/messaging_api/model_limit.go +++ b/linebot/messaging_api/model_limit.go @@ -28,7 +28,7 @@ type Limit struct { * The maximum number of narrowcast messages to send. Use this parameter to limit the number of narrowcast messages sent. The recipients will be chosen at random. * minimum: 1 */ - Max int32 `json:"max"` + Max int32 `json:"max,omitempty"` /** * If true, the message will be sent within the maximum number of deliverable messages. The default value is `false`. Targets will be selected at random. diff --git a/linebot/messaging_api/model_show_loading_animation_request.go b/linebot/messaging_api/model_show_loading_animation_request.go index 92c6de9d..3af1ea1e 100644 --- a/linebot/messaging_api/model_show_loading_animation_request.go +++ b/linebot/messaging_api/model_show_loading_animation_request.go @@ -34,5 +34,5 @@ type ShowLoadingAnimationRequest struct { * minimum: 5 * maximum: 60 */ - LoadingSeconds int32 `json:"loadingSeconds"` + LoadingSeconds int32 `json:"loadingSeconds,omitempty"` }