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.AccountRelationship
11 alias Pleroma.Web.ApiSpec.Schemas.ActorType
12 alias Pleroma.Web.ApiSpec.Schemas.ApiError
13 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
14 alias Pleroma.Web.ApiSpec.Schemas.List
15 alias Pleroma.Web.ApiSpec.Schemas.Status
16 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
18 import Pleroma.Web.ApiSpec.Helpers
20 @spec open_api_operation(atom) :: Operation.t()
21 def open_api_operation(action) do
22 operation = String.to_existing_atom("#{action}_operation")
23 apply(__MODULE__, operation, [])
26 @spec create_operation() :: Operation.t()
27 def create_operation do
30 summary: "Register an account",
32 "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.",
33 operationId: "AccountController.create",
34 requestBody: request_body("Parameters", create_request(), required: true),
36 200 => Operation.response("Account", "application/json", create_response()),
37 400 => Operation.response("Error", "application/json", ApiError),
38 403 => Operation.response("Error", "application/json", ApiError),
39 429 => Operation.response("Error", "application/json", ApiError)
44 def verify_credentials_operation do
47 description: "Test to make sure that the user token works.",
48 summary: "Verify account credentials",
49 operationId: "AccountController.verify_credentials",
50 security: [%{"oAuth" => ["read:accounts"]}],
52 200 => Operation.response("Account", "application/json", Account)
57 def update_credentials_operation do
60 summary: "Update account credentials",
61 description: "Update the user's display and preferences.",
62 operationId: "AccountController.update_credentials",
63 security: [%{"oAuth" => ["write:accounts"]}],
64 requestBody: request_body("Parameters", update_credentials_request(), required: true),
66 200 => Operation.response("Account", "application/json", Account),
67 403 => Operation.response("Error", "application/json", ApiError)
72 def relationships_operation do
75 summary: "Check relationships to other accounts",
76 operationId: "AccountController.relationships",
77 description: "Find out whether a given account is followed, blocked, muted, etc.",
78 security: [%{"oAuth" => ["read:follows"]}],
84 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
91 200 => Operation.response("Account", "application/json", array_of_relationships())
100 operationId: "AccountController.show",
101 description: "View information about a profile.",
102 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
104 200 => Operation.response("Account", "application/json", Account),
105 401 => Operation.response("Error", "application/json", ApiError),
106 404 => Operation.response("Error", "application/json", ApiError)
111 def statuses_operation do
115 operationId: "AccountController.statuses",
117 "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)",
120 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
121 Operation.parameter(:pinned, :query, BooleanLike, "Include only pinned statuses"),
122 Operation.parameter(:tagged, :query, :string, "With tag"),
127 "Include only statuses with media attached"
133 "Include statuses from muted acccounts."
135 Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblogs"),
136 Operation.parameter(:exclude_replies, :query, BooleanLike, "Exclude replies"),
138 :exclude_visibilities,
140 %Schema{type: :array, items: VisibilityScope},
141 "Exclude visibilities"
143 ] ++ pagination_params(),
145 200 => Operation.response("Statuses", "application/json", array_of_statuses()),
146 401 => Operation.response("Error", "application/json", ApiError),
147 404 => Operation.response("Error", "application/json", ApiError)
152 def followers_operation do
155 summary: "Followers",
156 operationId: "AccountController.followers",
157 security: [%{"oAuth" => ["read:accounts"]}],
159 "Accounts which follow the given account, if network is not hidden by the account owner.",
161 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
162 Operation.parameter(:id, :query, :string, "ID of the resource owner"),
163 with_relationships_param() | pagination_params()
166 200 => Operation.response("Accounts", "application/json", array_of_accounts())
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"},
181 Operation.parameter(:id, :query, :string, "ID of the resource owner"),
182 with_relationships_param() | pagination_params()
184 responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
188 def lists_operation do
191 summary: "Lists containing this account",
192 operationId: "AccountController.lists",
193 security: [%{"oAuth" => ["read:lists"]}],
194 description: "User lists that you have added this account to.",
195 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
196 responses: %{200 => Operation.response("Lists", "application/json", array_of_lists())}
200 def follow_operation do
204 operationId: "AccountController.follow",
205 security: [%{"oAuth" => ["follow", "write:follows"]}],
206 description: "Follow the given account",
208 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
218 description: "Receive this account's reblogs in home timeline? Defaults to true.",
226 200 => Operation.response("Relationship", "application/json", AccountRelationship),
227 400 => Operation.response("Error", "application/json", ApiError),
228 404 => Operation.response("Error", "application/json", ApiError)
233 def unfollow_operation do
237 operationId: "AccountController.unfollow",
238 security: [%{"oAuth" => ["follow", "write:follows"]}],
239 description: "Unfollow the given account",
240 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
242 200 => Operation.response("Relationship", "application/json", AccountRelationship),
243 400 => Operation.response("Error", "application/json", ApiError),
244 404 => Operation.response("Error", "application/json", ApiError)
249 def mute_operation do
253 operationId: "AccountController.mute",
254 security: [%{"oAuth" => ["follow", "write:mutes"]}],
255 requestBody: request_body("Parameters", mute_request()),
257 "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).",
259 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
263 %Schema{allOf: [BooleanLike], default: true},
264 "Mute notifications in addition to statuses? Defaults to `true`."
268 200 => Operation.response("Relationship", "application/json", AccountRelationship)
273 def unmute_operation do
277 operationId: "AccountController.unmute",
278 security: [%{"oAuth" => ["follow", "write:mutes"]}],
279 description: "Unmute the given account.",
280 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
282 200 => Operation.response("Relationship", "application/json", AccountRelationship)
287 def block_operation do
291 operationId: "AccountController.block",
292 security: [%{"oAuth" => ["follow", "write:blocks"]}],
294 "Block the given account. Clients should filter statuses from this account if received (e.g. due to a boost in the Home timeline)",
295 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
297 200 => Operation.response("Relationship", "application/json", AccountRelationship)
302 def unblock_operation do
306 operationId: "AccountController.unblock",
307 security: [%{"oAuth" => ["follow", "write:blocks"]}],
308 description: "Unblock the given account.",
309 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
311 200 => Operation.response("Relationship", "application/json", AccountRelationship)
316 def follow_by_uri_operation do
319 summary: "Follow by URI",
320 operationId: "AccountController.follows",
321 security: [%{"oAuth" => ["follow", "write:follows"]}],
322 requestBody: request_body("Parameters", follow_by_uri_request(), required: true),
324 200 => Operation.response("Account", "application/json", AccountRelationship),
325 400 => Operation.response("Error", "application/json", ApiError),
326 404 => Operation.response("Error", "application/json", ApiError)
331 def mutes_operation do
334 summary: "Muted accounts",
335 operationId: "AccountController.mutes",
336 description: "Accounts the user has muted.",
337 security: [%{"oAuth" => ["follow", "read:mutes"]}],
339 200 => Operation.response("Accounts", "application/json", array_of_accounts())
344 def blocks_operation do
347 summary: "Blocked users",
348 operationId: "AccountController.blocks",
349 description: "View your blocks. See also accounts/:id/{block,unblock}",
350 security: [%{"oAuth" => ["read:blocks"]}],
352 200 => Operation.response("Accounts", "application/json", array_of_accounts())
357 def endorsements_operation do
360 summary: "Endorsements",
361 operationId: "AccountController.endorsements",
362 description: "Not implemented",
363 security: [%{"oAuth" => ["read:accounts"]}],
365 200 => empty_array_response()
370 def identity_proofs_operation do
373 summary: "Identity proofs",
374 operationId: "AccountController.identity_proofs",
375 description: "Not implemented",
377 200 => empty_array_response()
382 defp create_request do
384 title: "AccountCreateRequest",
385 description: "POST body for creating an account",
387 required: [:username, :password, :agreement],
393 "Text that will be reviewed by moderators if registrations require manual approval"
395 username: %Schema{type: :string, description: "The desired username for the account"},
400 "The email address to be used for login. Required when `account_activation_required` is enabled.",
405 description: "The password to be used for login",
409 allOf: [BooleanLike],
411 "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."
416 description: "The language of the confirmation email that will be sent"
418 # Pleroma-specific properties:
419 fullname: %Schema{type: :string, nullable: true, description: "Full name"},
420 bio: %Schema{type: :string, description: "Bio", nullable: true, default: ""},
421 captcha_solution: %Schema{
424 description: "Provider-specific captcha solution"
426 captcha_token: %Schema{
429 description: "Provider-specific captcha token"
431 captcha_answer_data: %Schema{
434 description: "Provider-specific captcha data"
439 description: "Invite token required when the registrations aren't public"
443 "username" => "cofe",
444 "email" => "cofe@example.com",
445 "password" => "secret",
446 "agreement" => "true",
452 # TODO: This is actually a token respone, but there's no oauth operation file yet.
453 defp create_response do
455 title: "AccountCreateResponse",
456 description: "Response schema for an account",
459 token_type: %Schema{type: :string},
460 access_token: %Schema{type: :string},
461 refresh_token: %Schema{type: :string},
462 scope: %Schema{type: :string},
463 created_at: %Schema{type: :integer, format: :"date-time"},
464 me: %Schema{type: :string},
465 expires_in: %Schema{type: :integer}
468 "token_type" => "Bearer",
469 "access_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzk",
470 "refresh_token" => "i9hAVVzGld86Pl5JtLtizKoXVvtTlSCJvwaugCxvZzz",
471 "created_at" => 1_585_918_714,
473 "scope" => "read write follow push",
474 "me" => "https://gensokyo.2hu/users/raymoo"
479 defp update_credentials_request do
481 title: "AccountUpdateCredentialsRequest",
482 description: "POST body for creating an account",
486 allOf: [BooleanLike],
488 description: "Whether the account has a bot flag."
490 display_name: %Schema{
493 description: "The display name to use for the profile."
495 note: %Schema{type: :string, description: "The account bio."},
499 description: "Avatar image encoded using multipart/form-data",
505 description: "Header image encoded using multipart/form-data",
509 allOf: [BooleanLike],
511 description: "Whether manual approval of follow requests is required."
513 accepts_chat_messages: %Schema{
514 allOf: [BooleanLike],
516 description: "Whether the user accepts receiving chat messages."
518 fields_attributes: %Schema{
521 %Schema{type: :array, items: attribute_field()},
522 %Schema{type: :object, additionalProperties: %Schema{type: attribute_field()}}
525 # NOTE: `source` field is not supported
530 # privacy: %Schema{type: :string},
531 # sensitive: %Schema{type: :boolean},
532 # language: %Schema{type: :string}
536 # Pleroma-specific fields
537 no_rich_text: %Schema{
538 allOf: [BooleanLike],
540 description: "html tags are stripped from all statuses requested from the API"
542 hide_followers: %Schema{
543 allOf: [BooleanLike],
545 description: "user's followers will be hidden"
547 hide_follows: %Schema{
548 allOf: [BooleanLike],
550 description: "user's follows will be hidden"
552 hide_followers_count: %Schema{
553 allOf: [BooleanLike],
555 description: "user's follower count will be hidden"
557 hide_follows_count: %Schema{
558 allOf: [BooleanLike],
560 description: "user's follow count will be hidden"
562 hide_favorites: %Schema{
563 allOf: [BooleanLike],
565 description: "user's favorites timeline will be hidden"
568 allOf: [BooleanLike],
570 description: "user's role (e.g admin, moderator) will be exposed to anyone in the
573 default_scope: VisibilityScope,
574 pleroma_settings_store: %Schema{
577 description: "Opaque user settings to be saved on the backend."
579 skip_thread_containment: %Schema{
580 allOf: [BooleanLike],
582 description: "Skip filtering out broken threads"
584 allow_following_move: %Schema{
585 allOf: [BooleanLike],
587 description: "Allows automatically follow moved following accounts"
589 pleroma_background_image: %Schema{
592 description: "Sets the background image of the user.",
595 discoverable: %Schema{
596 allOf: [BooleanLike],
599 "Discovery of this account in search results and other services is allowed."
601 actor_type: ActorType
605 display_name: "cofe",
607 fields_attributes: [%{name: "foo", value: "bar"}],
609 hide_followers: true,
611 hide_followers_count: false,
612 hide_follows_count: false,
613 hide_favorites: false,
615 default_scope: "private",
616 pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
617 skip_thread_containment: false,
618 allow_following_move: false,
625 def array_of_accounts do
627 title: "ArrayOfAccounts",
630 example: [Account.schema().example]
634 defp array_of_relationships do
636 title: "ArrayOfRelationships",
637 description: "Response schema for account relationships",
639 items: AccountRelationship,
644 "showing_reblogs" => true,
645 "followed_by" => true,
647 "blocked_by" => true,
649 "muting_notifications" => false,
650 "requested" => false,
651 "domain_blocking" => false,
652 "subscribing" => false,
658 "showing_reblogs" => true,
659 "followed_by" => true,
661 "blocked_by" => true,
663 "muting_notifications" => false,
665 "domain_blocking" => false,
666 "subscribing" => false,
672 "showing_reblogs" => true,
673 "followed_by" => true,
675 "blocked_by" => false,
677 "muting_notifications" => false,
678 "requested" => false,
679 "domain_blocking" => true,
680 "subscribing" => true,
687 defp follow_by_uri_request do
689 title: "AccountFollowsRequest",
690 description: "POST body for muting an account",
693 uri: %Schema{type: :string, nullable: true, format: :uri}
701 title: "AccountMuteRequest",
702 description: "POST body for muting an account",
705 notifications: %Schema{
706 allOf: [BooleanLike],
708 description: "Mute notifications in addition to statuses? Defaults to true.",
713 "notifications" => true
718 defp array_of_lists do
720 title: "ArrayOfLists",
721 description: "Response schema for lists",
725 %{"id" => "123", "title" => "my list"},
726 %{"id" => "1337", "title" => "anotehr list"}
731 defp array_of_statuses do
733 title: "ArrayOfStatuses",
739 defp attribute_field do
741 title: "AccountAttributeField",
742 description: "Request schema for account custom fields",
745 name: %Schema{type: :string},
746 value: %Schema{type: :string}
748 required: [:name, :value],
751 "value" => "https://pleroma.com"