1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
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
13 import Pleroma.Web.ApiSpec.Helpers
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
20 def confirmation_resend_operation do
23 summary: "Resend confirmation email. Expects `email` or `nickname`",
24 operationId: "PleromaAPI.AccountController.confirmation_resend",
26 Operation.parameter(:email, :query, :string, "Email of that needs to be verified",
27 example: "cofe@cofe.io"
33 "Nickname of user that needs to be verified",
38 204 => no_content_response()
43 def update_avatar_operation do
46 summary: "Set/clear user avatar image",
47 operationId: "PleromaAPI.AccountController.update_avatar",
49 request_body("Parameters", update_avatar_or_background_request(), required: true),
50 security: [%{"oAuth" => ["write:accounts"]}],
52 200 => update_response(),
53 403 => Operation.response("Forbidden", "application/json", ApiError)
58 def update_banner_operation do
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"]}],
66 200 => update_response()
71 def update_background_operation do
74 summary: "Set/clear user background image",
75 operationId: "PleromaAPI.AccountController.update_background",
76 security: [%{"oAuth" => ["write:accounts"]}],
78 request_body("Parameters", update_avatar_or_background_request(), required: true),
80 200 => update_response()
85 def favourites_operation do
88 summary: "Returns favorites timeline of any user",
89 operationId: "PleromaAPI.AccountController.favourites",
90 parameters: [id_param() | pagination_params()],
91 security: [%{"oAuth" => ["read:favourites"]}],
97 StatusOperation.array_of_statuses()
99 403 => Operation.response("Forbidden", "application/json", ApiError),
100 404 => Operation.response("Not Found", "application/json", ApiError)
105 def subscribe_operation do
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"]}],
113 200 => Operation.response("Relationship", "application/json", AccountRelationship),
114 404 => Operation.response("Not Found", "application/json", ApiError)
119 def unsubscribe_operation do
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"]}],
127 200 => Operation.response("Relationship", "application/json", AccountRelationship),
128 404 => Operation.response("Not Found", "application/json", ApiError)
134 Operation.parameter(:id, :path, FlakeID, "Account ID",
135 example: "9umDrYheeY451cQnEe",
140 defp update_avatar_or_background_request do
142 title: "PleromaAccountUpdateAvatarOrBackgroundRequest",
149 description: "Image encoded using `multipart/form-data` or an empty string to clear"
155 defp update_banner_request do
157 title: "PleromaAccountUpdateBannerRequest",
164 description: "Image encoded using `multipart/form-data` or an empty string to clear"
170 defp update_response do
171 Operation.response("PleromaAccountUpdateResponse", "application/json", %Schema{
178 description: "Image URL"
183 "https://cofe.party/media/9d0add56-bcb6-4c0f-8225-cbbd0b6dd773/13eadb6972c9ccd3f4ffa3b8196f0e0d38b4d2f27594457c52e52946c054cd9a.gif"