1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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",
105 Operation.parameter(:password, :query, :string, "Current password", required: true),
106 Operation.parameter(:email, :query, :string, "New email", required: true)
111 Operation.response("Success", "application/json", %Schema{
113 properties: %{status: %Schema{type: :string, example: "success"}}
115 400 => Operation.response("Error", "application/json", ApiError),
116 403 => Operation.response("Error", "application/json", ApiError)
121 def update_notificaton_settings_operation do
124 summary: "Update Notification Settings",
125 security: [%{"oAuth" => ["write:accounts"]}],
126 operationId: "UtilController.update_notificaton_settings",
129 :block_from_strangers,
132 "blocks notifications from accounts you do not follow"
135 :hide_notification_contents,
138 "removes the contents of a message from the push notification"
144 Operation.response("Success", "application/json", %Schema{
146 properties: %{status: %Schema{type: :string, example: "success"}}
148 400 => Operation.response("Error", "application/json", ApiError)
153 def disable_account_operation do
155 tags: ["Account credentials"],
156 summary: "Disable Account",
157 security: [%{"oAuth" => ["write:accounts"]}],
158 operationId: "UtilController.disable_account",
160 Operation.parameter(:password, :query, :string, "Password")
164 Operation.response("Success", "application/json", %Schema{
166 properties: %{status: %Schema{type: :string, example: "success"}}
168 403 => Operation.response("Error", "application/json", ApiError)
173 def delete_account_operation do
175 tags: ["Account credentials"],
176 summary: "Delete Account",
177 security: [%{"oAuth" => ["write:accounts"]}],
178 operationId: "UtilController.delete_account",
180 Operation.parameter(:password, :query, :string, "Password")
184 Operation.response("Success", "application/json", %Schema{
186 properties: %{status: %Schema{type: :string, example: "success"}}
188 403 => Operation.response("Error", "application/json", ApiError)
193 def captcha_operation do
195 summary: "Get a captcha",
196 operationId: "UtilController.captcha",
199 200 => Operation.response("Success", "application/json", %Schema{type: :object})
204 def healthcheck_operation do
207 summary: "Quick status check on the instance",
208 security: [%{"oAuth" => ["write:accounts"]}],
209 operationId: "UtilController.healthcheck",
212 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
214 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
219 def remote_subscribe_operation do
222 summary: "Remote Subscribe",
223 operationId: "UtilController.remote_subscribe",
225 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}