Add spec for AccountController.followers
[akkoma] / lib / pleroma / web / api_spec / operations / 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.AccountOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Reference
8 alias OpenApiSpex.Schema
9 alias Pleroma.Web.ApiSpec.Helpers
10 alias Pleroma.Web.ApiSpec.Schemas.Account
11 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
12 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
13 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
14 alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
15 alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
16 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
17 alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
18 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
19
20 @spec open_api_operation(atom) :: Operation.t()
21 def open_api_operation(action) do
22 operation = String.to_existing_atom("#{action}_operation")
23 apply(__MODULE__, operation, [])
24 end
25
26 @spec create_operation() :: Operation.t()
27 def create_operation do
28 %Operation{
29 tags: ["accounts"],
30 summary: "Register an account",
31 description:
32 "Creates a user and account records. Returns an account access token for the app that initiated the request. The app should save this token for later, and should wait for the user to confirm their account by clicking a link in their email inbox.",
33 operationId: "AccountController.create",
34 requestBody: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
35 responses: %{
36 200 => Operation.response("Account", "application/json", AccountCreateResponse)
37 }
38 }
39 end
40
41 def verify_credentials_operation do
42 %Operation{
43 tags: ["accounts"],
44 description: "Test to make sure that the user token works.",
45 summary: "Verify account credentials",
46 operationId: "AccountController.verify_credentials",
47 security: [%{"oAuth" => ["read:accounts"]}],
48 responses: %{
49 200 => Operation.response("Account", "application/json", Account)
50 }
51 }
52 end
53
54 def update_credentials_operation do
55 %Operation{
56 tags: ["accounts"],
57 summary: "Update account credentials",
58 description: "Update the user's display and preferences.",
59 operationId: "AccountController.update_credentials",
60 security: [%{"oAuth" => ["write:accounts"]}],
61 requestBody:
62 Helpers.request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
63 responses: %{
64 200 => Operation.response("Account", "application/json", Account)
65 }
66 }
67 end
68
69 def relationships_operation do
70 %Operation{
71 tags: ["accounts"],
72 summary: "Check relationships to other accounts",
73 operationId: "AccountController.relationships",
74 description: "Find out whether a given account is followed, blocked, muted, etc.",
75 security: [%{"oAuth" => ["read:follows"]}],
76 parameters: [
77 Operation.parameter(
78 :id,
79 :query,
80 %Schema{
81 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
82 },
83 "Account IDs",
84 example: "123"
85 )
86 ],
87 responses: %{
88 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
89 }
90 }
91 end
92
93 def show_operation do
94 %Operation{
95 tags: ["accounts"],
96 summary: "Account",
97 operationId: "AccountController.show",
98 description: "View information about a profile.",
99 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
100 responses: %{
101 200 => Operation.response("Account", "application/json", Account)
102 }
103 }
104 end
105
106 def statuses_operation do
107 %Operation{
108 tags: ["accounts"],
109 summary: "Statuses",
110 operationId: "AccountController.statuses",
111 description:
112 "Statuses posted to the given account. Public (for public statuses only), or user token + `read:statuses` (for private statuses the user is authorized to see)",
113 parameters: [
114 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
115 Operation.parameter(:pinned, :query, BooleanLike, "Pinned"),
116 Operation.parameter(:tagged, :query, :string, "With tag"),
117 Operation.parameter(:only_media, :query, BooleanLike, "Only meadia"),
118 Operation.parameter(:with_muted, :query, BooleanLike, "With muted"),
119 Operation.parameter(:exclude_reblogs, :query, BooleanLike, "Exclude reblobs"),
120 Operation.parameter(
121 :exclude_visibilities,
122 :query,
123 %Schema{type: :array, items: VisibilityScope},
124 "Exclude visibilities"
125 ),
126 Operation.parameter(:max_id, :query, :string, "Max ID"),
127 Operation.parameter(:min_id, :query, :string, "Mix ID"),
128 Operation.parameter(:since_id, :query, :string, "Since ID"),
129 Operation.parameter(
130 :limit,
131 :query,
132 %Schema{type: :integer, default: 20, maximum: 40},
133 "Limit"
134 )
135 ],
136 responses: %{
137 200 => Operation.response("Statuses", "application/json", StatusesResponse)
138 }
139 }
140 end
141
142 def followers_operation do
143 %Operation{
144 tags: ["accounts"],
145 summary: "Followers",
146 operationId: "AccountController.followers",
147 security: [%{"oAuth" => ["read:accounts"]}],
148 description:
149 "Accounts which follow the given account, if network is not hidden by the account owner.",
150 parameters: [
151 %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
152 Operation.parameter(:max_id, :query, :string, "Max ID"),
153 Operation.parameter(:since_id, :query, :string, "Since ID"),
154 Operation.parameter(:limit, :query, :integer, "Limit")
155 ],
156 responses: %{
157 200 => Operation.response("Accounts", "application/json", AccountsResponse)
158 }
159 }
160 end
161
162 def following_operation, do: :ok
163 def lists_operation, do: :ok
164 def follow_operation, do: :ok
165 def unfollow_operation, do: :ok
166 def mute_operation, do: :ok
167 def unmute_operation, do: :ok
168 def block_operation, do: :ok
169 def unblock_operation, do: :ok
170 def follows_operation, do: :ok
171 def mutes_operation, do: :ok
172 def blocks_operation, do: :ok
173 def endorsements_operation, do: :ok
174 end