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
20 tags: ["Custom emojis"],
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}}
34 extensions: %{"x-additionalPropertiesName": "Emoji name"}
38 "image_url" => "/emoji/firefox.png",
47 def frontend_configurations_operation do
50 summary: "Dump frontend configurations",
51 operationId: "UtilController.frontend_configurations",
55 Operation.response("List", "application/json", %Schema{
57 additionalProperties: %Schema{
60 "Opaque object representing the instance-wide configuration for the frontend",
61 extensions: %{"x-additionalPropertiesName": "Frontend name"}
68 def change_password_operation do
70 tags: ["Account credentials"],
71 summary: "Change account password",
72 security: [%{"oAuth" => ["write:accounts"]}],
73 operationId: "UtilController.change_password",
74 requestBody: request_body("Parameters", change_password_request(), required: true),
77 Operation.response("Success", "application/json", %Schema{
79 properties: %{status: %Schema{type: :string, example: "success"}}
81 400 => Operation.response("Error", "application/json", ApiError),
82 403 => Operation.response("Error", "application/json", ApiError)
87 defp change_password_request do
89 title: "ChangePasswordRequest",
90 description: "POST body for changing the account's password",
92 required: [:password, :new_password, :new_password_confirmation],
94 password: %Schema{type: :string, description: "Current password"},
95 new_password: %Schema{type: :string, description: "New password"},
96 new_password_confirmation: %Schema{
98 description: "New password, confirmation"
104 def change_email_operation do
106 tags: ["Account credentials"],
107 summary: "Change account email",
108 security: [%{"oAuth" => ["write:accounts"]}],
109 operationId: "UtilController.change_email",
110 requestBody: request_body("Parameters", change_email_request(), required: true),
113 Operation.response("Success", "application/json", %Schema{
115 properties: %{status: %Schema{type: :string, example: "success"}}
117 400 => Operation.response("Error", "application/json", ApiError),
118 403 => Operation.response("Error", "application/json", ApiError)
123 defp change_email_request do
125 title: "ChangeEmailRequest",
126 description: "POST body for changing the account's email",
128 required: [:email, :password],
132 description: "New email. Set to blank to remove the user's email."
134 password: %Schema{type: :string, description: "Current password"}
139 def update_notification_settings_operation do
142 summary: "Update Notification Settings",
143 security: [%{"oAuth" => ["write:accounts"]}],
144 operationId: "UtilController.update_notification_settings",
147 :block_from_strangers,
149 BooleanLike.schema(),
150 "blocks notifications from accounts you do not follow"
153 :hide_notification_contents,
155 BooleanLike.schema(),
156 "removes the contents of a message from the push notification"
162 Operation.response("Success", "application/json", %Schema{
164 properties: %{status: %Schema{type: :string, example: "success"}}
166 400 => Operation.response("Error", "application/json", ApiError)
171 def disable_account_operation do
173 tags: ["Account credentials"],
174 summary: "Disable Account",
175 security: [%{"oAuth" => ["write:accounts"]}],
176 operationId: "UtilController.disable_account",
178 Operation.parameter(:password, :query, :string, "Password")
182 Operation.response("Success", "application/json", %Schema{
184 properties: %{status: %Schema{type: :string, example: "success"}}
186 403 => Operation.response("Error", "application/json", ApiError)
191 def delete_account_operation do
193 tags: ["Account credentials"],
194 summary: "Delete Account",
195 security: [%{"oAuth" => ["write:accounts"]}],
196 operationId: "UtilController.delete_account",
198 Operation.parameter(:password, :query, :string, "Password")
200 requestBody: request_body("Parameters", delete_account_request(), required: false),
203 Operation.response("Success", "application/json", %Schema{
205 properties: %{status: %Schema{type: :string, example: "success"}}
207 403 => Operation.response("Error", "application/json", ApiError)
212 def captcha_operation do
214 summary: "Get a captcha",
215 operationId: "UtilController.captcha",
219 200 => Operation.response("Success", "application/json", %Schema{type: :object})
224 def move_account_operation do
226 tags: ["Account credentials"],
227 summary: "Move account",
228 security: [%{"oAuth" => ["write:accounts"]}],
229 operationId: "UtilController.move_account",
230 requestBody: request_body("Parameters", move_account_request(), required: true),
233 Operation.response("Success", "application/json", %Schema{
235 properties: %{status: %Schema{type: :string, example: "success"}}
237 400 => Operation.response("Error", "application/json", ApiError),
238 403 => Operation.response("Error", "application/json", ApiError),
239 404 => Operation.response("Error", "application/json", ApiError)
244 defp move_account_request do
246 title: "MoveAccountRequest",
247 description: "POST body for moving the account",
249 required: [:password, :target_account],
251 password: %Schema{type: :string, description: "Current password"},
252 target_account: %Schema{
254 description: "The nickname of the target account to move to"
260 def list_aliases_operation do
262 tags: ["Account credentials"],
263 summary: "List account aliases",
264 security: [%{"oAuth" => ["read:accounts"]}],
265 operationId: "UtilController.list_aliases",
268 Operation.response("Success", "application/json", %Schema{
273 items: %Schema{type: :string},
274 example: ["foo@example.org"]
278 400 => Operation.response("Error", "application/json", ApiError),
279 403 => Operation.response("Error", "application/json", ApiError)
284 def add_alias_operation do
286 tags: ["Account credentials"],
287 summary: "Add an alias to this account",
288 security: [%{"oAuth" => ["write:accounts"]}],
289 operationId: "UtilController.add_alias",
290 requestBody: request_body("Parameters", add_alias_request(), required: true),
293 Operation.response("Success", "application/json", %Schema{
302 400 => Operation.response("Error", "application/json", ApiError),
303 403 => Operation.response("Error", "application/json", ApiError),
304 404 => Operation.response("Error", "application/json", ApiError)
309 defp add_alias_request do
311 title: "AddAliasRequest",
312 description: "PUT body for adding aliases",
318 description: "The nickname of the account to add to aliases"
324 def delete_alias_operation do
326 tags: ["Account credentials"],
327 summary: "Delete an alias from this account",
328 security: [%{"oAuth" => ["write:accounts"]}],
329 operationId: "UtilController.delete_alias",
330 requestBody: request_body("Parameters", delete_alias_request(), required: true),
333 Operation.response("Success", "application/json", %Schema{
342 400 => Operation.response("Error", "application/json", ApiError),
343 403 => Operation.response("Error", "application/json", ApiError),
344 404 => Operation.response("Error", "application/json", ApiError)
349 defp delete_alias_request do
351 title: "DeleteAliasRequest",
352 description: "PUT body for deleting aliases",
358 description: "The nickname of the account to delete from aliases"
364 def healthcheck_operation do
367 summary: "Quick status check on the instance",
368 security: [%{"oAuth" => ["write:accounts"]}],
369 operationId: "UtilController.healthcheck",
372 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
374 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
379 def remote_subscribe_operation do
381 tags: ["Remote interaction"],
382 summary: "Remote Subscribe",
383 operationId: "UtilController.remote_subscribe",
385 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
389 def remote_interaction_operation do
391 tags: ["Remote interaction"],
392 summary: "Remote interaction",
393 operationId: "UtilController.remote_interaction",
394 requestBody: request_body("Parameters", remote_interaction_request(), required: true),
397 Operation.response("Remote interaction URL", "application/json", %Schema{type: :object})
402 defp remote_interaction_request do
404 title: "RemoteInteractionRequest",
405 description: "POST body for remote interaction",
407 required: [:ap_id, :profile],
409 ap_id: %Schema{type: :string, description: "Profile or status ActivityPub ID"},
410 profile: %Schema{type: :string, description: "Remote profile webfinger"}
415 def show_subscribe_form_operation do
417 tags: ["Remote interaction"],
418 summary: "Show remote subscribe form",
419 operationId: "UtilController.show_subscribe_form",
421 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
425 defp delete_account_request do
427 title: "AccountDeleteRequest",
428 description: "POST body for deleting one's own account",
433 description: "The user's own password for confirmation.",
438 "password" => "prettyp0ony1313"