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.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
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, [])
25 @spec create_operation() :: Operation.t()
26 def create_operation do
29 summary: "Register an account",
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),
35 200 => Operation.response("Account", "application/json", AccountCreateResponse)
40 def verify_credentials_operation do
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"]}],
48 200 => Operation.response("Account", "application/json", Account)
53 def update_credentials_operation do
56 summary: "Update account credentials",
57 description: "Update the user's display and preferences.",
58 operationId: "AccountController.update_credentials",
59 security: [%{"oAuth" => ["write:accounts"]}],
61 Helpers.request_body("Parameters", AccountUpdateCredentialsRequest, required: true),
63 200 => Operation.response("Account", "application/json", Account)
68 def relationships_operation do
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"]}],
80 oneOf: [%Schema{type: :array, items: %Schema{type: :string}}, %Schema{type: :string}]
87 200 => Operation.response("Account", "application/json", AccountRelationshipsResponse)
96 operationId: "AccountController.show",
97 description: "View information about a profile.",
98 parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
100 200 => Operation.response("Account", "application/json", Account)
105 def statuses_operation do
109 operationId: "AccountController.statuses",
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)",
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"),
120 :exclude_visibilities,
122 %Schema{type: :array, items: VisibilityScope},
123 "Exclude visibilities"
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"),
131 %Schema{type: :integer, default: 20, maximum: 40},
136 200 => Operation.response("Statuses", "application/json", StatusesResponse)
141 def followers_operation do
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