5b1b2eb4c5e37cd05a96e6e0967712ff4521a08e
[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 %Operation{
90 tags: ["accounts"],
91 summary: "Account",
92 operationId: "AccountController.show",
93 description: "View information about a profile.",
94 parameters: [
95 Operation.parameter(:id, :path, :string, "Account ID or nickname",
96 example: "123",
97 required: true
98 )
99 ],
100 responses: %{
101 200 => Operation.response("Account", "application/json", Account)
102 }
103 }
104 end
105
106 def statuses_operation do
107 :ok
108 end
109
110 def followers_operation do
111 :ok
112 end
113
114 def following_operation, do: :ok
115 def lists_operation, do: :ok
116 def follow_operation, do: :ok
117 def unfollow_operation, do: :ok
118 def mute_operation, do: :ok
119 def unmute_operation, do: :ok
120 def block_operation, do: :ok
121 def unblock_operation, do: :ok
122 def follows_operation, do: :ok
123 def mutes_operation, do: :ok
124 def blocks_operation, do: :ok
125 def endorsements_operation, do: :ok
126 end