diff options
author | 2024-03-06 09:05:45 -0800 | |
---|---|---|
committer | 2024-03-06 18:05:45 +0100 | |
commit | fc3741365c27f1d703e8a736af95b95ff811cc45 (patch) | |
tree | 929f1d5e20d1469d63a3dfe81d38d89f9a073c5a /internal/api/model | |
parent | [chore/bugfix] Little DB fixes (#2726) (diff) | |
download | gotosocial-fc3741365c27f1d703e8a736af95b95ff811cc45.tar.xz |
[bugfix] Fix Swagger spec and add test script (#2698)
* Add Swagger spec test script
* Fix Swagger spec errors not related to statuses with polls
* Add API tests that post a status with a poll
* Fix creating a status with a poll from form params
* Fix Swagger spec errors related to statuses with polls (this is the last error)
* Fix Swagger spec warnings not related to unused definitions
* Suppress a duplicate list update params definition that was somehow causing wrong param names
* Add Swagger test to CI
- updates Drone config
- vendorizes go-swagger
- fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version
* Put `Sample: ` on its own line everywhere
* Remove unused id param from emojiCategoriesGet
* Add 5 more pairs of profile fields to account update API Swagger
* Remove Swagger prefix from dummy fields
It makes the generated code look weird
* Manually annotate params for statusCreate operation
* Fix all remaining Swagger spec warnings
- Change some models into operation parameters
- Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields)
* Documented that creating a status with scheduled_at isn't implemented yet
* sign drone.yml
* Fix filter API Swagger errors
* fixup! Fix filter API Swagger errors
---------
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/api/model')
-rw-r--r-- | internal/api/model/account.go | 4 | ||||
-rw-r--r-- | internal/api/model/announcement.go | 2 | ||||
-rw-r--r-- | internal/api/model/announcementreaction.go | 2 | ||||
-rw-r--r-- | internal/api/model/domain.go | 6 | ||||
-rw-r--r-- | internal/api/model/emoji.go | 4 | ||||
-rw-r--r-- | internal/api/model/headerfilter.go | 8 | ||||
-rw-r--r-- | internal/api/model/instancev1.go | 2 | ||||
-rw-r--r-- | internal/api/model/list.go | 15 | ||||
-rw-r--r-- | internal/api/model/marker.go | 2 | ||||
-rw-r--r-- | internal/api/model/multistatus.go | 6 | ||||
-rw-r--r-- | internal/api/model/poll.go | 10 | ||||
-rw-r--r-- | internal/api/model/report.go | 12 | ||||
-rw-r--r-- | internal/api/model/rule.go | 19 | ||||
-rw-r--r-- | internal/api/model/status.go | 20 |
14 files changed, 61 insertions, 51 deletions
diff --git a/internal/api/model/account.go b/internal/api/model/account.go index 46b043f80..7d3fa4b62 100644 --- a/internal/api/model/account.go +++ b/internal/api/model/account.go @@ -170,7 +170,7 @@ type UpdateCredentialsRequest struct { // UpdateSource is to be used specifically in an UpdateCredentialsRequest. // -// swagger:model updateSource +// swagger:ignore type UpdateSource struct { // Default post privacy for authored statuses. Privacy *string `form:"privacy" json:"privacy"` @@ -185,7 +185,7 @@ type UpdateSource struct { // UpdateField is to be used specifically in an UpdateCredentialsRequest. // By default, max 6 fields and 255 characters per property/value. // -// swagger:model updateField +// swagger:ignore type UpdateField struct { // Key this form field was submitted with; // only set if it was submitted as JSON. diff --git a/internal/api/model/announcement.go b/internal/api/model/announcement.go index f2b3b102c..f776ecf92 100644 --- a/internal/api/model/announcement.go +++ b/internal/api/model/announcement.go @@ -19,7 +19,7 @@ package model // Announcement models an admin announcement for the instance. // -// swagger:model announcement +// TODO: swagger:model announcement once announcement API is supported type Announcement struct { // The ID of the announcement. // example: 01FC30T7X4TNCZK0TH90QYF3M4 diff --git a/internal/api/model/announcementreaction.go b/internal/api/model/announcementreaction.go index a77e13bf6..f0a7006e9 100644 --- a/internal/api/model/announcementreaction.go +++ b/internal/api/model/announcementreaction.go @@ -19,7 +19,7 @@ package model // AnnouncementReaction models a user reaction to an announcement. // -// swagger:model announcementReaction +// TODO: swagger:model announcementReaction once announcement API is supported type AnnouncementReaction struct { // The emoji used for the reaction. Either a unicode emoji, or a custom emoji's shortcode. // example: blobcat_uwu diff --git a/internal/api/model/domain.go b/internal/api/model/domain.go index a5e1ddf10..ddc96ef05 100644 --- a/internal/api/model/domain.go +++ b/internal/api/model/domain.go @@ -65,7 +65,7 @@ type DomainPermission struct { // DomainPermissionRequest is the form submitted as a POST to create a new domain permission entry (allow/block). // -// swagger:model domainPermissionCreateRequest +// swagger:ignore type DomainPermissionRequest struct { // A list of domains for which this permission request should apply. // Only used if import=true is specified. @@ -87,9 +87,9 @@ type DomainPermissionRequest struct { PublicComment string `form:"public_comment" json:"public_comment" xml:"public_comment"` } -// DomainBlockCreateRequest is the form submitted as a POST to /api/v1/admin/domain_keys_expire to expire a domain's public keys. +// DomainKeysExpireRequest is the form submitted as a POST to /api/v1/admin/domain_keys_expire to expire a domain's public keys. // -// swagger:model domainKeysExpireRequest +// swagger:parameters domainKeysExpire type DomainKeysExpireRequest struct { // hostname/domain to expire keys for. Domain string `form:"domain" json:"domain" xml:"domain"` diff --git a/internal/api/model/emoji.go b/internal/api/model/emoji.go index acf1f1332..cebc38196 100644 --- a/internal/api/model/emoji.go +++ b/internal/api/model/emoji.go @@ -42,7 +42,7 @@ type Emoji struct { // EmojiCreateRequest represents a request to create a custom emoji made through the admin API. // -// swagger:model emojiCreateRequest +// swagger:ignore type EmojiCreateRequest struct { // Desired shortcode for the emoji, without surrounding colons. This must be unique for the domain. // example: blobcat_uwu @@ -56,7 +56,7 @@ type EmojiCreateRequest struct { // EmojiUpdateRequest represents a request to update a custom emoji, made through the admin API. // -// swagger:model emojiUpdateRequest +// swagger:ignore type EmojiUpdateRequest struct { // Type of action. One of disable, modify, copy. Type EmojiUpdateType `form:"type" json:"type" xml:"type"` diff --git a/internal/api/model/headerfilter.go b/internal/api/model/headerfilter.go index 96ba819f5..0800adeb2 100644 --- a/internal/api/model/headerfilter.go +++ b/internal/api/model/headerfilter.go @@ -18,6 +18,8 @@ package model // HeaderFilter represents a regex value filter applied to one particular HTTP header (allow / block). +// +// swagger:model headerFilter type HeaderFilter struct { // The ID of the header filter. // example: 01FBW21XJA09XYX51KV5JVBW0F @@ -45,11 +47,15 @@ type HeaderFilter struct { // HeaderFilterRequest is the form submitted as a POST to create a new header filter entry (allow / block). // -// swagger:model headerFilterCreateRequest +// swagger:parameters headerFilterAllowCreate headerFilterBlockCreate type HeaderFilterRequest struct { // The HTTP header to match against (e.g. User-Agent). + // required: true + // in: formData Header string `form:"header" json:"header" xml:"header"` // The header value matching regular expression. + // required: true + // in: formData Regex string `form:"regex" json:"regex" xml:"regex"` } diff --git a/internal/api/model/instancev1.go b/internal/api/model/instancev1.go index b402cdefe..03e27619c 100644 --- a/internal/api/model/instancev1.go +++ b/internal/api/model/instancev1.go @@ -60,7 +60,7 @@ type InstanceV1 struct { // example: 0.1.1 cb85f65 Version string `json:"version"` // Primary language of the instance. - // example: en + // example: ["en"] Languages []string `json:"languages"` // New account registrations are enabled on this instance. Registrations bool `json:"registrations"` diff --git a/internal/api/model/list.go b/internal/api/model/list.go index f897bcc88..03ea3420d 100644 --- a/internal/api/model/list.go +++ b/internal/api/model/list.go @@ -37,7 +37,7 @@ type List struct { // swagger:parameters listCreate type ListCreateRequest struct { // Title of this list. - // example: Cool People + // Sample: Cool People // in: formData // required: true Title string `form:"title" json:"title" xml:"title"` @@ -45,28 +45,35 @@ type ListCreateRequest struct { // followed = Show replies to any followed user // list = Show replies to members of the list // none = Show replies to no one - // example: list + // Sample: list // default: list // in: formData + // enum: + // - followed + // - list + // - none RepliesPolicy string `form:"replies_policy" json:"replies_policy" xml:"replies_policy"` } // ListUpdateRequest models list update parameters. // -// swagger:parameters listUpdate +// swagger:ignore type ListUpdateRequest struct { // Title of this list. - // example: Cool People + // Sample: Cool People // in: formData Title *string `form:"title" json:"title" xml:"title"` // RepliesPolicy for this list. // followed = Show replies to any followed user // list = Show replies to members of the list // none = Show replies to no one + // Sample: list // in: formData RepliesPolicy *string `form:"replies_policy" json:"replies_policy" xml:"replies_policy"` } +// ListAccountsChangeRequest is a list of account IDs to add to or remove from a list. +// // swagger:ignore type ListAccountsChangeRequest struct { AccountIDs []string `form:"account_ids[]" json:"account_ids" xml:"account_ids"` diff --git a/internal/api/model/marker.go b/internal/api/model/marker.go index f2d5cb296..d0d5dc67e 100644 --- a/internal/api/model/marker.go +++ b/internal/api/model/marker.go @@ -18,6 +18,8 @@ package model // Marker represents the last read position within a user's timelines. +// +// swagger:model markers type Marker struct { // Information about the user's position in the home timeline. Home *TimelineMarker `json:"home,omitempty"` diff --git a/internal/api/model/multistatus.go b/internal/api/model/multistatus.go index cac8b4f9b..d58ea8eae 100644 --- a/internal/api/model/multistatus.go +++ b/internal/api/model/multistatus.go @@ -22,7 +22,7 @@ package model // 207 MULTI-STATUS to indicate a mixture of responses. // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/207 // -// swagger:model multiStatus +// TODO: swagger:model multiStatus once domain permissions API supports HTTP 207 type MultiStatus struct { Data []MultiStatusEntry `json:"data"` Metadata MultiStatusMetadata `json:"metadata"` @@ -34,7 +34,7 @@ type MultiStatus struct { // the caller, but at minimum it should be expected to be // JSON-serializable. // -// swagger:model multiStatusEntry +// TODO: swagger:model multiStatusEntry once domain permissions API supports HTTP 207 type MultiStatusEntry struct { // The resource/result for this entry. // Value may be any type, check the docs @@ -49,7 +49,7 @@ type MultiStatusEntry struct { // MultiStatusMetadata models an at-a-glance summary of // the data contained in the MultiStatus. // -// swagger:model multiStatusMetadata +// TODO: swagger:model multiStatusMetadata once domain permissions API supports HTTP 207 type MultiStatusMetadata struct { // Success count + failure count. Total int `json:"total"` diff --git a/internal/api/model/poll.go b/internal/api/model/poll.go index 5603ff222..089dfc0f0 100644 --- a/internal/api/model/poll.go +++ b/internal/api/model/poll.go @@ -73,26 +73,26 @@ type PollOption struct { // PollRequest models a request to create a poll. // -// swagger:model pollRequest +// swagger:ignore type PollRequest struct { // Array of possible answers. // If provided, media_ids cannot be used, and poll[expires_in] must be provided. // name: poll[options] - Options []string `form:"options" json:"options" xml:"options"` + Options []string `form:"poll[options][]" json:"options" xml:"options"` // Duration the poll should be open, in seconds. // If provided, media_ids cannot be used, and poll[options] must be provided. - ExpiresIn int `form:"expires_in" xml:"expires_in"` + ExpiresIn int `form:"poll[expires_in]" xml:"expires_in"` // Duration the poll should be open, in seconds. // If provided, media_ids cannot be used, and poll[options] must be provided. ExpiresInI interface{} `json:"expires_in"` // Allow multiple choices on this poll. - Multiple bool `form:"multiple" json:"multiple" xml:"multiple"` + Multiple bool `form:"poll[multiple]" json:"multiple" xml:"multiple"` // Hide vote counts until the poll ends. - HideTotals bool `form:"hide_totals" json:"hide_totals" xml:"hide_totals"` + HideTotals bool `form:"poll[hide_totals]" json:"hide_totals" xml:"hide_totals"` } // PollVoteRequest models a request to vote in a poll. diff --git a/internal/api/model/report.go b/internal/api/model/report.go index b9b8c77d2..175875204 100644 --- a/internal/api/model/report.go +++ b/internal/api/model/report.go @@ -65,31 +65,31 @@ type Report struct { // swagger:parameters reportCreate type ReportCreateRequest struct { // ID of the account to report. - // example: 01GPE75FXSH2EGFBF85NXPH3KP + // Sample: 01GPE75FXSH2EGFBF85NXPH3KP // in: formData // required: true AccountID string `form:"account_id" json:"account_id" xml:"account_id"` // IDs of statuses to attach to the report to provide additional context. - // example: ["01GPE76N4SBVRZ8K24TW51ZZQ4","01GPE76WN9JZE62EPT3Q9FRRD4"] + // Sample: ["01GPE76N4SBVRZ8K24TW51ZZQ4","01GPE76WN9JZE62EPT3Q9FRRD4"] // in: formData StatusIDs []string `form:"status_ids[]" json:"status_ids" xml:"status_ids"` // The reason for the report. Default maximum of 1000 characters. - // example: Anti-Blackness, transphobia. + // Sample: Anti-Blackness, transphobia. // in: formData Comment string `form:"comment" json:"comment" xml:"comment"` // If the account is remote, should the report be forwarded to the remote admin? - // example: true + // Sample: true // default: false // in: formData Forward bool `form:"forward" json:"forward" xml:"forward"` // Specify if the report is due to spam, violation of enumerated instance rules, or some other reason. // Currently only 'other' is supported. - // example: other + // Sample: other // default: other // in: formData Category string `form:"category" json:"category" xml:"category"` // IDs of rules on this instance which have been broken according to the reporter. - // example: ["01GPBN5YDY6JKBWE44H7YQBDCQ","01GPBN65PDWSBPWVDD0SQCFFY3"] + // Sample: ["01GPBN5YDY6JKBWE44H7YQBDCQ","01GPBN65PDWSBPWVDD0SQCFFY3"] // in: formData RuleIDs []string `form:"rule_ids[]" json:"rule_ids" xml:"rule_ids"` } diff --git a/internal/api/model/rule.go b/internal/api/model/rule.go index f4caf7dd0..b94c502c5 100644 --- a/internal/api/model/rule.go +++ b/internal/api/model/rule.go @@ -27,15 +27,24 @@ type InstanceRule struct { // InstanceRuleCreateRequest represents a request to create a new instance rule, made through the admin API. // -// swagger:model instanceRuleCreateRequest +// swagger:parameters ruleCreate type InstanceRuleCreateRequest struct { - Text string `form:"text" validation:"required"` + // Text body for the instance rule, plaintext. + // required: true + // in: formData + Text string `form:"text" json:"text" validation:"required"` } // InstanceRuleUpdateRequest represents a request to update the text of an instance rule, made through the admin API. // -// swagger:model instanceRuleUpdateRequest +// swagger:parameters ruleUpdate type InstanceRuleUpdateRequest struct { - ID string `form:"id"` - Text string `form:"text"` + // The id of the rule to update. + // required: true + // in: path + ID string `form:"id" json:"id"` + // Text body for the updated instance rule, plaintext. + // required: true + // in: formData + Text string `form:"text" json:"text"` } diff --git a/internal/api/model/status.go b/internal/api/model/status.go index 8ca41c767..fed2cdf37 100644 --- a/internal/api/model/status.go +++ b/internal/api/model/status.go @@ -163,47 +163,33 @@ type StatusReblogged struct { // StatusCreateRequest models status creation parameters. // -// swagger:model statusCreateRequest +// swagger:ignore type StatusCreateRequest struct { // Text content of the status. // If media_ids is provided, this becomes optional. // Attaching a poll is optional while status is provided. - // in: formData Status string `form:"status" json:"status" xml:"status"` // Array of Attachment ids to be attached as media. // If provided, status becomes optional, and poll cannot be used. - // - // If the status is being submitted as a form, the key is 'media_ids[]', - // but if it's json or xml, the key is 'media_ids'. - // - // in: formData MediaIDs []string `form:"media_ids[]" json:"media_ids" xml:"media_ids"` // Poll to include with this status. - // in: formData Poll *PollRequest `form:"poll" json:"poll" xml:"poll"` // ID of the status being replied to, if status is a reply. - // in: formData InReplyToID string `form:"in_reply_to_id" json:"in_reply_to_id" xml:"in_reply_to_id"` // Status and attached media should be marked as sensitive. - // in: formData Sensitive bool `form:"sensitive" json:"sensitive" xml:"sensitive"` // Text to be shown as a warning or subject before the actual content. // Statuses are generally collapsed behind this field. - // in: formData SpoilerText string `form:"spoiler_text" json:"spoiler_text" xml:"spoiler_text"` // Visibility of the posted status. - // in: formData Visibility Visibility `form:"visibility" json:"visibility" xml:"visibility"` // ISO 8601 Datetime at which to schedule a status. // Providing this parameter will cause ScheduledStatus to be returned instead of Status. // Must be at least 5 minutes in the future. - // in: formData ScheduledAt string `form:"scheduled_at" json:"scheduled_at" xml:"scheduled_at"` // ISO 639 language code for this status. - // in: formData Language string `form:"language" json:"language" xml:"language"` // Content type to use when parsing this status. - // in: formData ContentType StatusContentType `form:"content_type" json:"content_type" xml:"content_type"` } @@ -229,7 +215,7 @@ const ( // AdvancedStatusCreateForm wraps the mastodon-compatible status create form along with the GTS advanced // visibility settings. // -// swagger:parameters statusCreate +// swagger:ignore type AdvancedStatusCreateForm struct { StatusCreateRequest AdvancedVisibilityFlagsForm @@ -238,7 +224,7 @@ type AdvancedStatusCreateForm struct { // AdvancedVisibilityFlagsForm allows a few more advanced flags to be set on new statuses, in addition // to the standard mastodon-compatible ones. // -// swagger:model advancedVisibilityFlagsForm +// swagger:ignore type AdvancedVisibilityFlagsForm struct { // This status will be federated beyond the local timeline(s). Federated *bool `form:"federated" json:"federated" xml:"federated"` |