1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 import Pleroma.Web.ApiSpec.Helpers
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def remote_operation do
19 tags: ["Emoji pack administration"],
20 summary: "Make request to another instance for emoji packs list",
21 security: [%{"oAuth" => ["admin:write"]}],
27 %Schema{type: :integer, default: 1},
33 %Schema{type: :integer, default: 30},
34 "Number of emoji to return"
37 operationId: "PleromaAPI.EmojiPackController.remote",
39 200 => emoji_packs_response(),
40 500 => Operation.response("Error", "application/json", ApiError)
45 def index_operation do
47 tags: ["Emoji packs"],
48 summary: "Lists local custom emoji packs",
49 operationId: "PleromaAPI.EmojiPackController.index",
54 %Schema{type: :integer, default: 1},
60 %Schema{type: :integer, default: 50},
61 "Number of emoji packs to return"
65 200 => emoji_packs_response()
72 tags: ["Emoji packs"],
73 summary: "Show emoji pack",
74 operationId: "PleromaAPI.EmojiPackController.show",
80 %Schema{type: :integer, default: 1},
86 %Schema{type: :integer, default: 30},
87 "Number of emoji to return"
91 200 => Operation.response("Emoji Pack", "application/json", emoji_pack()),
92 400 => Operation.response("Bad Request", "application/json", ApiError),
93 404 => Operation.response("Not Found", "application/json", ApiError)
98 def archive_operation do
100 tags: ["Emoji packs"],
101 summary: "Requests a local pack archive from the instance",
102 operationId: "PleromaAPI.EmojiPackController.archive",
103 parameters: [name_param()],
106 Operation.response("Archive file", "application/octet-stream", %Schema{
110 403 => Operation.response("Forbidden", "application/json", ApiError),
111 404 => Operation.response("Not Found", "application/json", ApiError)
116 def download_operation do
118 tags: ["Emoji pack administration"],
119 summary: "Download pack from another instance",
120 operationId: "PleromaAPI.EmojiPackController.download",
121 security: [%{"oAuth" => ["admin:write"]}],
122 requestBody: request_body("Parameters", download_request(), required: true),
124 200 => ok_response(),
125 500 => Operation.response("Error", "application/json", ApiError)
130 defp download_request do
133 required: [:url, :name],
138 description: "URL of the instance to download from"
140 name: %Schema{type: :string, format: :uri, description: "Pack Name"},
141 as: %Schema{type: :string, format: :uri, description: "Save as"}
146 def create_operation do
148 tags: ["Emoji pack administration"],
149 summary: "Create an empty pack",
150 operationId: "PleromaAPI.EmojiPackController.create",
151 security: [%{"oAuth" => ["admin:write"]}],
152 parameters: [name_param()],
154 200 => ok_response(),
155 400 => Operation.response("Not Found", "application/json", ApiError),
156 409 => Operation.response("Conflict", "application/json", ApiError),
157 500 => Operation.response("Error", "application/json", ApiError)
162 def delete_operation do
164 tags: ["Emoji pack administration"],
165 summary: "Delete a custom emoji pack",
166 operationId: "PleromaAPI.EmojiPackController.delete",
167 security: [%{"oAuth" => ["admin:write"]}],
168 parameters: [name_param()],
170 200 => ok_response(),
171 400 => Operation.response("Bad Request", "application/json", ApiError),
172 404 => Operation.response("Not Found", "application/json", ApiError),
173 500 => Operation.response("Error", "application/json", ApiError)
178 def update_operation do
180 tags: ["Emoji pack administration"],
181 summary: "Updates (replaces) pack metadata",
182 operationId: "PleromaAPI.EmojiPackController.update",
183 security: [%{"oAuth" => ["admin:write"]}],
184 requestBody: request_body("Parameters", update_request(), required: true),
185 parameters: [name_param()],
187 200 => Operation.response("Metadata", "application/json", metadata()),
188 400 => Operation.response("Bad Request", "application/json", ApiError),
189 500 => Operation.response("Error", "application/json", ApiError)
194 def import_from_filesystem_operation do
196 tags: ["Emoji pack administration"],
197 summary: "Imports packs from filesystem",
198 operationId: "PleromaAPI.EmojiPackController.import",
199 security: [%{"oAuth" => ["admin:write"]}],
202 Operation.response("Array of imported pack names", "application/json", %Schema{
204 items: %Schema{type: :string}
211 Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
218 %Schema{type: :string, format: :uri},
219 "URL of the instance",
225 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
228 defp emoji_packs_response do
230 "Object with pack names as keys and pack contents as values",
235 count: %Schema{type: :integer},
238 additionalProperties: emoji_pack()
244 "emojos" => emoji_pack().example
256 files: files_object(),
260 license: %Schema{type: :string},
261 homepage: %Schema{type: :string, format: :uri},
262 description: %Schema{type: :string},
263 "can-download": %Schema{type: :boolean},
264 "share-files": %Schema{type: :boolean},
265 "download-sha256": %Schema{type: :string}
270 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
272 "license" => "Test license",
273 "homepage" => "https://pleroma.social",
274 "description" => "Test description",
275 "can-download" => true,
276 "share-files" => true,
277 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
286 additionalProperties: %Schema{type: :string},
287 description: "Object with emoji names as keys and filenames as values"
291 defp update_request do
297 description: "Metadata to replace the old one",
299 license: %Schema{type: :string},
300 homepage: %Schema{type: :string, format: :uri},
301 description: %Schema{type: :string},
302 "fallback-src": %Schema{
305 description: "Fallback url to download pack from"
307 "fallback-src-sha256": %Schema{
309 description: "SHA256 encoded for fallback pack archive"
311 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
322 license: %Schema{type: :string},
323 homepage: %Schema{type: :string, format: :uri},
324 description: %Schema{type: :string},
325 "fallback-src": %Schema{
328 description: "Fallback url to download pack from"
330 "fallback-src-sha256": %Schema{
332 description: "SHA256 encoded for fallback pack archive"
334 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}