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.Helpers
10 alias Pleroma.Web.ApiSpec.Schemas.Account
11 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
12 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
13 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
14 alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
15 alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
16 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
17 alias Pleroma.Web.ApiSpec.Schemas.ListsResponse
18 alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
19 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
21 @spec open_api_operation(atom) :: Operation.t()
22 def open_api_operation(action) do
23 operation = String.to_existing_atom("#{action}_operation")
24 apply(__MODULE__, operation, [])
27 @spec create_operation() :: Operation.t()
28 def create_operation do
31 summary: "Register an account",
33 "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.",
34 operationId: "AccountController.create",
35 requestBody: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
37 200 => Operation.response("Account", "application/json", AccountCreateResponse)
42 def verify_credentials_operation do
45 description: "Test to make sure that the user token works.",
46 summary: "Verify account credentials",
47 operationId: "AccountController.verify_credentials",
48 security: [%{"oAuth" => ["read:accounts"]}],
50 200 => Operation.response("Account", "application/json", Account)
55 def update_credentials_operation do
58 summary: "Update account credentials",
59 description: "Update the user's display and preferences.",
60 operationId: "AccountController.update_credentials",
61 security: [%{"oAuth" => ["write:accounts"]}],
63 Helpers.request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
65 200 => Operation.response("Account", "application/json", Account)
70 def relationships_operation do
73 summary: "Check relationships to other accounts",
74 operationId: "AccountController.relationships",
75 description: "Find out whether a given account is followed, blocked, muted, etc.",
76 security: [%{"oAuth" => ["read:follows"]}],
82 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
89 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
98 operationId: "AccountController.show",
99 description: "View information about a profile.",
100 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
102 200 => Operation.response("Account", "application/json", Account)
107 def statuses_operation do
111 operationId: "AccountController.statuses",
113 "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)",
115 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
116 Operation.parameter(:pinned, :query, BooleanLike, "Pinned"),
117 Operation.parameter(:tagged, :query, :string, "With tag"),
118 Operation.parameter(:only_media, :query, BooleanLike, "Only meadia"),
119 Operation.parameter(:with_muted, :query, BooleanLike, "With muted"),
120 Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblobs"),
122 :exclude_visibilities,
124 %Schema{type: :array, items: VisibilityScope},
125 "Exclude visibilities"
127 Operation.parameter(:max_id, :query, :string, "Max ID"),
128 Operation.parameter(:min_id, :query, :string, "Mix ID"),
129 Operation.parameter(:since_id, :query, :string, "Since ID"),
133 %Schema{type: :integer, default: 20, maximum: 40},
138 200 => Operation.response("Statuses", "application/json", StatusesResponse)
143 def followers_operation do
146 summary: "Followers",
147 operationId: "AccountController.followers",
148 security: [%{"oAuth" => ["read:accounts"]}],
150 "Accounts which follow the given account, if network is not hidden by the account owner.",
152 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
153 Operation.parameter(:max_id, :query, :string, "Max ID"),
154 Operation.parameter(:min_id, :query, :string, "Mix ID"),
155 Operation.parameter(:since_id, :query, :string, "Since ID"),
159 %Schema{type: :integer, default: 20, maximum: 40},
164 200 => Operation.response("Accounts", "application/json", AccountsResponse)
169 def following_operation do
172 summary: "Following",
173 operationId: "AccountController.following",
174 security: [%{"oAuth" => ["read:accounts"]}],
176 "Accounts which the given account is following, if network is not hidden by the account owner.",
178 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
179 Operation.parameter(:max_id, :query, :string, "Max ID"),
180 Operation.parameter(:min_id, :query, :string, "Mix ID"),
181 Operation.parameter(:since_id, :query, :string, "Since ID"),
185 %Schema{type: :integer, default: 20, maximum: 40},
190 200 => Operation.response("Accounts", "application/json", AccountsResponse)
195 def lists_operation do
198 summary: "Lists containing this account",
199 operationId: "AccountController.lists",
200 security: [%{"oAuth" => ["read:lists"]}],
201 description: "User lists that you have added this account to.",
203 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
206 200 => Operation.response("Lists", "application/json", ListsResponse)
211 def follow_operation, do: :ok
212 def unfollow_operation, do: :ok
213 def mute_operation, do: :ok
214 def unmute_operation, do: :ok
215 def block_operation, do: :ok
216 def unblock_operation, do: :ok
217 def follows_operation, do: :ok
218 def mutes_operation, do: :ok
219 def blocks_operation, do: :ok
220 def endorsements_operation, do: :ok