1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.TwitterUtilOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
11 import Pleroma.Web.ApiSpec.Helpers
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
18 def emoji_operation do
21 summary: "List all custom emojis",
22 operationId: "UtilController.emoji",
26 Operation.response("List", "application/json", %Schema{
28 additionalProperties: %Schema{
31 image_url: %Schema{type: :string},
32 tags: %Schema{type: :array, items: %Schema{type: :string}}
37 "image_url" => "/emoji/firefox.png",
46 def frontend_configurations_operation do
48 tags: ["Configuration"],
49 summary: "Dump frontend configurations",
50 operationId: "UtilController.frontend_configurations",
54 Operation.response("List", "application/json", %Schema{
56 additionalProperties: %Schema{type: :object}
62 def change_password_operation do
64 tags: ["Account credentials"],
65 summary: "Change account password",
66 security: [%{"oAuth" => ["write:accounts"]}],
67 operationId: "UtilController.change_password",
68 requestBody: request_body("Parameters", change_password_request(), required: true),
71 Operation.response("Success", "application/json", %Schema{
73 properties: %{status: %Schema{type: :string, example: "success"}}
75 400 => Operation.response("Error", "application/json", ApiError),
76 403 => Operation.response("Error", "application/json", ApiError)
81 defp change_password_request do
83 title: "ChangePasswordRequest",
84 description: "POST body for changing the account's passowrd",
86 required: [:password, :new_password, :new_password_confirmation],
88 password: %Schema{type: :string, description: "Current password"},
89 new_password: %Schema{type: :string, description: "New password"},
90 new_password_confirmation: %Schema{
92 description: "New password, confirmation"
98 def change_email_operation do
100 tags: ["Account credentials"],
101 summary: "Change account email",
102 security: [%{"oAuth" => ["write:accounts"]}],
103 operationId: "UtilController.change_email",
104 requestBody: request_body("Parameters", change_email_request(), required: true),
107 Operation.response("Success", "application/json", %Schema{
109 properties: %{status: %Schema{type: :string, example: "success"}}
111 400 => Operation.response("Error", "application/json", ApiError),
112 403 => Operation.response("Error", "application/json", ApiError)
117 defp change_email_request do
119 title: "ChangeEmailRequest",
120 description: "POST body for changing the account's email",
122 required: [:email, :password],
126 description: "New email. Set to blank to remove the user's email."
128 password: %Schema{type: :string, description: "Current password"}
133 def update_notificaton_settings_operation do
136 summary: "Update Notification Settings",
137 security: [%{"oAuth" => ["write:accounts"]}],
138 operationId: "UtilController.update_notificaton_settings",
141 :block_from_strangers,
144 "blocks notifications from accounts you do not follow"
147 :hide_notification_contents,
150 "removes the contents of a message from the push notification"
156 Operation.response("Success", "application/json", %Schema{
158 properties: %{status: %Schema{type: :string, example: "success"}}
160 400 => Operation.response("Error", "application/json", ApiError)
165 def disable_account_operation do
167 tags: ["Account credentials"],
168 summary: "Disable Account",
169 security: [%{"oAuth" => ["write:accounts"]}],
170 operationId: "UtilController.disable_account",
172 Operation.parameter(:password, :query, :string, "Password")
176 Operation.response("Success", "application/json", %Schema{
178 properties: %{status: %Schema{type: :string, example: "success"}}
180 403 => Operation.response("Error", "application/json", ApiError)
185 def delete_account_operation do
187 tags: ["Account credentials"],
188 summary: "Delete Account",
189 security: [%{"oAuth" => ["write:accounts"]}],
190 operationId: "UtilController.delete_account",
192 Operation.parameter(:password, :query, :string, "Password")
194 requestBody: request_body("Parameters", delete_account_request(), required: false),
197 Operation.response("Success", "application/json", %Schema{
199 properties: %{status: %Schema{type: :string, example: "success"}}
201 403 => Operation.response("Error", "application/json", ApiError)
206 def captcha_operation do
208 summary: "Get a captcha",
209 operationId: "UtilController.captcha",
212 200 => Operation.response("Success", "application/json", %Schema{type: :object})
217 def move_account_operation do
219 tags: ["Account credentials"],
220 summary: "Move account",
221 security: [%{"oAuth" => ["write:accounts"]}],
222 operationId: "UtilController.move_account",
223 requestBody: request_body("Parameters", move_account_request(), required: true),
226 Operation.response("Success", "application/json", %Schema{
228 properties: %{status: %Schema{type: :string, example: "success"}}
230 400 => Operation.response("Error", "application/json", ApiError),
231 403 => Operation.response("Error", "application/json", ApiError),
232 404 => Operation.response("Error", "application/json", ApiError)
237 defp move_account_request do
239 title: "MoveAccountRequest",
240 description: "POST body for moving the account",
242 required: [:password, :target_account],
244 password: %Schema{type: :string, description: "Current password"},
245 target_account: %Schema{
247 description: "The nickname of the target account to move to"
253 def list_aliases_operation do
255 tags: ["Account credentials"],
256 summary: "List account aliases",
257 security: [%{"oAuth" => ["read:accounts"]}],
258 operationId: "UtilController.list_aliases",
261 Operation.response("Success", "application/json", %Schema{
266 items: %Schema{type: :string},
267 example: ["foo@example.org"]
271 400 => Operation.response("Error", "application/json", ApiError),
272 403 => Operation.response("Error", "application/json", ApiError)
277 def add_alias_operation do
279 tags: ["Account credentials"],
280 summary: "Add an alias to this account",
281 security: [%{"oAuth" => ["write:accounts"]}],
282 operationId: "UtilController.add_alias",
283 requestBody: request_body("Parameters", add_alias_request(), required: true),
286 Operation.response("Success", "application/json", %Schema{
295 400 => Operation.response("Error", "application/json", ApiError),
296 403 => Operation.response("Error", "application/json", ApiError),
297 404 => Operation.response("Error", "application/json", ApiError)
302 defp add_alias_request do
304 title: "AddAliasRequest",
305 description: "PUT body for adding aliases",
311 description: "The nickname of the account to add to aliases"
317 def delete_alias_operation do
319 tags: ["Account credentials"],
320 summary: "Delete an alias from this account",
321 security: [%{"oAuth" => ["write:accounts"]}],
322 operationId: "UtilController.delete_alias",
323 requestBody: request_body("Parameters", delete_alias_request(), required: true),
326 Operation.response("Success", "application/json", %Schema{
335 400 => Operation.response("Error", "application/json", ApiError),
336 403 => Operation.response("Error", "application/json", ApiError),
337 404 => Operation.response("Error", "application/json", ApiError)
342 defp delete_alias_request do
344 title: "DeleteAliasRequest",
345 description: "PUT body for deleting aliases",
351 description: "The nickname of the account to delete from aliases"
357 def healthcheck_operation do
360 summary: "Quick status check on the instance",
361 security: [%{"oAuth" => ["write:accounts"]}],
362 operationId: "UtilController.healthcheck",
365 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
367 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
372 def remote_subscribe_operation do
375 summary: "Remote Subscribe",
376 operationId: "UtilController.remote_subscribe",
378 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
382 def remote_interaction_operation do
385 summary: "Remote interaction",
386 operationId: "UtilController.remote_interaction",
387 requestBody: request_body("Parameters", remote_interaction_request(), required: true),
390 Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
395 defp remote_interaction_request do
397 title: "RemoteInteractionRequest",
398 description: "POST body for remote interaction",
400 required: [:ap_id, :profile],
402 ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
403 profile: %Schema{type: :string, description: "Remote profile webfinger"}
408 def show_subscribe_form_operation do
411 summary: "Show remote subscribe form",
412 operationId: "UtilController.show_subscribe_form",
414 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
418 defp delete_account_request do
420 title: "AccountDeleteRequest",
421 description: "POST body for deleting one's own account",
426 description: "The user's own password for confirmation.",
431 "password" => "prettyp0ony1313"