ChatMessage schema: Add `unread` property
[akkoma] / lib / pleroma / web / api_spec / operations / admin / relay_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Admin.RelayOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8
9 import Pleroma.Web.ApiSpec.Helpers
10
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
14 end
15
16 def index_operation do
17 %Operation{
18 tags: ["Relays"],
19 summary: "Retrieve a list of relays",
20 operationId: "AdminAPI.RelayController.index",
21 security: [%{"oAuth" => ["read"]}],
22 parameters: admin_api_params(),
23 responses: %{
24 200 =>
25 Operation.response("Response", "application/json", %Schema{
26 type: :object,
27 properties: %{
28 relays: %Schema{
29 type: :array,
30 items: relay()
31 }
32 }
33 })
34 }
35 }
36 end
37
38 def follow_operation do
39 %Operation{
40 tags: ["Relays"],
41 summary: "Follow a relay",
42 operationId: "AdminAPI.RelayController.follow",
43 security: [%{"oAuth" => ["write:follows"]}],
44 parameters: admin_api_params(),
45 requestBody: request_body("Parameters", relay_url()),
46 responses: %{
47 200 => Operation.response("Status", "application/json", relay())
48 }
49 }
50 end
51
52 def unfollow_operation do
53 %Operation{
54 tags: ["Relays"],
55 summary: "Unfollow a relay",
56 operationId: "AdminAPI.RelayController.unfollow",
57 security: [%{"oAuth" => ["write:follows"]}],
58 parameters: admin_api_params(),
59 requestBody: request_body("Parameters", relay_unfollow()),
60 responses: %{
61 200 =>
62 Operation.response("Status", "application/json", %Schema{
63 type: :string,
64 example: "http://mastodon.example.org/users/admin"
65 })
66 }
67 }
68 end
69
70 defp relay do
71 %Schema{
72 type: :object,
73 properties: %{
74 actor: %Schema{
75 type: :string,
76 example: "https://example.com/relay"
77 },
78 followed_back: %Schema{
79 type: :boolean,
80 description: "Is relay followed back by this actor?"
81 }
82 }
83 }
84 end
85
86 defp relay_url do
87 %Schema{
88 type: :object,
89 properties: %{
90 relay_url: %Schema{type: :string, format: :uri}
91 }
92 }
93 end
94
95 defp relay_unfollow do
96 %Schema{
97 type: :object,
98 properties: %{
99 relay_url: %Schema{type: :string, format: :uri},
100 force: %Schema{type: :boolean, default: false}
101 }
102 }
103 end
104 end