352f66e9d163f7921fc24025dbb46cc405ab3c0e
[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.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateRequest
11 alias Pleroma.Web.ApiSpec.Schemas.AccountCreateResponse
12 alias Pleroma.Web.ApiSpec.Schemas.AccountRelationshipsResponse
13 alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
14
15 @spec open_api_operation(atom) :: Operation.t()
16 def open_api_operation(action) do
17 operation = String.to_existing_atom("#{action}_operation")
18 apply(__MODULE__, operation, [])
19 end
20
21 @spec create_operation() :: Operation.t()
22 def create_operation do
23 %Operation{
24 tags: ["accounts"],
25 summary: "Register an account",
26 description:
27 "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.",
28 operationId: "AccountController.create",
29 requestBody: Helpers.request_body("Parameters", AccountCreateRequest, required: true),
30 responses: %{
31 200 => Operation.response("Account", "application/json", AccountCreateResponse)
32 }
33 }
34 end
35
36 def verify_credentials_operation do
37 %Operation{
38 tags: ["accounts"],
39 description: "Test to make sure that the user token works.",
40 summary: "Verify account credentials",
41 operationId: "AccountController.verify_credentials",
42 security: [%{"oAuth" => ["read:accounts"]}],
43 responses: %{
44 200 => Operation.response("Account", "application/json", Account)
45 }
46 }
47 end
48
49 def update_credentials_operation do
50 %Operation{
51 tags: ["accounts"],
52 summary: "Update account credentials",
53 description: "Update the user's display and preferences.",
54 operationId: "AccountController.update_credentials",
55 security: [%{"oAuth" => ["write:accounts"]}],
56 requestBody:
57 Helpers.request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
58 responses: %{
59 200 => Operation.response("Account", "application/json", Account)
60 }
61 }
62 end
63
64 def relationships_operation do
65 %Operation{
66 tags: ["accounts"],
67 summary: "Check relationships to other accounts",
68 operationId: "AccountController.relationships",
69 description: "Find out whether a given account is followed, blocked, muted, etc.",
70 security: [%{"oAuth" => ["read:follows"]}],
71 parameters: [
72 Operation.parameter(
73 :id,
74 :query,
75 %Schema{
76 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
77 },
78 "Account IDs",
79 example: "123"
80 )
81 ],
82 responses: %{
83 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
84 }
85 }
86 end
87
88 def show_operation do
89 :ok
90 end
91
92 def statuses_operation do
93 :ok
94 end
95
96 def followers_operation do
97 :ok
98 end
99
100 def following_operation, do: :ok
101 def lists_operation, do: :ok
102 def follow_operation, do: :ok
103 def unfollow_operation, do: :ok
104 def mute_operation, do: :ok
105 def unmute_operation, do: :ok
106 def block_operation, do: :ok
107 def unblock_operation, do: :ok
108 def follows_operation, do: :ok
109 def mutes_operation, do: :ok
110 def blocks_operation, do: :ok
111 def endorsements_operation, do: :ok
112 end