Merge branch 'issue/2068' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / instance_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.InstanceOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8
9 def open_api_operation(action) do
10 operation = String.to_existing_atom("#{action}_operation")
11 apply(__MODULE__, operation, [])
12 end
13
14 def show_operation do
15 %Operation{
16 tags: ["Instance"],
17 summary: "Fetch instance",
18 description: "Information about the server",
19 operationId: "InstanceController.show",
20 responses: %{
21 200 => Operation.response("Instance", "application/json", instance())
22 }
23 }
24 end
25
26 def peers_operation do
27 %Operation{
28 tags: ["Instance"],
29 summary: "List of known hosts",
30 operationId: "InstanceController.peers",
31 responses: %{
32 200 => Operation.response("Array of domains", "application/json", array_of_domains())
33 }
34 }
35 end
36
37 defp instance do
38 %Schema{
39 type: :object,
40 properties: %{
41 uri: %Schema{type: :string, description: "The domain name of the instance"},
42 title: %Schema{type: :string, description: "The title of the website"},
43 description: %Schema{
44 type: :string,
45 description: "Admin-defined description of the Pleroma site"
46 },
47 version: %Schema{
48 type: :string,
49 description: "The version of Pleroma installed on the instance"
50 },
51 email: %Schema{
52 type: :string,
53 description: "An email that may be contacted for any inquiries",
54 format: :email
55 },
56 urls: %Schema{
57 type: :object,
58 description: "URLs of interest for clients apps",
59 properties: %{
60 streaming_api: %Schema{
61 type: :string,
62 description: "Websockets address for push streaming"
63 }
64 }
65 },
66 stats: %Schema{
67 type: :object,
68 description: "Statistics about how much information the instance contains",
69 properties: %{
70 user_count: %Schema{
71 type: :integer,
72 description: "Users registered on this instance"
73 },
74 status_count: %Schema{
75 type: :integer,
76 description: "Statuses authored by users on instance"
77 },
78 domain_count: %Schema{
79 type: :integer,
80 description: "Domains federated with this instance"
81 }
82 }
83 },
84 thumbnail: %Schema{
85 type: :string,
86 description: "Banner image for the website",
87 nullable: true
88 },
89 languages: %Schema{
90 type: :array,
91 items: %Schema{type: :string},
92 description: "Primary langauges of the website and its staff"
93 },
94 registrations: %Schema{type: :boolean, description: "Whether registrations are enabled"},
95 # Extra (not present in Mastodon):
96 max_toot_chars: %Schema{
97 type: :integer,
98 description: ": Posts character limit (CW/Subject included in the counter)"
99 },
100 poll_limits: %Schema{
101 type: :object,
102 description: "A map with poll limits for local polls",
103 properties: %{
104 max_options: %Schema{
105 type: :integer,
106 description: "Maximum number of options."
107 },
108 max_option_chars: %Schema{
109 type: :integer,
110 description: "Maximum number of characters per option."
111 },
112 min_expiration: %Schema{
113 type: :integer,
114 description: "Minimum expiration time (in seconds)."
115 },
116 max_expiration: %Schema{
117 type: :integer,
118 description: "Maximum expiration time (in seconds)."
119 }
120 }
121 },
122 upload_limit: %Schema{
123 type: :integer,
124 description: "File size limit of uploads (except for avatar, background, banner)"
125 },
126 avatar_upload_limit: %Schema{type: :integer, description: "The title of the website"},
127 background_upload_limit: %Schema{type: :integer, description: "The title of the website"},
128 banner_upload_limit: %Schema{type: :integer, description: "The title of the website"},
129 background_image: %Schema{
130 type: :string,
131 format: :uri,
132 description: "The background image for the website"
133 }
134 },
135 example: %{
136 "avatar_upload_limit" => 2_000_000,
137 "background_upload_limit" => 4_000_000,
138 "background_image" => "/static/image.png",
139 "banner_upload_limit" => 4_000_000,
140 "description" => "Pleroma: An efficient and flexible fediverse server",
141 "email" => "lain@lain.com",
142 "languages" => ["en"],
143 "max_toot_chars" => 5000,
144 "poll_limits" => %{
145 "max_expiration" => 31_536_000,
146 "max_option_chars" => 200,
147 "max_options" => 20,
148 "min_expiration" => 0
149 },
150 "registrations" => false,
151 "stats" => %{
152 "domain_count" => 2996,
153 "status_count" => 15_802,
154 "user_count" => 5
155 },
156 "thumbnail" => "https://lain.com/instance/thumbnail.jpeg",
157 "title" => "lain.com",
158 "upload_limit" => 16_000_000,
159 "uri" => "https://lain.com",
160 "urls" => %{
161 "streaming_api" => "wss://lain.com"
162 },
163 "version" => "2.7.2 (compatible; Pleroma 2.0.50-536-g25eec6d7-develop)"
164 }
165 }
166 end
167
168 defp array_of_domains do
169 %Schema{
170 type: :array,
171 items: %Schema{type: :string},
172 example: ["pleroma.site", "lain.com", "bikeshed.party"]
173 }
174 end
175 end