Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): let the Go and Java clients clear a proxy

Yudhi Armyndharis6adaa1ebe6f4
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjs
index bd7d68661..66da4ac64 100644
--- a/scripts/check-contract-shapes.mjs
+++ b/scripts/check-contract-shapes.mjs
@@ -187,6 +187,8 @@ const EXCLUDED = {
'BY DESIGN: `events` carries no omitempty so the key is always on the wire, which is what lets an empty slice mean "subscribe to nothing": the server keeps [] and only defaults when the key is absent. Adding omitempty would silently turn that into the default subscription',
UpdateSessionConfigRequest:
'BY DESIGN: every component is `json:"-"` and MarshalJSON writes the body by hand, because the three fields need an explicit null to reset and Go cannot express "null" and "absent" through one pointer, so the harvester sees no wire fields at all',
+ UpdateSessionProxyRequest:
+ 'BY DESIGN, same shape as UpdateSessionConfigRequest above: clearing a proxy needs an explicit null and `omitempty` on a nil pointer omits the key instead, so ProxyURL is `json:"-"` with a ClearProxyURL flag and MarshalJSON writes the body, leaving no wire fields for the harvester to see',
},
'sdk/java': {
UpdateSessionConfigRequest:
diff --git a/sdk/go/types_session.go b/sdk/go/types_session.go
index 695120239..ceb8384b6 100644
--- a/sdk/go/types_session.go
+++ b/sdk/go/types_session.go
@@ -186,16 +186,36 @@ type CreateSessionRequest struct {
// SessionProxy is the masked per-session proxy configuration returned by GET/PATCH /proxy.
type SessionProxy struct {
- Enabled bool `json:"enabled"`
- ProxyType *ProxyType `json:"proxyType"`
- ProxyHost *string `json:"proxyHost"`
- HasCredentials bool `json:"hasCredentials"`
+ Enabled bool `json:"enabled"`
+ ProxyType *ProxyType `json:"proxyType"`
+ ProxyHost *string `json:"proxyHost"`
+ HasCredentials bool `json:"hasCredentials"`
}
-// UpdateSessionProxyRequest updates per-session proxy settings. Send ProxyURL as a JSON null to
-// clear. Changes apply on the next start, not to a running engine.
+// UpdateSessionProxyRequest updates per-session proxy settings. Changes apply on the next start,
+// not to a running engine.
+//
+// Three states, the same shape as UpdateSessionConfigRequest: an absent key leaves the proxy
+// unchanged, an explicit null clears it, and a value sets it. `omitempty` on a nil pointer OMITS the
+// key rather than emitting null, so clearing needs its own flag and the MarshalJSON below.
type UpdateSessionProxyRequest struct {
- ProxyURL *string `json:"proxyUrl,omitempty"`
+ ProxyURL *string `json:"-"`
+
+ // ClearProxyURL sends an explicit null, removing the proxy. It wins over ProxyURL if both are set.
+ ClearProxyURL bool `json:"-"`
+}
+
+// MarshalJSON emits only what the caller addressed: the Clear flag becomes an explicit null, a
+// non-nil pointer becomes its value, and neither leaves the key out so the server keeps the proxy
+// it already has.
+func (r UpdateSessionProxyRequest) MarshalJSON() ([]byte, error) {
+ out := map[string]any{}
+ if r.ClearProxyURL {
+ out["proxyUrl"] = nil
+ } else if r.ProxyURL != nil {
+ out["proxyUrl"] = *r.ProxyURL
+ }
+ return json.Marshal(out)
}
// QrCodeResponse carries the current QR code for a session awaiting scan.
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
index 79f657272..ad21f26dc 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
@@ -12,6 +12,7 @@ import com.rmyndharis.openwa.http.HttpMethod;
import com.rmyndharis.openwa.model.MuteChatRequest;
import com.rmyndharis.openwa.model.UpdateSessionConfigRequest;
import com.rmyndharis.openwa.model.UpdateSessionConfigRequestSerializer;
+import com.rmyndharis.openwa.model.UpdateSessionProxyRequest;
import com.rmyndharis.openwa.http.HttpRequestData;
import com.rmyndharis.openwa.http.HttpResponseData;
import com.rmyndharis.openwa.http.HttpTransport;
@@ -192,7 +193,11 @@ public final class OpenWAClient {
* turn into an unintended "reset to default".
*/
private Gson bodySerializer(Object body) {
- return body instanceof UpdateSessionConfigRequest || body instanceof MuteChatRequest ? nullEmittingGson : gson;
+ return body instanceof UpdateSessionConfigRequest
+ || body instanceof MuteChatRequest
+ || body instanceof UpdateSessionProxyRequest
+ ? nullEmittingGson
+ : gson;
}
private HttpResponseData execute(HttpMethod method, String path, Object query, Object body) {
diff --git a/sdk/php/src/Resources/SessionsResource.php b/sdk/php/src/Resources/SessionsResource.php
index f11ec080a..9a04f19b7 100644
--- a/sdk/php/src/Resources/SessionsResource.php
+++ b/sdk/php/src/Resources/SessionsResource.php
@@ -67,7 +67,7 @@ class SessionsResource
* Update per-session proxy settings. No restart — changes apply on the next start.
* Send proxyUrl: null to clear. OPERATOR role required.
*
- * @param array{proxyUrl?: ?string, proxyType?: ?string} $body
+ * @param array{proxyUrl?: ?string} $body
* @return array{enabled: bool, proxyType: ?string, proxyHost: ?string, hasCredentials: bool}
*/
public function updateProxy(string $id, array $body): array
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 86b6a0ad7..912065c44 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -239,7 +239,7 @@ class SessionProxy(TypedDict):
"""Masked per-session proxy configuration — credentials are never returned."""
enabled: bool
- proxyType: ProxyType | None
+ proxyType: Literal['http', 'https', 'socks4', 'socks5'] | None
proxyHost: str | None
hasCredentials: bool