Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): stop the shape gate losing a component to its spelling

Yudhi Armyndharis8aeaee556285
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 392d96de7..3b7ea6b4f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,8 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Tests
-- The client shape gate covers request bodies on the Python, Go and Java clients, not only responses: 149 new pairs, and the per-client mapping floors rise with them.
-- The gate reads vocabularies it previously skipped, so a wrong wire value fails instead of passing unread: numeric `Literal` and const-block enums, Java enum constants by their `@SerializedName`, enum members inside a list, and package-qualified generics.
+- The client shape gate covers request bodies on the Python, Go and Java clients, not only responses: 152 new pairs, and the per-client mapping floors rise with them.
+- The gate reads vocabularies it previously skipped, so a wrong wire value fails instead of passing unread: numeric `Literal` and const-block enums, Java enum constants by their `@SerializedName`, and enum members carried inside a list.
+- The gate no longer loses a Java component to its own spelling: a package-qualified generic, a boxed numeric and a generic carrying a comma each resolved to something uncomparable, so the field counted as present with its type unchecked.
### Documentation
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjs
index d6dc21c83..48ef83c5e 100644
--- a/scripts/check-contract-shapes.mjs
+++ b/scripts/check-contract-shapes.mjs
@@ -55,27 +55,17 @@ const REPO_ROOT = fileURLToPath(new URL('..', import.meta.url));
const MAPPINGS = {
'sdk/javascript/src/types.ts': {
AccountRestriction: 'AccountRestrictionDto',
+ ArchiveChatRequest: 'ArchiveChatDto',
BatchMessageResult: 'BatchMessageResultDto',
BatchProgress: 'BatchProgressDto',
BatchStatusResponse: 'BatchStatusResponseDto',
+ BulkMediaRequest: 'BulkMediaDto',
BulkMessageContent: 'BulkMessageContentDto',
BulkMessageItem: 'BulkMessageItemDto',
BulkMessageResponse: 'BulkMessageResponseDto',
CallLinkResponse: 'CallLinkResponseDto',
ChatHistoryMessage: 'ChatHistoryMessageDto',
ChatSummary: 'ChatSummaryDto',
- GroupInfo: 'GroupInfoDto',
- GroupJoinInfo: 'GroupJoinInfoDto',
- GroupParticipant: 'GroupParticipantDto',
- GroupSummary: 'GroupSummaryDto',
- MessageListResponse: 'MessageListResponseDto',
- MessageRecord: 'MessageListItemDto',
- MessageResponse: 'MessageResponseDto',
- // Request-side pairs: every *Request interface with a matching DTO, plus the filter-condition
- // shape. Two requests have NO named schema (inline objects on their routes) and stay unmapped:
- // AddLabelRequest (POST /labels/chat/:chatId) and SubscribeChannelRequest (POST /channels/subscribe).
- ArchiveChatRequest: 'ArchiveChatDto',
- BulkMediaRequest: 'BulkMediaDto',
CreateCallLinkRequest: 'CreateCallLinkDto',
CreateChannelRequest: 'CreateChannelDto',
CreateGroupRequest: 'CreateGroupDto',
@@ -88,18 +78,30 @@ const MAPPINGS = {
EditMessageRequest: 'EditMessageDto',
ForwardMessageRequest: 'ForwardMessageDto',
GroupDescriptionRequest: 'GroupDescriptionDto',
+ GroupInfo: 'GroupInfoDto',
+ GroupJoinInfo: 'GroupJoinInfoDto',
GroupMembershipRequest: 'GroupMembershipRequestDto',
+ GroupParticipant: 'GroupParticipantDto',
GroupSubjectRequest: 'GroupSubjectDto',
+ GroupSummary: 'GroupSummaryDto',
JoinGroupRequest: 'JoinGroupDto',
MarkChatRequest: 'MarkChatReadDto',
+ MessageListResponse: 'MessageListResponseDto',
+ MessageRecord: 'MessageListItemDto',
+ MessageResponse: 'MessageResponseDto',
MuteChannelRequest: 'MuteChannelDto',
MuteChatRequest: 'MuteChatDto',
+ PairingCodeResponse: 'PairingCodeResponseDto',
+ ParticipantPresence: 'ParticipantPresenceDto',
ParticipantsRequest: 'ParticipantsDto',
PinChatRequest: 'PinChatDto',
PinMessageRequest: 'PinMessageDto',
+ ProfilePictureResponse: 'ProfilePictureResponseDto',
+ ProfilePicturesResponse: 'ProfilePicturesResponseDto',
ReactMessageRequest: 'ReactMessageDto',
ReplyMessageRequest: 'ReplyMessageDto',
RequestPairingCodeRequest: 'RequestPairingCodeDto',
+ SearchHit: 'SearchHitDto',
SendAudioRequest: 'SendAudioMessageDto',
SendBulkRequest: 'SendBulkMessageDto',
SendChatStateRequest: 'SendChatStateDto',
@@ -114,12 +116,14 @@ const MAPPINGS = {
SendTextStatusRequest: 'SendTextStatusDto',
SendVideoStatusRequest: 'SendVideoStatusDto',
SendVoiceStatusRequest: 'SendVoiceStatusDto',
+ SessionResponse: 'SessionResponseDto',
SetGroupPictureRequest: 'SetGroupPictureDto',
SetOwnPresenceRequest: 'SetOwnPresenceDto',
SetProfileNameRequest: 'SetProfileNameDto',
SetProfilePictureRequest: 'SetProfilePictureDto',
SetProfileStatusRequest: 'SetProfileStatusDto',
StarMessageRequest: 'StarMessageDto',
+ StatusResult: 'StatusResultDto',
TransferChannelOwnershipRequest: 'TransferChannelOwnershipDto',
UnpinMessageRequest: 'UnpinMessageDto',
UpdateSessionConfigRequest: 'UpdateSessionConfigDto',
@@ -127,13 +131,6 @@ const MAPPINGS = {
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
WebhookFilterCondition: 'WebhookFilterConditionDto',
- PairingCodeResponse: 'PairingCodeResponseDto',
- ParticipantPresence: 'ParticipantPresenceDto',
- ProfilePictureResponse: 'ProfilePictureResponseDto',
- ProfilePicturesResponse: 'ProfilePicturesResponseDto',
- SearchHit: 'SearchHitDto',
- SessionResponse: 'SessionResponseDto',
- StatusResult: 'StatusResultDto',
WebhookResponse: 'WebhookResponseDto',
},
'dashboard/src/services/api.ts': {
@@ -169,14 +166,16 @@ const MAPPINGS = {
const MINIMUM_MAPPED = {
'sdk/javascript/src/types.ts': 78,
'dashboard/src/services/api.ts': 20,
- 'sdk/python/openwa/types.py': 72,
- 'sdk/go': 73,
- 'sdk/java': 77,
+ 'sdk/python/openwa/types.py': 73,
+ 'sdk/go': 74,
+ 'sdk/java': 78,
};
/** Known drift, deliberately not gated yet — each line is a to-adjudicate follow-up. */
const EXCLUDED = {
'sdk/go': {
+ UpdateWebhookRequest:
+ 'BY DESIGN, same alias as WebhookResponse below: the events list resolves to array<string> because `WebhookEvent` is an alias for string, so the vocabulary cannot be carried on this client',
WebhookResponse:
'BY DESIGN: `WebhookEvent` is a type ALIAS for string so the Event* constants drop into a []string literal without a conversion, which means the events list resolves to array<string> and cannot carry the vocabulary. Un-excluding means making it a defined type and retyping the three Events fields, a source break for a published client',
CreateWebhookRequest:
@@ -196,6 +195,11 @@ const EXCLUDED = {
},
};
+// UpdateWebhookRequest is mapped on the three clients that declare it as a named type. The
+// JavaScript SDK spells it `Partial<CreateWebhookRequest> & { active?: boolean }`, a type ALIAS
+// rather than an interface, which the hand parser does not read; mapping it there would fail as a
+// missing hand type rather than gate anything.
+
/** Python client pairs (TypedDict classes in openwa/types.py). */
const PYTHON_MAPPING = {
AccountRestriction: 'AccountRestrictionDto',
@@ -266,6 +270,7 @@ const PYTHON_MAPPING = {
TransferChannelOwnershipRequest: 'TransferChannelOwnershipDto',
UnpinMessageRequest: 'UnpinMessageDto',
UpdateSessionConfigRequest: 'UpdateSessionConfigDto',
+ UpdateWebhookRequest: 'UpdateWebhookDto',
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
@@ -343,6 +348,7 @@ const GO_MAPPING = {
TransferChannelOwnershipRequest: 'TransferChannelOwnershipDto',
UnpinMessageRequest: 'UnpinMessageDto',
UpdateSessionConfigRequest: 'UpdateSessionConfigDto',
+ UpdateWebhookRequest: 'UpdateWebhookDto',
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
@@ -424,6 +430,7 @@ const JAVA_MAPPING = {
TransferChannelOwnershipRequest: 'TransferChannelOwnershipDto',
UnpinMessageRequest: 'UnpinMessageDto',
UpdateSessionConfigRequest: 'UpdateSessionConfigDto',
+ UpdateWebhookRequest: 'UpdateWebhookDto',
UpsertContactRequest: 'UpsertContactDto',
UpsertLabelRequest: 'UpsertLabelDto',
VotePollRequest: 'VotePollDto',
@@ -949,6 +956,12 @@ export function parseJavaTypes(sources) {
boolean: 'boolean',
Integer: 'number',
Long: 'number',
+ // The boxed numerics as a family: a component typed `Double` resolved to the bare class name,
+ // which is not a simple token, so its type went uncompared while the field counted as present.
+ Double: 'number',
+ Float: 'number',
+ Short: 'number',
+ Byte: 'number',
Boolean: 'boolean',
JsonObject: 'any',
Object: 'any',
@@ -982,7 +995,25 @@ export function parseJavaTypes(sources) {
const source = raw.replace(/\/\*[\s\S]*?\*\//g, '');
for (const m of source.matchAll(/record (\w+)\(([^)]*)\)/g)) {
const members = {};
- for (const comp of m[2].split(',')) {
+ // Split at TOP-LEVEL commas only. A plain split(',') tears `Map<String, Object> config` into
+ // two halves: the first is unparseable and dropped, the second parses as type `Object>` with
+ // the right field NAME, so the member survived with a token nothing could compare and the
+ // pair passed on names alone.
+ const components = [];
+ let buffer = '';
+ let angle = 0;
+ for (const ch of m[2]) {
+ if (ch === '<') angle++;
+ else if (ch === '>') angle--;
+ if (ch === ',' && angle === 0) {
+ components.push(buffer);
+ buffer = '';
+ continue;
+ }
+ buffer += ch;
+ }
+ if (buffer.trim()) components.push(buffer);
+ for (const comp of components) {
const cm = comp.trim().match(/^(?:final\s+)?([\w<>,.\[\]\s]+?)\s+(\w+)$/);
if (!cm) continue;
members[cm[2]] = { optional: true, token: cm[1].trim(), __java: cm[1].trim() };
diff --git a/scripts/check-contract-shapes.spec.mjs b/scripts/check-contract-shapes.spec.mjs
index dd7070848..87f19fb2b 100644
--- a/scripts/check-contract-shapes.spec.mjs
+++ b/scripts/check-contract-shapes.spec.mjs
@@ -259,3 +259,25 @@ test('parseJavaTypes: a package-qualified generic is the same shape as the bare
assert.equal(s.mentions.token, 'array<string>');
assert.equal(s.tags.token, s.mentions.token);
});
+
+test('parseJavaTypes: a generic carrying a comma is one component, not two', () => {
+ // A plain split(',') tore `Map<String, Object> config` in half: the first piece was unparseable
+ // and dropped, the second parsed as type `Object>` under the right field name, so the member
+ // survived carrying a token nothing could compare.
+ const src = 'public record Sample(String name, Map<String, Object> config, String tail) {}';
+ const s = parseJavaTypes([src]).Sample;
+ assert.deepEqual(Object.keys(s), ['name', 'config', 'tail']);
+ assert.equal(s.config.token, 'dict');
+});
+
+test('parseJavaTypes: boxed numerics reduce to number rather than their class name', () => {
+ // `Double` fell through to the bare class name, which is not a simple token, so comparePair
+ // skipped the field: a Double component against a string contract reported nothing.
+ const s = parseJavaTypes(['public record Sample(Double a, Float b, Short c, Byte d) {}']).Sample;
+ assert.deepEqual(
+ Object.values(s).map(v => v.token),
+ ['number', 'number', 'number', 'number'],
+ );
+ const schema = { type: 'object', required: ['a'], properties: { a: { type: 'string' } } };
+ assert.equal(comparePair('Sample', { a: s.a }, 'Dto', schema, {}, false).length, 1);
+});
diff --git a/sdk/go/client_test.go b/sdk/go/client_test.go
index 90d419394..6001aeb2f 100644
--- a/sdk/go/client_test.go
+++ b/sdk/go/client_test.go
@@ -1404,3 +1404,56 @@ func TestUpdateSessionConfigEmitsThreeStates(t *testing.T) {
}
}
}
+
+// The request enums are named types, so a Go value can no longer be an arbitrary string. What the
+// compiler cannot check is the value each constant CARRIES: these fields travel as their
+// underlying string or number, and a typo would be refused by the server, not by the build.
+func TestRequestEnumWireValues(t *testing.T) {
+ wireStrings := map[string]string{
+ string(CallLinkAudio): "audio",
+ string(CallLinkVideo): "video",
+ string(ProxyHTTP): "http",
+ string(ProxyHTTPS): "https",
+ string(ProxySOCKS4): "socks4",
+ string(ProxySOCKS5): "socks5",
+ string(MembershipInviteLink): "invite_link",
+ string(MembershipLinkedGroupJoin): "linked_group_join",
+ string(MembershipNonAdminAdd): "non_admin_add",
+ string(ChatStateTyping): "typing",
+ string(ChatStateRecording): "recording",
+ string(ChatStatePaused): "paused",
+ }
+ for got, want := range wireStrings {
+ if got != want {
+ t.Errorf("wire value = %q, want %q", got, want)
+ }
+ }
+ wireNumbers := map[int]int{
+ int(PinOneDay): 86400,
+ int(PinSevenDays): 604800,
+ int(PinThirtyDays): 2592000,
+ int(StatusFontDefault): 0,
+ int(StatusFontBold): 6,
+ int(StatusFontBryndan): 10,
+ }
+ for got, want := range wireNumbers {
+ if got != want {
+ t.Errorf("wire value = %d, want %d", got, want)
+ }
+ }
+ // The named types must still marshal as bare JSON scalars, not as objects or quoted numbers.
+ body, err := json.Marshal(SendChatStateRequest{ChatID: "[email protected]", State: ChatStateTyping})
+ if err != nil {
+ t.Fatalf("marshal: %v", err)
+ }
+ if !strings.Contains(string(body), `"state":"typing"`) {
+ t.Errorf("state did not marshal as a bare string: %s", body)
+ }
+ pin, err := json.Marshal(PinMessageRequest{ChatID: "[email protected]", MessageID: "m", DurationSeconds: PinOneDay})
+ if err != nil {
+ t.Fatalf("marshal: %v", err)
+ }
+ if !strings.Contains(string(pin), `"durationSeconds":86400`) {
+ t.Errorf("durationSeconds did not marshal as a bare number: %s", pin)
+ }
+}