0cafbc719cf8a6b9d9e0975233ce7fc1596d9ffe
[akkoma] / lib / pleroma / web / api_spec / operations / twitter_util_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
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
10
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
14 end
15
16 def emoji_operation do
17 %Operation{
18 tags: ["Emojis"],
19 summary: "List all custom emojis",
20 operationId: "UtilController.emoji",
21 parameters: [],
22 responses: %{
23 200 =>
24 Operation.response("List", "application/json", %Schema{
25 type: :object,
26 additionalProperties: %Schema{
27 type: :object,
28 properties: %{
29 image_url: %Schema{type: :string},
30 tags: %Schema{type: :array, items: %Schema{type: :string}}
31 }
32 },
33 example: %{
34 "firefox" => %{
35 "image_url" => "/emoji/firefox.png",
36 "tag" => ["Fun"]
37 }
38 }
39 })
40 }
41 }
42 end
43
44 def frontend_configurations_operation do
45 %Operation{
46 tags: ["Configuration"],
47 summary: "Dump frontend configurations",
48 operationId: "UtilController.frontend_configurations",
49 parameters: [],
50 responses: %{
51 200 =>
52 Operation.response("List", "application/json", %Schema{
53 type: :object,
54 additionalProperties: %Schema{type: :object}
55 })
56 }
57 }
58 end
59
60 def change_password_operation do
61 %Operation{
62 tags: ["Account credentials"],
63 summary: "Change account password",
64 security: [%{"oAuth" => ["write:accounts"]}],
65 operationId: "UtilController.change_password",
66 parameters: [
67 Operation.parameter(:password, :query, :string, "Current password", required: true),
68 Operation.parameter(:new_password, :query, :string, "New password", required: true),
69 Operation.parameter(
70 :new_password_confirmation,
71 :query,
72 :string,
73 "New password, confirmation",
74 required: true
75 )
76 ],
77 responses: %{
78 200 =>
79 Operation.response("Success", "application/json", %Schema{
80 type: :object,
81 properties: %{status: %Schema{type: :string, example: "success"}}
82 }),
83 400 => Operation.response("Error", "application/json", ApiError),
84 403 => Operation.response("Error", "application/json", ApiError)
85 }
86 }
87 end
88
89 def change_email_operation do
90 %Operation{
91 tags: ["Account credentials"],
92 summary: "Change account email",
93 security: [%{"oAuth" => ["write:accounts"]}],
94 operationId: "UtilController.change_email",
95 parameters: [
96 Operation.parameter(:password, :query, :string, "Current password", required: true),
97 Operation.parameter(:email, :query, :string, "New email", required: true)
98 ],
99 requestBody: nil,
100 responses: %{
101 200 =>
102 Operation.response("Success", "application/json", %Schema{
103 type: :object,
104 properties: %{status: %Schema{type: :string, example: "success"}}
105 }),
106 400 => Operation.response("Error", "application/json", ApiError),
107 403 => Operation.response("Error", "application/json", ApiError)
108 }
109 }
110 end
111
112 def update_notificaton_settings_operation do
113 %Operation{
114 tags: ["Accounts"],
115 summary: "Update Notification Settings",
116 security: [%{"oAuth" => ["write:accounts"]}],
117 operationId: "UtilController.update_notificaton_settings",
118 parameters: [
119 Operation.parameter(
120 :block_from_strangers,
121 :query,
122 BooleanLike,
123 "blocks notifications from accounts you do not follow"
124 ),
125 Operation.parameter(
126 :hide_notification_contents,
127 :query,
128 BooleanLike,
129 "removes the contents of a message from the push notification"
130 )
131 ],
132 requestBody: nil,
133 responses: %{
134 200 =>
135 Operation.response("Success", "application/json", %Schema{
136 type: :object,
137 properties: %{status: %Schema{type: :string, example: "success"}}
138 }),
139 400 => Operation.response("Error", "application/json", ApiError)
140 }
141 }
142 end
143
144 def disable_account_operation do
145 %Operation{
146 tags: ["Account credentials"],
147 summary: "Disable Account",
148 security: [%{"oAuth" => ["write:accounts"]}],
149 operationId: "UtilController.disable_account",
150 parameters: [
151 Operation.parameter(:password, :query, :string, "Password")
152 ],
153 responses: %{
154 200 =>
155 Operation.response("Success", "application/json", %Schema{
156 type: :object,
157 properties: %{status: %Schema{type: :string, example: "success"}}
158 }),
159 403 => Operation.response("Error", "application/json", ApiError)
160 }
161 }
162 end
163
164 def delete_account_operation do
165 %Operation{
166 tags: ["Account credentials"],
167 summary: "Delete Account",
168 security: [%{"oAuth" => ["write:accounts"]}],
169 operationId: "UtilController.delete_account",
170 parameters: [
171 Operation.parameter(:password, :query, :string, "Password")
172 ],
173 responses: %{
174 200 =>
175 Operation.response("Success", "application/json", %Schema{
176 type: :object,
177 properties: %{status: %Schema{type: :string, example: "success"}}
178 }),
179 403 => Operation.response("Error", "application/json", ApiError)
180 }
181 }
182 end
183
184 def captcha_operation do
185 %Operation{
186 summary: "Get a captcha",
187 operationId: "UtilController.captcha",
188 parameters: [],
189 responses: %{
190 200 => Operation.response("Success", "application/json", %Schema{type: :object})
191 }
192 }
193 end
194
195 def healthcheck_operation do
196 %Operation{
197 tags: ["Accounts"],
198 summary: "Quick status check on the instance",
199 security: [%{"oAuth" => ["write:accounts"]}],
200 operationId: "UtilController.healthcheck",
201 parameters: [],
202 responses: %{
203 200 => Operation.response("Healthy", "application/json", %Schema{type: :object}),
204 503 =>
205 Operation.response("Disabled or Unhealthy", "application/json", %Schema{type: :object})
206 }
207 }
208 end
209
210 def remote_subscribe_operation do
211 %Operation{
212 tags: ["Accounts"],
213 summary: "Remote Subscribe",
214 operationId: "UtilController.remote_subscribe",
215 parameters: [],
216 responses: %{200 => Operation.response("Web Page", "test/html", %Schema{type: :string})}
217 }
218 end
219 end