From 58dddd86e0ddbb0c6aa54506dcef162321babfbb Mon Sep 17 00:00:00 2001
From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>
Date: Sat, 31 Jul 2021 17:49:59 +0200
Subject: Swagger (#124)
* start experimenting with swagger documentation
* further adventures in swagger
* do a few more api paths
* account paths documented
* go fmt
* fix up some models
* bit o lintin'
---
internal/api/client/account/accountcreate.go | 44 +++++++++-
internal/api/client/account/accountget.go | 38 ++++++++-
internal/api/client/account/accountupdate.go | 76 +++++++++++++++--
internal/api/client/account/accountverify.go | 28 ++++++-
internal/api/client/account/block.go | 35 ++++++++
internal/api/client/account/follow.go | 35 ++++++++
internal/api/client/account/followers.go | 37 +++++++++
internal/api/client/account/following.go | 37 +++++++++
internal/api/client/account/relationships.go | 39 +++++++++
internal/api/client/account/statuses.go | 74 +++++++++++++++--
internal/api/client/account/unblock.go | 35 ++++++++
internal/api/client/account/unfollow.go | 35 ++++++++
internal/api/model/account.go | 119 ++++++++++++++++++---------
internal/api/model/activity.go | 31 -------
internal/api/model/application.go | 23 ++++--
internal/api/model/attachment.go | 26 ++++--
internal/api/model/card.go | 18 ++--
internal/api/model/domainblock.go | 34 ++++++--
internal/api/model/emoji.go | 20 +++--
internal/api/model/field.go | 17 ++--
internal/api/model/mention.go | 15 ++--
internal/api/model/poll.go | 11 ++-
internal/api/model/relationship.go | 27 +++---
internal/api/model/status.go | 67 +++++++++------
internal/api/model/tag.go | 8 +-
internal/api/model/token.go | 15 ++--
26 files changed, 758 insertions(+), 186 deletions(-)
delete mode 100644 internal/api/model/activity.go
(limited to 'internal/api')
diff --git a/internal/api/client/account/accountcreate.go b/internal/api/client/account/accountcreate.go
index b53d8c412..e7b05fcc6 100644
--- a/internal/api/client/account/accountcreate.go
+++ b/internal/api/client/account/accountcreate.go
@@ -32,13 +32,53 @@ import (
// AccountCreatePOSTHandler handles create account requests, validates them,
// and puts them in the database if they're valid.
-// It should be served as a POST at /api/v1/accounts
+//
+// swagger:operation POST /api/v1/accounts accountCreate
+//
+// Create a new account using an application token.
+//
+// ---
+// tags:
+// - accounts
+//
+// consumes:
+// - application/json
+// - application/xml
+// - application/x-www-form-urlencoded
+// - multipart/form-data
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: Account Create Request
+// in: body
+// schema:
+// "$ref": "#/definitions/accountCreateRequest"
+//
+// security:
+// - OAuth2 Application:
+// - write:accounts
+//
+// responses:
+// '200':
+// description: "An OAuth2 access token for the newly-created account."
+// schema:
+// "$ref": "#/definitions/oauthToken"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
+// '500':
+// description: internal error
func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
l := m.log.WithField("func", "accountCreatePOSTHandler")
authed, err := oauth.Authed(c, true, true, false, false)
if err != nil {
l.Debugf("couldn't auth: %s", err)
- c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
+ c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
return
}
diff --git a/internal/api/client/account/accountget.go b/internal/api/client/account/accountget.go
index 5ca17a167..ff7c1a485 100644
--- a/internal/api/client/account/accountget.go
+++ b/internal/api/client/account/accountget.go
@@ -25,12 +25,42 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
-// AccountGETHandler serves the account information held by the server in response to a GET
-// request. It should be served as a GET at /api/v1/accounts/:id.
+// AccountGETHandler returns info about the given account.
//
-// See: https://docs.joinmastodon.org/methods/accounts/
+// swagger:operation GET /api/v1/accounts/{id} accountGet
+//
+// Get information about an account with the given ID.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: The id of the requested account.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// schema:
+// "$ref": "#/definitions/account"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountGETHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, false, false, false, false)
+ authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
return
diff --git a/internal/api/client/account/accountupdate.go b/internal/api/client/account/accountupdate.go
index 23a350503..6d9a3f3f9 100644
--- a/internal/api/client/account/accountupdate.go
+++ b/internal/api/client/account/accountupdate.go
@@ -29,14 +29,78 @@ import (
// AccountUpdateCredentialsPATCHHandler allows a user to modify their account/profile settings.
// It should be served as a PATCH at /api/v1/accounts/update_credentials
//
-// TODO: this can be optimized massively by building up a picture of what we want the new account
-// details to be, and then inserting it all in the database at once. As it is, we do queries one-by-one
-// which is not gonna make the database very happy when lots of requests are going through.
-// This way it would also be safer because the update won't happen until *all* the fields are validated.
-// Otherwise we risk doing a partial update and that's gonna cause probllleeemmmsss.
+// swagger:operation PATCH /api/v1/accounts/update_credentials accountUpdate
+//
+// Update your account.
+//
+// ---
+// tags:
+// - accounts
+//
+// consumes:
+// - multipart/form-data
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: discoverable
+// in: formData
+// description: Account should be made discoverable and shown in the profile directory (if enabled).
+// type: boolean
+// - name: bot
+// in: formData
+// description: Account is flagged as a bot.
+// type: boolean
+// - name: display_name
+// in: formData
+// description: The display name to use for the account.
+// type: string
+// - name: note
+// in: formData
+// description: Bio/description of this account.
+// type: string
+// - name: avatar
+// in: formData
+// description: Avatar of the user.
+// type: file
+// - name: header
+// in: formData
+// description: Header of the user.
+// type: file
+// - name: locked
+// in: formData
+// description: Require manual approval of follow requests.
+// type: boolean
+// - name: source.privacy
+// in: formData
+// description: Default post privacy for authored statuses.
+// type: string
+// - name: source.sensitive
+// in: formData
+// description: Mark authored statuses as sensitive by default.
+// type: boolean
+// - name: source.language
+// in: formData
+// description: Default language to use for authored statuses (ISO 6391).
+// type: string
+//
+// security:
+// - OAuth2 Bearer:
+// - write:accounts
+//
+// responses:
+// '200':
+// description: "The newly updated account."
+// schema:
+// "$ref": "#/definitions/account"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
func (m *Module) AccountUpdateCredentialsPATCHHandler(c *gin.Context) {
l := m.log.WithField("func", "accountUpdateCredentialsPATCHHandler")
- authed, err := oauth.Authed(c, true, false, false, true)
+ authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
l.Debugf("couldn't auth: %s", err)
c.JSON(http.StatusForbidden, gin.H{"error": err.Error()})
diff --git a/internal/api/client/account/accountverify.go b/internal/api/client/account/accountverify.go
index 4c62ff705..0ff61362d 100644
--- a/internal/api/client/account/accountverify.go
+++ b/internal/api/client/account/accountverify.go
@@ -27,7 +27,33 @@ import (
// AccountVerifyGETHandler serves a user's account details to them IF they reached this
// handler while in possession of a valid token, according to the oauth middleware.
-// It should be served as a GET at /api/v1/accounts/verify_credentials
+// It should be served as a GET at /api/v1/accounts/verify_credentials.
+//
+// swagger:operation GET /api/v1/accounts/verify_credentials accountVerify
+//
+// Verify a token by returning account details pertaining to it.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// schema:
+// "$ref": "#/definitions/account"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountVerifyGETHandler(c *gin.Context) {
l := m.log.WithField("func", "accountVerifyGETHandler")
authed, err := oauth.Authed(c, true, false, false, true)
diff --git a/internal/api/client/account/block.go b/internal/api/client/account/block.go
index c83837c2a..ec2ba5b2c 100644
--- a/internal/api/client/account/block.go
+++ b/internal/api/client/account/block.go
@@ -26,6 +26,41 @@ import (
)
// AccountBlockPOSTHandler handles the creation of a block from the authed account targeting the given account ID.
+//
+// swagger:operation POST /api/v1/accounts/{id}/block accountBlock
+//
+// Block account with id.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: The id of the account to block.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - write:blocks
+//
+// responses:
+// '200':
+// name: account relationship
+// description: Your relationship to this account.
+// schema:
+// "$ref": "#/definitions/accountRelationship"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountBlockPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
diff --git a/internal/api/client/account/follow.go b/internal/api/client/account/follow.go
index bee41c280..a0c5213fa 100644
--- a/internal/api/client/account/follow.go
+++ b/internal/api/client/account/follow.go
@@ -27,6 +27,41 @@ import (
)
// AccountFollowPOSTHandler is the endpoint for creating a new follow request to the target account
+//
+// swagger:operation POST /api/v1/accounts/{id}/follow accountFollow
+//
+// Follow account with id.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: The id of the account to follow.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - write:follows
+//
+// responses:
+// '200':
+// name: account relationship
+// description: Your relationship to this account.
+// schema:
+// "$ref": "#/definitions/accountRelationship"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountFollowPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
diff --git a/internal/api/client/account/followers.go b/internal/api/client/account/followers.go
index 3401df24c..85bb65978 100644
--- a/internal/api/client/account/followers.go
+++ b/internal/api/client/account/followers.go
@@ -26,6 +26,43 @@ import (
)
// AccountFollowersGETHandler serves the followers of the requested account, if they're visible to the requester.
+//
+// swagger:operation GET /api/v1/accounts/{id}/followers accountFollowers
+//
+// See followers of account with given id.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: Account ID.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// name: accounts
+// description: Array of accounts that follow this account.
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/account"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountFollowersGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
diff --git a/internal/api/client/account/following.go b/internal/api/client/account/following.go
index f1adeac2b..e0ab2748b 100644
--- a/internal/api/client/account/following.go
+++ b/internal/api/client/account/following.go
@@ -26,6 +26,43 @@ import (
)
// AccountFollowingGETHandler serves the following of the requested account, if they're visible to the requester.
+//
+// swagger:operation GET /api/v1/accounts/{id}/following accountFollowing
+//
+// See accounts followed by given account id.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: Account ID.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// name: accounts
+// description: Array of accounts that are followed by this account.
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/account"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountFollowingGETHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
diff --git a/internal/api/client/account/relationships.go b/internal/api/client/account/relationships.go
index fd96867ac..b0404c3a1 100644
--- a/internal/api/client/account/relationships.go
+++ b/internal/api/client/account/relationships.go
@@ -9,6 +9,45 @@ import (
)
// AccountRelationshipsGETHandler serves the relationship of the requesting account with one or more requested account IDs.
+//
+// swagger:operation GET /api/v1/accounts/relationships accountRelationships
+//
+// See your account's relationships with the given account IDs.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: array
+// items:
+// type: string
+// description: Account IDs.
+// in: query
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// name: account relationships
+// description: Array of account relationships.
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/accountRelationship"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountRelationshipsGETHandler(c *gin.Context) {
l := m.log.WithField("func", "AccountRelationshipsGETHandler")
diff --git a/internal/api/client/account/statuses.go b/internal/api/client/account/statuses.go
index c92e85cee..8e9faffcf 100644
--- a/internal/api/client/account/statuses.go
+++ b/internal/api/client/account/statuses.go
@@ -28,13 +28,75 @@ import (
// AccountStatusesGETHandler serves the statuses of the requested account, if they're visible to the requester.
//
-// Several different filters might be passed into this function in the query:
+// swagger:operation GET /api/v1/accounts/{id}/statuses accountStatuses
//
-// limit -- show only limit number of statuses
-// exclude_replies -- exclude statuses that are a reply to another status
-// max_id -- the maximum ID of the status to show
-// pinned -- show only pinned statuses
-// media_only -- show only statuses that have media attachments
+// See statuses posted by the requested account.
+//
+// The statuses will be returned in descending chronological order (newest first), with sequential IDs (bigger = newer).
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: Account ID.
+// in: path
+// required: true
+// - name: limit
+// type: integer
+// description: Number of statuses to return.
+// default: 30
+// in: query
+// required: false
+// - name: exclude_replies
+// type: boolean
+// description: Exclude statuses that are a reply to another status.
+// default: false
+// in: query
+// required: false
+// - name: max_id
+// type: string
+// description: |-
+// Return only statuses *OLDER* than the given max status ID.
+// The status with the specified ID will not be included in the response.
+// in: query
+// required: false
+// - name: pinned_only
+// type: boolean
+// description: Show only pinned statuses. In other words,e xclude statuses that are not pinned to the given account ID.
+// default: false
+// in: query
+// required: false
+// - name: media_only
+// type: boolean
+// description: Show only statuses with media attachments.
+// default: false
+// in: query
+// required: false
+//
+// security:
+// - OAuth2 Bearer:
+// - read:accounts
+//
+// responses:
+// '200':
+// name: statuses
+// description: Array of statuses..
+// schema:
+// type: array
+// items:
+// "$ref": "#/definitions/status"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountStatusesGETHandler(c *gin.Context) {
l := m.log.WithField("func", "AccountStatusesGETHandler")
diff --git a/internal/api/client/account/unblock.go b/internal/api/client/account/unblock.go
index 1cb959db9..60b7c766d 100644
--- a/internal/api/client/account/unblock.go
+++ b/internal/api/client/account/unblock.go
@@ -26,6 +26,41 @@ import (
)
// AccountUnblockPOSTHandler handles the removal of a block from the authed account targeting the given account ID.
+//
+// swagger:operation POST /api/v1/accounts/{id}/unblock accountUnblock
+//
+// Unblock account with ID.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: The id of the account to unblock.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - write:blocks
+//
+// responses:
+// '200':
+// name: account relationship
+// description: Your relationship to this account.
+// schema:
+// "$ref": "#/definitions/accountRelationship"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountUnblockPOSTHandler(c *gin.Context) {
authed, err := oauth.Authed(c, true, true, true, true)
if err != nil {
diff --git a/internal/api/client/account/unfollow.go b/internal/api/client/account/unfollow.go
index 69ed72b88..ba0ab8426 100644
--- a/internal/api/client/account/unfollow.go
+++ b/internal/api/client/account/unfollow.go
@@ -26,6 +26,41 @@ import (
)
// AccountUnfollowPOSTHandler is the endpoint for removing a follow and/or follow request to the target account
+//
+// swagger:operation POST /api/v1/accounts/{id}/unfollow accountUnfollow
+//
+// Unfollow account with id.
+//
+// ---
+// tags:
+// - accounts
+//
+// produces:
+// - application/json
+//
+// parameters:
+// - name: id
+// type: string
+// description: The id of the account to unfollow.
+// in: path
+// required: true
+//
+// security:
+// - OAuth2 Bearer:
+// - write:follows
+//
+// responses:
+// '200':
+// name: account relationship
+// description: Your relationship to this account.
+// schema:
+// "$ref": "#/definitions/accountRelationship"
+// '401':
+// description: unauthorized
+// '400':
+// description: bad request
+// '404':
+// description: not found
func (m *Module) AccountUnfollowPOSTHandler(c *gin.Context) {
l := m.log.WithField("func", "AccountUnfollowPOSTHandler")
authed, err := oauth.Authed(c, true, true, true, true)
diff --git a/internal/api/model/account.go b/internal/api/model/account.go
index ba5ac567a..1e02e38ec 100644
--- a/internal/api/model/account.go
+++ b/internal/api/model/account.go
@@ -23,104 +23,139 @@ import (
"net"
)
-// Account represents a mastodon-api Account object, as described here: https://docs.joinmastodon.org/entities/account/
+// Account represents a fediverse account of some kind, either a remote one or one on this instance.
+//
+// swagger:model account
type Account struct {
- // The account id
+ // The account id.
+ // example: 01FBVD42CQ3ZEEVMW180SBX03B
ID string `json:"id"`
// The username of the account, not including domain.
+ // example: some_user
Username string `json:"username"`
- // The Webfinger account URI. Equal to username for local users, or username@domain for remote users.
+ // The account URI as discovered via webfinger.
+ // Equal to username for local users, or username@domain for remote users.
+ // example: some_user@example.org
Acct string `json:"acct"`
- // The profile's display name.
+ // The account's display name.
+ // example: big jeff (he/him)
DisplayName string `json:"display_name"`
- // Whether the account manually approves follow requests.
+ // Account manually approves follow requests.
Locked bool `json:"locked"`
- // Whether the account has opted into discovery features such as the profile directory.
+ // Account has opted into discovery features such as the profile directory.
Discoverable bool `json:"discoverable,omitempty"`
- // A presentational flag. Indicates that the account may perform automated actions, may not be monitored, or identifies as a robot.
+ // Account identifies as a bot.
Bot bool `json:"bot"`
- // When the account was created. (ISO 8601 Datetime)
+ // When the account was created (ISO 8601 Datetime).
+ // example: 2021-07-30T09:20:25+00:00
CreatedAt string `json:"created_at"`
- // The profile's bio / description.
+ // Bio/description of this account.
Note string `json:"note"`
- // The location of the user's profile page.
+ // Web location of the account's profile page.
+ // example: https://example.org/@some_user
URL string `json:"url"`
- // An image icon that is shown next to statuses and in the profile.
+ // Web location of the account's avatar.
+ // example: https://example.org/media/some_user/avatar/original/avatar.jpeg
Avatar string `json:"avatar"`
- // A static version of the avatar. Equal to avatar if its value is a static image; different if avatar is an animated GIF.
+ // Web location of a static version of the account's avatar.
+ // Only relevant when the account's main avatar is a video or a gif.
+ // example: https://example.org/media/some_user/avatar/static/avatar.png
AvatarStatic string `json:"avatar_static"`
- // An image banner that is shown above the profile and in profile cards.
+ // Web location of the account's header image.
+ // example: https://example.org/media/some_user/header/original/header.jpeg
Header string `json:"header"`
- // A static version of the header. Equal to header if its value is a static image; different if header is an animated GIF.
+ // Web location of a static version of the account's header.
+ // Only relevant when the account's main header is a video or a gif.
+ // example: https://example.org/media/some_user/header/static/header.png
HeaderStatic string `json:"header_static"`
- // The reported followers of this profile.
+ // Number of accounts following this account, according to our instance.
FollowersCount int `json:"followers_count"`
- // The reported follows of this profile.
+ // Number of account's followed by this account, according to our instance.
FollowingCount int `json:"following_count"`
- // How many statuses are attached to this account.
+ // Number of statuses posted by this account, according to our instance.
StatusesCount int `json:"statuses_count"`
- // When the most recent status was posted. (ISO 8601 Datetime)
+ // When the account's most recent status was posted (ISO 8601 Datetime).
+ // example: 2021-07-30T09:20:25+00:00
LastStatusAt string `json:"last_status_at"`
- // Custom emoji entities to be used when rendering the profile. If none, an empty array will be returned.
+ // Array of custom emojis used in this account's note or display name.
Emojis []Emoji `json:"emojis"`
- // Additional metadata attached to a profile as name-value pairs.
+ // Additional metadata attached to this account's profile.
Fields []Field `json:"fields"`
- // An extra entity returned when an account is suspended.
+ // Account has been suspended by our instance.
Suspended bool `json:"suspended,omitempty"`
- // When a timed mute will expire, if applicable. (ISO 8601 Datetime)
+ // If this account has been muted, when will the mute expire (ISO 8601 Datetime).
+ // example: 2021-07-30T09:20:25+00:00
MuteExpiresAt string `json:"mute_expires_at,omitempty"`
- // An extra entity to be used with API methods to verify credentials and update credentials.
+ // Extra profile information. Shown only if the requester owns the account being requested.
Source *Source `json:"source,omitempty"`
}
// AccountCreateRequest represents the form submitted during a POST request to /api/v1/accounts.
-// See https://docs.joinmastodon.org/methods/accounts/
+//
+// swagger:model accountCreateRequest
type AccountCreateRequest struct {
// Text that will be reviewed by moderators if registrations require manual approval.
Reason string `form:"reason" json:"reason" xml:"reason"`
- // The desired username for the account
+ // The desired username for the account.
+ // swagger:parameters
+ // pattern: [a-z0-9_]{2,64}
+ // example: a_valid_username
+ // required: true
Username string `form:"username" json:"username" xml:"username" binding:"required"`
- // The email address to be used for login
+ // The email address to be used for login.
+ // swagger:parameters
+ // example: someone@wherever.com
+ // required: true
Email string `form:"email" json:"email" xml:"email" binding:"required"`
- // The password to be used for login
+ // The password to be used for login. This will be hashed before storage.
+ // swagger:parameters
+ // example: some_really_really_really_strong_password
+ // required: true
Password string `form:"password" json:"password" xml:"password" binding:"required"`
- // Whether the user agrees to the local rules, terms, and policies.
- // These should be presented to the user in order to allow them to consent before setting this parameter to TRUE.
+ // The user agrees to the terms, conditions, and policies of the instance.
+ // swagger:parameters
+ // required: true
Agreement bool `form:"agreement" json:"agreement" xml:"agreement" binding:"required"`
- // The language of the confirmation email that will be sent
+ // The language of the confirmation email that will be sent.
+ // swagger:parameters
+ // example: en
+ // Required: true
Locale string `form:"locale" json:"locale" xml:"locale" binding:"required"`
- // The IP of the sign up request, will not be parsed from the form but must be added manually
+ // The IP of the sign up request, will not be parsed from the form.
+ // swagger:parameters
+ // swagger:ignore
IP net.IP `form:"-"`
}
// UpdateCredentialsRequest represents the form submitted during a PATCH request to /api/v1/accounts/update_credentials.
-// See https://docs.joinmastodon.org/methods/accounts/
+// swagger:ignore
type UpdateCredentialsRequest struct {
- // Whether the account should be shown in the profile directory.
+ // Account should be made discoverable and shown in the profile directory (if enabled).
Discoverable *bool `form:"discoverable" json:"discoverable" xml:"discoverable"`
- // Whether the account has a bot flag.
+ // Account is flagged as a bot.
Bot *bool `form:"bot" json:"bot" xml:"bot"`
- // The display name to use for the profile.
+ // The display name to use for the account.
DisplayName *string `form:"display_name" json:"display_name" xml:"display_name"`
- // The account bio.
+ // Bio/description of this account.
Note *string `form:"note" json:"note" xml:"note"`
- // Avatar image encoded using multipart/form-data
+ // Avatar image encoded using multipart/form-data.
Avatar *multipart.FileHeader `form:"avatar" json:"avatar" xml:"avatar"`
// Header image encoded using multipart/form-data
Header *multipart.FileHeader `form:"header" json:"header" xml:"header"`
- // Whether manual approval of follow requests is required.
+ // Require manual approval of follow requests.
Locked *bool `form:"locked" json:"locked" xml:"locked"`
- // New Source values for this account
+ // New Source values for this account.
Source *UpdateSource `form:"source" json:"source" xml:"source"`
// Profile metadata name and value
FieldsAttributes *[]UpdateField `form:"fields_attributes" json:"fields_attributes" xml:"fields_attributes"`
}
// UpdateSource is to be used specifically in an UpdateCredentialsRequest.
+// swagger:ignore
type UpdateSource struct {
// Default post privacy for authored statuses.
Privacy *string `form:"privacy" json:"privacy" xml:"privacy"`
- // Whether to mark authored statuses as sensitive by default.
+ // Mark authored statuses as sensitive by default.
Sensitive *bool `form:"sensitive" json:"sensitive" xml:"sensitive"`
// Default language to use for authored statuses. (ISO 6391)
Language *string `form:"language" json:"language" xml:"language"`
@@ -128,6 +163,8 @@ type UpdateSource struct {
// UpdateField is to be used specifically in an UpdateCredentialsRequest.
// By default, max 4 fields and 255 characters per property/value.
+//
+// swagger:model updateField
type UpdateField struct {
// Name of the field
Name *string `form:"name" json:"name" xml:"name"`
@@ -136,6 +173,8 @@ type UpdateField struct {
}
// AccountFollowRequest is for parsing requests at /api/v1/accounts/:id/follow
+//
+// swagger:model accountFollowRequest
type AccountFollowRequest struct {
// ID of the account to follow request
// This should be a URL parameter not a form field
diff --git a/internal/api/model/activity.go b/internal/api/model/activity.go
deleted file mode 100644
index c1736a8d6..000000000
--- a/internal/api/model/activity.go
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see
Hey this is a status!
Content string `json:"content"` - // The status being reblogged. + // The status that this status is a reblog/boost of. Reblog *Status `json:"reblog,omitempty"` - // The application used to post this status. + // The application used to post this status, if visible. Application *Application `json:"application"` // The account that authored this status. Account *Account `json:"account"` @@ -108,17 +121,21 @@ type StatusCreateRequest struct { Format StatusFormat `form:"format" json:"format" xml:"format"` } -// Visibility denotes the visibility of this status to other users +// Visibility denotes the visibility of a status to other users. +// +// swagger:model statusVisibility type Visibility string const ( - // VisibilityPublic means visible to everyone + // VisibilityPublic is visible to everyone, and will be available via the web even for nonauthenticated users. VisibilityPublic Visibility = "public" - // VisibilityUnlisted means visible to everyone but only on home timelines or in lists + // VisibilityUnlisted is visible to everyone, but only on home timelines, lists, etc. VisibilityUnlisted Visibility = "unlisted" - // VisibilityPrivate means visible to followers only + // VisibilityPrivate is visible only to followers of the account that posted the status. VisibilityPrivate Visibility = "private" - // VisibilityDirect means visible only to tagged recipients + // VisibilityMutualsOnly is visible only to mutual followers of the account that posted the status. + VisibilityMutualsOnly Visibility = "mutuals_only" + // VisibilityDirect is visible only to accounts tagged in the status. It is equivalent to a direct message. VisibilityDirect Visibility = "direct" ) diff --git a/internal/api/model/tag.go b/internal/api/model/tag.go index f009b4cef..951f07808 100644 --- a/internal/api/model/tag.go +++ b/internal/api/model/tag.go @@ -18,10 +18,14 @@ package model -// Tag represents a hashtag used within the content of a status. See https://docs.joinmastodon.org/entities/tag/ +// Tag represents a hashtag used within the content of a status. +// +// swagger:model tag type Tag struct { // The value of the hashtag after the # sign. + // example: helloworld Name string `json:"name"` - // A link to the hashtag on the instance. + // Web link to the hashtag. + // example: https://example.org/tags/helloworld URL string `json:"url"` } diff --git a/internal/api/model/token.go b/internal/api/model/token.go index 611ab214c..29a3c6f1d 100644 --- a/internal/api/model/token.go +++ b/internal/api/model/token.go @@ -18,14 +18,19 @@ package model -// Token represents an OAuth token used for authenticating with the API and performing actions.. See https://docs.joinmastodon.org/entities/token/ +// Token represents an OAuth token used for authenticating with the GoToSocial API and performing actions. +// +// swagger:model oauthToken type Token struct { - // An OAuth token to be used for authorization. + // Access token used for authorization. AccessToken string `json:"access_token"` - // The OAuth token type. Mastodon uses Bearer tokens. + // OAuth token type. Will always be 'Bearer'. + // example: bearer TokenType string `json:"token_type"` - // The OAuth scopes granted by this token, space-separated. + // OAuth scopes granted by this token, space-separated. + // example: read write admin Scope string `json:"scope"` - // When the token was generated. (UNIX timestamp seconds) + // When the OAuth token was generated (UNIX timestamp seconds). + // example: 1627644520 CreatedAt int64 `json:"created_at"` } -- cgit v1.2.3