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.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 Packs"],
20 summary: "Make request to another instance for emoji packs list",
21 security: [%{"oAuth" => ["write"]}],
22 parameters: [url_param()],
23 operationId: "PleromaAPI.EmojiPackController.remote",
25 200 => emoji_packs_response(),
26 500 => Operation.response("Error", "application/json", ApiError)
31 def index_operation do
33 tags: ["Emoji Packs"],
34 summary: "Lists local custom emoji packs",
35 operationId: "PleromaAPI.EmojiPackController.index",
37 200 => emoji_packs_response()
44 tags: ["Emoji Packs"],
45 summary: "Show emoji pack",
46 operationId: "PleromaAPI.EmojiPackController.show",
47 parameters: [name_param()],
49 200 => Operation.response("Emoji Pack", "application/json", emoji_pack()),
50 400 => Operation.response("Bad Request", "application/json", ApiError),
51 404 => Operation.response("Not Found", "application/json", ApiError)
56 def archive_operation do
58 tags: ["Emoji Packs"],
59 summary: "Requests a local pack archive from the instance",
60 operationId: "PleromaAPI.EmojiPackController.archive",
61 parameters: [name_param()],
64 Operation.response("Archive file", "application/octet-stream", %Schema{
68 403 => Operation.response("Forbidden", "application/json", ApiError),
69 404 => Operation.response("Not Found", "application/json", ApiError)
74 def download_operation do
76 tags: ["Emoji Packs"],
77 summary: "Download pack from another instance",
78 operationId: "PleromaAPI.EmojiPackController.download",
79 security: [%{"oAuth" => ["write"]}],
80 requestBody: request_body("Parameters", download_request(), required: true),
83 500 => Operation.response("Error", "application/json", ApiError)
88 defp download_request do
91 required: [:url, :name],
96 description: "URL of the instance to download from"
98 name: %Schema{type: :string, format: :uri, description: "Pack Name"},
99 as: %Schema{type: :string, format: :uri, description: "Save as"}
104 def create_operation do
106 tags: ["Emoji Packs"],
107 summary: "Create an empty pack",
108 operationId: "PleromaAPI.EmojiPackController.create",
109 security: [%{"oAuth" => ["write"]}],
110 parameters: [name_param()],
112 200 => ok_response(),
113 400 => Operation.response("Not Found", "application/json", ApiError),
114 409 => Operation.response("Conflict", "application/json", ApiError),
115 500 => Operation.response("Error", "application/json", ApiError)
120 def delete_operation do
122 tags: ["Emoji Packs"],
123 summary: "Delete a custom emoji pack",
124 operationId: "PleromaAPI.EmojiPackController.delete",
125 security: [%{"oAuth" => ["write"]}],
126 parameters: [name_param()],
128 200 => ok_response(),
129 400 => Operation.response("Bad Request", "application/json", ApiError),
130 404 => Operation.response("Not Found", "application/json", ApiError)
135 def update_operation do
137 tags: ["Emoji Packs"],
138 summary: "Updates (replaces) pack metadata",
139 operationId: "PleromaAPI.EmojiPackController.update",
140 security: [%{"oAuth" => ["write"]}],
141 requestBody: request_body("Parameters", update_request(), required: true),
142 parameters: [name_param()],
144 200 => Operation.response("Metadata", "application/json", metadata()),
145 400 => Operation.response("Bad Request", "application/json", ApiError)
150 def add_file_operation do
152 tags: ["Emoji Packs"],
153 summary: "Add new file to the pack",
154 operationId: "PleromaAPI.EmojiPackController.add_file",
155 security: [%{"oAuth" => ["write"]}],
156 requestBody: request_body("Parameters", add_file_request(), required: true),
157 parameters: [name_param()],
159 200 => Operation.response("Files Object", "application/json", files_object()),
160 400 => Operation.response("Bad Request", "application/json", ApiError),
161 409 => Operation.response("Conflict", "application/json", ApiError)
166 defp add_file_request do
173 "File needs to be uploaded with the multipart request or link to remote file",
175 %Schema{type: :string, format: :binary},
176 %Schema{type: :string, format: :uri}
182 "Shortcode for new emoji, must be uniq for all emoji. If not sended, shortcode will be taken from original filename."
187 "New emoji file name. If not specified will be taken from original filename."
193 def update_file_operation do
195 tags: ["Emoji Packs"],
196 summary: "Add new file to the pack",
197 operationId: "PleromaAPI.EmojiPackController.update_file",
198 security: [%{"oAuth" => ["write"]}],
199 requestBody: request_body("Parameters", update_file_request(), required: true),
200 parameters: [name_param()],
202 200 => Operation.response("Files Object", "application/json", files_object()),
203 400 => Operation.response("Bad Request", "application/json", ApiError),
204 409 => Operation.response("Conflict", "application/json", ApiError)
209 defp update_file_request do
212 required: [:shortcode, :new_shortcode, :new_filename],
216 description: "Emoji file shortcode"
218 new_shortcode: %Schema{
220 description: "New emoji file shortcode"
222 new_filename: %Schema{
224 description: "New filename for emoji file"
228 description: "With true value to overwrite existing emoji with new shortcode",
235 def delete_file_operation do
237 tags: ["Emoji Packs"],
238 summary: "Delete emoji file from pack",
239 operationId: "PleromaAPI.EmojiPackController.delete_file",
240 security: [%{"oAuth" => ["write"]}],
243 Operation.parameter(:shortcode, :query, :string, "File shortcode",
249 200 => Operation.response("Files Object", "application/json", files_object()),
250 400 => Operation.response("Bad Request", "application/json", ApiError)
255 def import_from_filesystem_operation do
257 tags: ["Emoji Packs"],
258 summary: "Imports packs from filesystem",
259 operationId: "PleromaAPI.EmojiPackController.import",
260 security: [%{"oAuth" => ["write"]}],
263 Operation.response("Array of imported pack names", "application/json", %Schema{
265 items: %Schema{type: :string}
272 Operation.parameter(:name, :path, :string, "Pack Name", example: "cofe", required: true)
279 %Schema{type: :string, format: :uri},
280 "URL of the instance",
286 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
289 defp emoji_packs_response do
291 "Object with pack names as keys and pack contents as values",
295 additionalProperties: emoji_pack(),
297 "emojos" => emoji_pack().example
308 files: files_object(),
312 license: %Schema{type: :string},
313 homepage: %Schema{type: :string, format: :uri},
314 description: %Schema{type: :string},
315 "can-download": %Schema{type: :boolean},
316 "share-files": %Schema{type: :boolean},
317 "download-sha256": %Schema{type: :string}
322 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
324 "license" => "Test license",
325 "homepage" => "https://pleroma.social",
326 "description" => "Test description",
327 "can-download" => true,
328 "share-files" => true,
329 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
338 additionalProperties: %Schema{type: :string},
339 description: "Object with emoji names as keys and filenames as values"
343 defp update_request do
349 description: "Metadata to replace the old one",
351 license: %Schema{type: :string},
352 homepage: %Schema{type: :string, format: :uri},
353 description: %Schema{type: :string},
354 "fallback-src": %Schema{
357 description: "Fallback url to download pack from"
359 "fallback-src-sha256": %Schema{
361 description: "SHA256 encoded for fallback pack archive"
363 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
374 license: %Schema{type: :string},
375 homepage: %Schema{type: :string, format: :uri},
376 description: %Schema{type: :string},
377 "fallback-src": %Schema{
380 description: "Fallback url to download pack from"
382 "fallback-src-sha256": %Schema{
384 description: "SHA256 encoded for fallback pack archive"
386 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}