1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.AccountOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Reference
8 alias OpenApiSpex.Schema
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
12 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
13 alias Pleroma.Web.ApiSpec.Schemas.AccountFollowsRequest
14 alias Pleroma.Web.ApiSpec.Schemas.AccountMuteRequest
15 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
16 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
17 alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
18 alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
19 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
20 alias Pleroma.Web.ApiSpec.Schemas.ListsResponse
21 alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
22 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
24 import Pleroma.Web.ApiSpec.Helpers
26 @spec open_api_operation(atom) :: Operation.t()
27 def open_api_operation(action) do
28 operation = String.to_existing_atom("#{action}_operation")
29 apply(__MODULE__, operation, [])
32 @spec create_operation() :: Operation.t()
33 def create_operation do
36 summary: "Register an account",
38 "Creates a user and account records. Returns an account access token for the app that initiated the request. The app should save this token for later, and should wait for the user to confirm their account by clicking a link in their email inbox.",
39 operationId: "AccountController.create",
40 requestBody: request_body("Parameters", AccountCreateRequest, required: true),
42 200 => Operation.response("Account", "application/json", AccountCreateResponse),
43 400 => Operation.response("Error", "application/json", ApiError),
44 403 => Operation.response("Error", "application/json", ApiError),
45 429 => Operation.response("Error", "application/json", ApiError)
50 def verify_credentials_operation do
53 description: "Test to make sure that the user token works.",
54 summary: "Verify account credentials",
55 operationId: "AccountController.verify_credentials",
56 security: [%{"oAuth" => ["read:accounts"]}],
58 200 => Operation.response("Account", "application/json", Account)
63 def update_credentials_operation do
66 summary: "Update account credentials",
67 description: "Update the user's display and preferences.",
68 operationId: "AccountController.update_credentials",
69 security: [%{"oAuth" => ["write:accounts"]}],
70 requestBody: request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
72 200 => Operation.response("Account", "application/json", Account),
73 403 => Operation.response("Error", "application/json", ApiError)
78 def relationships_operation do
81 summary: "Check relationships to other accounts",
82 operationId: "AccountController.relationships",
83 description: "Find out whether a given account is followed, blocked, muted, etc.",
84 security: [%{"oAuth" => ["read:follows"]}],
90 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
97 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
102 def show_operation do
106 operationId: "AccountController.show",
107 description: "View information about a profile.",
108 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
110 200 => Operation.response("Account", "application/json", Account),
111 404 => Operation.response("Error", "application/json", ApiError)
116 def statuses_operation do
120 operationId: "AccountController.statuses",
122 "Statuses posted to the given account. Public (for public statuses only), or user token + `read:statuses` (for private statuses the user is authorized to see)",
125 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
126 Operation.parameter(:pinned, :query, BooleanLike, "Include only pinned statuses"),
127 Operation.parameter(:tagged, :query, :string, "With tag"),
132 "Include only statuses with media attached"
138 "Include statuses from muted acccounts."
140 Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblogs"),
142 :exclude_visibilities,
144 %Schema{type: :array, items: VisibilityScope},
145 "Exclude visibilities"
147 ] ++ pagination_params(),
149 200 => Operation.response("Statuses", "application/json", StatusesResponse),
150 404 => Operation.response("Error", "application/json", ApiError)
155 def followers_operation do
158 summary: "Followers",
159 operationId: "AccountController.followers",
160 security: [%{"oAuth" => ["read:accounts"]}],
162 "Accounts which follow the given account, if network is not hidden by the account owner.",
164 [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
166 200 => Operation.response("Accounts", "application/json", AccountsResponse)
171 def following_operation do
174 summary: "Following",
175 operationId: "AccountController.following",
176 security: [%{"oAuth" => ["read:accounts"]}],
178 "Accounts which the given account is following, if network is not hidden by the account owner.",
180 [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ pagination_params(),
181 responses: %{200 => Operation.response("Accounts", "application/json", AccountsResponse)}
185 def lists_operation do
188 summary: "Lists containing this account",
189 operationId: "AccountController.lists",
190 security: [%{"oAuth" => ["read:lists"]}],
191 description: "User lists that you have added this account to.",
192 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
193 responses: %{200 => Operation.response("Lists", "application/json", ListsResponse)}
197 def follow_operation do
201 operationId: "AccountController.follow",
202 security: [%{"oAuth" => ["follow", "write:follows"]}],
203 description: "Follow the given account",
205 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
210 "Receive this account's reblogs in home timeline? Defaults to true."
214 200 => Operation.response("Relationship", "application/json", AccountRelationship),
215 400 => Operation.response("Error", "application/json", ApiError),
216 404 => Operation.response("Error", "application/json", ApiError)
221 def unfollow_operation do
225 operationId: "AccountController.unfollow",
226 security: [%{"oAuth" => ["follow", "write:follows"]}],
227 description: "Unfollow the given account",
228 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
230 200 => Operation.response("Relationship", "application/json", AccountRelationship),
231 400 => Operation.response("Error", "application/json", ApiError),
232 404 => Operation.response("Error", "application/json", ApiError)
237 def mute_operation do
241 operationId: "AccountController.mute",
242 security: [%{"oAuth" => ["follow", "write:mutes"]}],
243 requestBody: request_body("Parameters", AccountMuteRequest),
245 "Mute the given account. Clients should filter statuses and notifications from this account, if received (e.g. due to a boost in the Home timeline).",
247 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
251 %Schema{allOf: [BooleanLike], default: true},
252 "Mute notifications in addition to statuses? Defaults to `true`."
256 200 => Operation.response("Relationship", "application/json", AccountRelationship)
261 def unmute_operation do
265 operationId: "AccountController.unmute",
266 security: [%{"oAuth" => ["follow", "write:mutes"]}],
267 description: "Unmute the given account.",
268 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
270 200 => Operation.response("Relationship", "application/json", AccountRelationship)
275 def block_operation do
279 operationId: "AccountController.block",
280 security: [%{"oAuth" => ["follow", "write:blocks"]}],
282 "Block the given account. Clients should filter statuses from this account if received (e.g. due to a boost in the Home timeline)",
283 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
285 200 => Operation.response("Relationship", "application/json", AccountRelationship)
290 def unblock_operation do
294 operationId: "AccountController.unblock",
295 security: [%{"oAuth" => ["follow", "write:blocks"]}],
296 description: "Unblock the given account.",
297 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
299 200 => Operation.response("Relationship", "application/json", AccountRelationship)
304 def follows_operation do
308 operationId: "AccountController.follows",
309 security: [%{"oAuth" => ["follow", "write:follows"]}],
310 requestBody: request_body("Parameters", AccountFollowsRequest, required: true),
312 200 => Operation.response("Account", "application/json", AccountRelationship),
313 400 => Operation.response("Error", "application/json", ApiError),
314 404 => Operation.response("Error", "application/json", ApiError)
319 def mutes_operation do
322 summary: "Muted accounts",
323 operationId: "AccountController.mutes",
324 description: "Accounts the user has muted.",
325 security: [%{"oAuth" => ["follow", "read:mutes"]}],
327 200 => Operation.response("Accounts", "application/json", AccountsResponse)
332 def blocks_operation do
335 summary: "Blocked users",
336 operationId: "AccountController.blocks",
337 description: "View your blocks. See also accounts/:id/{block,unblock}",
338 security: [%{"oAuth" => ["read:blocks"]}],
340 200 => Operation.response("Accounts", "application/json", AccountsResponse)
345 def endorsements_operation do
348 summary: "Endorsements",
349 operationId: "AccountController.endorsements",
350 description: "Not implemented",
351 security: [%{"oAuth" => ["read:accounts"]}],
353 200 => Operation.response("Empry array", "application/json", %Schema{type: :array})
358 def identity_proofs_operation do
361 summary: "Identity proofs",
362 operationId: "AccountController.identity_proofs",
363 description: "Not implemented",
365 200 => Operation.response("Empry array", "application/json", %Schema{type: :array})