Merge branch 'develop' into 'remove-twitter-api'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_account_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaAccountOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.StatusOperation
12
13 import Pleroma.Web.ApiSpec.Helpers
14
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
18 end
19
20 def confirmation_resend_operation do
21 %Operation{
22 tags: ["Accounts"],
23 summary: "Resend confirmation email. Expects `email` or `nickname`",
24 operationId: "PleromaAPI.AccountController.confirmation_resend",
25 parameters: [
26 Operation.parameter(:email, :query, :string, "Email of that needs to be verified",
27 example: "cofe@cofe.io"
28 ),
29 Operation.parameter(
30 :nickname,
31 :query,
32 :string,
33 "Nickname of user that needs to be verified",
34 example: "cofefe"
35 )
36 ],
37 responses: %{
38 204 => no_content_response()
39 }
40 }
41 end
42
43 def update_avatar_operation do
44 %Operation{
45 tags: ["Accounts"],
46 summary: "Set/clear user avatar image",
47 operationId: "PleromaAPI.AccountController.update_avatar",
48 requestBody:
49 request_body("Parameters", update_avatar_or_background_request(), required: true),
50 security: [%{"oAuth" => ["write:accounts"]}],
51 responses: %{
52 200 => update_response(),
53 403 => Operation.response("Forbidden", "application/json", ApiError)
54 }
55 }
56 end
57
58 def update_banner_operation do
59 %Operation{
60 tags: ["Accounts"],
61 summary: "Set/clear user banner image",
62 operationId: "PleromaAPI.AccountController.update_banner",
63 requestBody: request_body("Parameters", update_banner_request(), required: true),
64 security: [%{"oAuth" => ["write:accounts"]}],
65 responses: %{
66 200 => update_response()
67 }
68 }
69 end
70
71 def update_background_operation do
72 %Operation{
73 tags: ["Accounts"],
74 summary: "Set/clear user background image",
75 operationId: "PleromaAPI.AccountController.update_background",
76 security: [%{"oAuth" => ["write:accounts"]}],
77 requestBody:
78 request_body("Parameters", update_avatar_or_background_request(), required: true),
79 responses: %{
80 200 => update_response()
81 }
82 }
83 end
84
85 def favourites_operation do
86 %Operation{
87 tags: ["Accounts"],
88 summary: "Returns favorites timeline of any user",
89 operationId: "PleromaAPI.AccountController.favourites",
90 parameters: [id_param() | pagination_params()],
91 security: [%{"oAuth" => ["read:favourites"]}],
92 responses: %{
93 200 =>
94 Operation.response(
95 "Array of Statuses",
96 "application/json",
97 StatusOperation.array_of_statuses()
98 ),
99 403 => Operation.response("Forbidden", "application/json", ApiError),
100 404 => Operation.response("Not Found", "application/json", ApiError)
101 }
102 }
103 end
104
105 def subscribe_operation do
106 %Operation{
107 tags: ["Accounts"],
108 summary: "Subscribe to receive notifications for all statuses posted by a user",
109 operationId: "PleromaAPI.AccountController.subscribe",
110 parameters: [id_param()],
111 security: [%{"oAuth" => ["follow", "write:follows"]}],
112 responses: %{
113 200 => Operation.response("Relationship", "application/json", AccountRelationship),
114 404 => Operation.response("Not Found", "application/json", ApiError)
115 }
116 }
117 end
118
119 def unsubscribe_operation do
120 %Operation{
121 tags: ["Accounts"],
122 summary: "Unsubscribe to stop receiving notifications from user statuses",
123 operationId: "PleromaAPI.AccountController.unsubscribe",
124 parameters: [id_param()],
125 security: [%{"oAuth" => ["follow", "write:follows"]}],
126 responses: %{
127 200 => Operation.response("Relationship", "application/json", AccountRelationship),
128 404 => Operation.response("Not Found", "application/json", ApiError)
129 }
130 }
131 end
132
133 defp id_param do
134 Operation.parameter(:id, :path, FlakeID, "Account ID",
135 example: "9umDrYheeY451cQnEe",
136 required: true
137 )
138 end
139
140 defp update_avatar_or_background_request do
141 %Schema{
142 title: "PleromaAccountUpdateAvatarOrBackgroundRequest",
143 type: :object,
144 properties: %{
145 img: %Schema{
146 nullable: true,
147 type: :string,
148 format: :binary,
149 description: "Image encoded using `multipart/form-data` or an empty string to clear"
150 }
151 }
152 }
153 end
154
155 defp update_banner_request do
156 %Schema{
157 title: "PleromaAccountUpdateBannerRequest",
158 type: :object,
159 properties: %{
160 banner: %Schema{
161 type: :string,
162 nullable: true,
163 format: :binary,
164 description: "Image encoded using `multipart/form-data` or an empty string to clear"
165 }
166 }
167 }
168 end
169
170 defp update_response do
171 Operation.response("PleromaAccountUpdateResponse", "application/json", %Schema{
172 type: :object,
173 properties: %{
174 url: %Schema{
175 type: :string,
176 format: :uri,
177 nullable: true,
178 description: "Image URL"
179 }
180 },
181 example: %{
182 "url" =>
183 "https://cofe.party/media/9d0add56-bcb6-4c0f-8225-cbbd0b6dd773/13eadb6972c9ccd3f4ffa3b8196f0e0d38b4d2f27594457c52e52946c054cd9a.gif"
184 }
185 })
186 end
187 end