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