From 40f299deff65c4eb7080d861ba17473cfde7abb5 Mon Sep 17 00:00:00 2001 From: Era Dorta Date: Mon, 6 Apr 2026 16:57:14 +0200 Subject: [PATCH] fix: add omitempty and generate swagger json with required fields --- Dockerfile | 2 +- src/api/api.go | 82 +++++++++++++++++++++++----------------------- src/docs/README.md | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Dockerfile b/Dockerfile index e80bec1..00d66db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -142,7 +142,7 @@ COPY src/plugin_loader.go /tmp/signal-cli-rest-api-src/ # build signal-cli-rest-api RUN ls -la /tmp/signal-cli-rest-api-src -RUN cd /tmp/signal-cli-rest-api-src && ${GOPATH}/bin/swag init +RUN cd /tmp/signal-cli-rest-api-src && ${GOPATH}/bin/swag init --requiredByDefault RUN cd /tmp/signal-cli-rest-api-src && go build -o signal-cli-rest-api main.go RUN cd /tmp/signal-cli-rest-api-src && go test ./client -v && go test ./utils -v diff --git a/src/api/api.go b/src/api/api.go index daf7639..4123aaf 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -34,32 +34,32 @@ const ( type UpdateContactRequest struct { Recipient string `json:"recipient"` - Name *string `json:"name"` - ExpirationInSeconds *int `json:"expiration_in_seconds"` + Name *string `json:"name,omitempty"` + ExpirationInSeconds *int `json:"expiration_in_seconds,omitempty"` } type CreateGroupRequest struct { Name string `json:"name"` Members []string `json:"members"` - Description string `json:"description"` - Permissions ds.GroupPermissions `json:"permissions"` - GroupLinkState string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"` - ExpirationTime *int `json:"expiration_time"` + Description string `json:"description,omitempty"` + Permissions ds.GroupPermissions `json:"permissions,omitempty"` + GroupLinkState string `json:"group_link,omitempty" enums:"disabled,enabled,enabled-with-approval"` + ExpirationTime *int `json:"expiration_time,omitempty"` } type UpdateGroupRequest struct { - Base64Avatar *string `json:"base64_avatar"` - Description *string `json:"description"` - Name *string `json:"name"` - ExpirationTime *int `json:"expiration_time"` - GroupLinkState *string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"` - Permissions *ds.GroupPermissions `json:"permissions"` + Base64Avatar *string `json:"base64_avatar,omitempty"` + Description *string `json:"description,omitempty"` + Name *string `json:"name,omitempty"` + ExpirationTime *int `json:"expiration_time,omitempty"` + GroupLinkState *string `json:"group_link,omitempty" enums:"disabled,enabled,enabled-with-approval"` + Permissions *ds.GroupPermissions `json:"permissions,omitempty"` } type PinMessageInGroupRequest struct { TargetAuthor string `json:"target_author"` Timestamp int64 `json:"timestamp"` - Duration *int `json:"duration"` + Duration *int `json:"duration,omitempty"` } type UnpinMessageInGroupRequest struct { @@ -84,17 +84,17 @@ type Configuration struct { } type RegisterNumberRequest struct { - UseVoice bool `json:"use_voice"` - Captcha string `json:"captcha"` + UseVoice bool `json:"use_voice,omitempty"` + Captcha string `json:"captcha,omitempty"` } type UnregisterNumberRequest struct { - DeleteAccount bool `json:"delete_account" example:"false"` - DeleteLocalData bool `json:"delete_local_data" example:"false"` + DeleteAccount bool `json:"delete_account,omitempty" example:"false"` + DeleteLocalData bool `json:"delete_local_data,omitempty" example:"false"` } type VerifyNumberSettings struct { - Pin string `json:"pin"` + Pin string `json:"pin,omitempty"` } type Reaction struct { @@ -114,27 +114,27 @@ type SendMessageV1 struct { Number string `json:"number"` Recipients []string `json:"recipients"` Message string `json:"message"` - Base64Attachment string `json:"base64_attachment" example:"'' OR 'data:;base64,' OR 'data:;filename=;base64,'"` - IsGroup bool `json:"is_group"` + Base64Attachment string `json:"base64_attachment,omitempty" example:"'' OR 'data:;base64,' OR 'data:;filename=;base64,'"` + IsGroup bool `json:"is_group,omitempty"` } type SendMessageV2 struct { Number string `json:"number"` Recipients []string `json:"recipients"` - Recipient string `json:"recipient" swaggerignore:"true"` //some REST API consumers (like the Synology NAS) do not support an array as recipients, so we provide this string parameter here as backup. In order to not confuse anyone, the parameter won't be exposed in the Swagger UI (most users are fine with the recipients parameter). + Recipient string `json:"recipient,omitempty" swaggerignore:"true"` //some REST API consumers (like the Synology NAS) do not support an array as recipients, so we provide this string parameter here as backup. In order to not confuse anyone, the parameter won't be exposed in the Swagger UI (most users are fine with the recipients parameter). Message string `json:"message"` - Base64Attachments []string `json:"base64_attachments" example:",data:;base64,data:;filename=;base64"` - Sticker string `json:"sticker"` - Mentions []ds.MessageMention `json:"mentions"` - QuoteTimestamp *int64 `json:"quote_timestamp"` - QuoteAuthor *string `json:"quote_author"` - QuoteMessage *string `json:"quote_message"` - QuoteMentions []ds.MessageMention `json:"quote_mentions"` - TextMode *string `json:"text_mode" enums:"normal,styled"` - EditTimestamp *int64 `json:"edit_timestamp"` - NotifySelf *bool `json:"notify_self"` - LinkPreview *ds.LinkPreviewType `json:"link_preview"` - ViewOnce *bool `json:"view_once"` + Base64Attachments []string `json:"base64_attachments,omitempty" example:",data:;base64,data:;filename=;base64"` + Sticker string `json:"sticker,omitempty"` + Mentions []ds.MessageMention `json:"mentions,omitempty"` + QuoteTimestamp *int64 `json:"quote_timestamp,omitempty"` + QuoteAuthor *string `json:"quote_author,omitempty"` + QuoteMessage *string `json:"quote_message,omitempty"` + QuoteMentions []ds.MessageMention `json:"quote_mentions,omitempty"` + TextMode *string `json:"text_mode,omitempty" enums:"normal,styled"` + EditTimestamp *int64 `json:"edit_timestamp,omitempty"` + NotifySelf *bool `json:"notify_self,omitempty"` + LinkPreview *ds.LinkPreviewType `json:"link_preview,omitempty"` + ViewOnce *bool `json:"view_once,omitempty"` } type TypingIndicatorRequest struct { @@ -157,13 +157,13 @@ type CreateGroupResponse struct { type UpdateProfileRequest struct { Name string `json:"name"` - Base64Avatar string `json:"base64_avatar"` - About *string `json:"about"` + Base64Avatar string `json:"base64_avatar,omitempty"` + About *string `json:"about,omitempty"` } type TrustIdentityRequest struct { - VerifiedSafetyNumber *string `json:"verified_safety_number"` - TrustAllKnownKeys *bool `json:"trust_all_known_keys" example:"false"` + VerifiedSafetyNumber *string `json:"verified_safety_number,omitempty"` + TrustAllKnownKeys *bool `json:"trust_all_known_keys,omitempty" example:"false"` } type SendMessageResponse struct { @@ -203,8 +203,8 @@ type RateLimitChallengeRequest struct { } type UpdateAccountSettingsRequest struct { - DiscoverableByNumber *bool `json:"discoverable_by_number"` - ShareNumber *bool `json:"share_number"` + DiscoverableByNumber *bool `json:"discoverable_by_number,omitempty"` + ShareNumber *bool `json:"share_number,omitempty"` } type SetUsernameRequest struct { @@ -226,7 +226,7 @@ type RemoteDeleteRequest struct { } type DeleteLocalAccountDataRequest struct { - IgnoreRegistered bool `json:"ignore_registered" example:"false"` + IgnoreRegistered bool `json:"ignore_registered,omitempty" example:"false"` } type DeviceLinkUriResponse struct { @@ -237,7 +237,7 @@ type CreatePollRequest struct { Recipient string `json:"recipient" example:" OR OR "` Question string `json:"question" example:"What's your favourite fruit?"` Answers []string `json:"answers" example:"apple,banana,orange"` - AllowMultipleSelections *bool `json:"allow_multiple_selections" example:"true"` + AllowMultipleSelections *bool `json:"allow_multiple_selections,omitempty" example:"true"` } type CreatePollResponse struct { diff --git a/src/docs/README.md b/src/docs/README.md index 0117eff..dc4b95f 100644 --- a/src/docs/README.md +++ b/src/docs/README.md @@ -9,7 +9,7 @@ docker run --rm -v $(pwd):/code ghcr.io/swaggo/swag:latest init Or, if you have `swag` installed: ```bash -swag init +swag init --requiredByDefault ``` Then run the app in `/src`