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.StatusesResponse
18 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
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: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
36 200 => Operation.response("Account", "application/json", AccountCreateResponse)
41 def verify_credentials_operation do
44 description: "Test to make sure that the user token works.",
45 summary: "Verify account credentials",
46 operationId: "AccountController.verify_credentials",
47 security: [%{"oAuth" => ["read:accounts"]}],
49 200 => Operation.response("Account", "application/json", Account)
54 def update_credentials_operation do
57 summary: "Update account credentials",
58 description: "Update the user's display and preferences.",
59 operationId: "AccountController.update_credentials",
60 security: [%{"oAuth" => ["write:accounts"]}],
62 Helpers.request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
64 200 => Operation.response("Account", "application/json", Account)
69 def relationships_operation do
72 summary: "Check relationships to other accounts",
73 operationId: "AccountController.relationships",
74 description: "Find out whether a given account is followed, blocked, muted, etc.",
75 security: [%{"oAuth" => ["read:follows"]}],
81 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
88 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
97 operationId: "AccountController.show",
98 description: "View information about a profile.",
99 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
101 200 => Operation.response("Account", "application/json", Account)
106 def statuses_operation do
110 operationId: "AccountController.statuses",
112 "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)",
114 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
115 Operation.parameter(:pinned, :query, BooleanLike, "Pinned"),
116 Operation.parameter(:tagged, :query, :string, "With tag"),
117 Operation.parameter(:only_media, :query, BooleanLike, "Only meadia"),
118 Operation.parameter(:with_muted, :query, BooleanLike, "With muted"),
119 Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblobs"),
121 :exclude_visibilities,
123 %Schema{type: :array, items: VisibilityScope},
124 "Exclude visibilities"
126 Operation.parameter(:max_id, :query, :string, "Max ID"),
127 Operation.parameter(:min_id, :query, :string, "Mix ID"),
128 Operation.parameter(:since_id, :query, :string, "Since ID"),
132 %Schema{type: :integer, default: 20, maximum: 40},
137 200 => Operation.response("Statuses", "application/json", StatusesResponse)
142 def followers_operation do
145 summary: "Followers",
146 operationId: "AccountController.followers",
147 security: [%{"oAuth" => ["read:accounts"]}],
149 "Accounts which follow the given account, if network is not hidden by the account owner.",
151 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
152 Operation.parameter(:max_id, :query, :string, "Max ID"),
153 Operation.parameter(:min_id, :query, :string, "Mix ID"),
154 Operation.parameter(:since_id, :query, :string, "Since ID"),
158 %Schema{type: :integer, default: 20, maximum: 40},
163 200 => Operation.response("Accounts", "application/json", AccountsResponse)
168 def following_operation do
171 summary: "Following",
172 operationId: "AccountController.following",
173 security: [%{"oAuth" => ["read:accounts"]}],
175 "Accounts which the given account is following, if network is not hidden by the account owner.",
177 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
178 Operation.parameter(:max_id, :query, :string, "Max ID"),
179 Operation.parameter(:min_id, :query, :string, "Mix ID"),
180 Operation.parameter(:since_id, :query, :string, "Since ID"),
184 %Schema{type: :integer, default: 20, maximum: 40},
189 200 => Operation.response("Accounts", "application/json", AccountsResponse)
194 def lists_operation, do: :ok
195 def follow_operation, do: :ok
196 def unfollow_operation, do: :ok
197 def mute_operation, do: :ok
198 def unmute_operation, do: :ok
199 def block_operation, do: :ok
200 def unblock_operation, do: :ok
201 def follows_operation, do: :ok
202 def mutes_operation, do: :ok
203 def blocks_operation, do: :ok
204 def endorsements_operation, do: :ok