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",
40 %Schema{type: :integer, default: 1},
46 %Schema{type: :integer, default: 50},
47 "Number of emoji packs to return"
51 200 => emoji_packs_response()
58 tags: ["Emoji Packs"],
59 summary: "Show emoji pack",
60 operationId: "PleromaAPI.EmojiPackController.show",
66 %Schema{type: :integer, default: 1},
72 %Schema{type: :integer, default: 30},
73 "Number of emoji to return"
77 200 => Operation.response("Emoji Pack", "application/json", emoji_pack()),
78 400 => Operation.response("Bad Request", "application/json", ApiError),
79 404 => Operation.response("Not Found", "application/json", ApiError)
84 def archive_operation do
86 tags: ["Emoji Packs"],
87 summary: "Requests a local pack archive from the instance",
88 operationId: "PleromaAPI.EmojiPackController.archive",
89 parameters: [name_param()],
92 Operation.response("Archive file", "application/octet-stream", %Schema{
96 403 => Operation.response("Forbidden", "application/json", ApiError),
97 404 => Operation.response("Not Found", "application/json", ApiError)
102 def download_operation do
104 tags: ["Emoji Packs"],
105 summary: "Download pack from another instance",
106 operationId: "PleromaAPI.EmojiPackController.download",
107 security: [%{"oAuth" => ["write"]}],
108 requestBody: request_body("Parameters", download_request(), required: true),
110 200 => ok_response(),
111 500 => Operation.response("Error", "application/json", ApiError)
116 defp download_request do
119 required: [:url, :name],
124 description: "URL of the instance to download from"
126 name: %Schema{type: :string, format: :uri, description: "Pack Name"},
127 as: %Schema{type: :string, format: :uri, description: "Save as"}
132 def create_operation do
134 tags: ["Emoji Packs"],
135 summary: "Create an empty pack",
136 operationId: "PleromaAPI.EmojiPackController.create",
137 security: [%{"oAuth" => ["write"]}],
138 parameters: [name_param()],
140 200 => ok_response(),
141 400 => Operation.response("Not Found", "application/json", ApiError),
142 409 => Operation.response("Conflict", "application/json", ApiError),
143 500 => Operation.response("Error", "application/json", ApiError)
148 def delete_operation do
150 tags: ["Emoji Packs"],
151 summary: "Delete a custom emoji pack",
152 operationId: "PleromaAPI.EmojiPackController.delete",
153 security: [%{"oAuth" => ["write"]}],
154 parameters: [name_param()],
156 200 => ok_response(),
157 400 => Operation.response("Bad Request", "application/json", ApiError),
158 404 => Operation.response("Not Found", "application/json", ApiError)
163 def update_operation do
165 tags: ["Emoji Packs"],
166 summary: "Updates (replaces) pack metadata",
167 operationId: "PleromaAPI.EmojiPackController.update",
168 security: [%{"oAuth" => ["write"]}],
169 requestBody: request_body("Parameters", update_request(), required: true),
170 parameters: [name_param()],
172 200 => Operation.response("Metadata", "application/json", metadata()),
173 400 => Operation.response("Bad Request", "application/json", ApiError)
178 def add_file_operation do
180 tags: ["Emoji Packs"],
181 summary: "Add new file to the pack",
182 operationId: "PleromaAPI.EmojiPackController.add_file",
183 security: [%{"oAuth" => ["write"]}],
184 requestBody: request_body("Parameters", add_file_request(), required: true),
185 parameters: [name_param()],
187 200 => Operation.response("Files Object", "application/json", files_object()),
188 400 => Operation.response("Bad Request", "application/json", ApiError),
189 409 => Operation.response("Conflict", "application/json", ApiError)
194 defp add_file_request do
201 "File needs to be uploaded with the multipart request or link to remote file",
203 %Schema{type: :string, format: :binary},
204 %Schema{type: :string, format: :uri}
210 "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
215 "New emoji file name. If not specified will be taken from original filename."
221 def update_file_operation do
223 tags: ["Emoji Packs"],
224 summary: "Add new file to the pack",
225 operationId: "PleromaAPI.EmojiPackController.update_file",
226 security: [%{"oAuth" => ["write"]}],
227 requestBody: request_body("Parameters", update_file_request(), required: true),
228 parameters: [name_param()],
230 200 => Operation.response("Files Object", "application/json", files_object()),
231 400 => Operation.response("Bad Request", "application/json", ApiError),
232 409 => Operation.response("Conflict", "application/json", ApiError)
237 defp update_file_request do
240 required: [:shortcode, :new_shortcode, :new_filename],
244 description: "Emoji file shortcode"
246 new_shortcode: %Schema{
248 description: "New emoji file shortcode"
250 new_filename: %Schema{
252 description: "New filename for emoji file"
256 description: "With true value to overwrite existing emoji with new shortcode",
263 def delete_file_operation do
265 tags: ["Emoji Packs"],
266 summary: "Delete emoji file from pack",
267 operationId: "PleromaAPI.EmojiPackController.delete_file",
268 security: [%{"oAuth" => ["write"]}],
271 Operation.parameter(:shortcode, :query, :string, "File shortcode",
277 200 => Operation.response("Files Object", "application/json", files_object()),
278 400 => Operation.response("Bad Request", "application/json", ApiError)
283 def import_from_filesystem_operation do
285 tags: ["Emoji Packs"],
286 summary: "Imports packs from filesystem",
287 operationId: "PleromaAPI.EmojiPackController.import",
288 security: [%{"oAuth" => ["write"]}],
291 Operation.response("Array of imported pack names", "application/json", %Schema{
293 items: %Schema{type: :string}
300 Operation.parameter(:name, :path, :string, "Pack Name", example: "cofe", required: true)
307 %Schema{type: :string, format: :uri},
308 "URL of the instance",
314 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
317 defp emoji_packs_response do
319 "Object with pack names as keys and pack contents as values",
323 additionalProperties: emoji_pack(),
325 "emojos" => emoji_pack().example
336 files: files_object(),
340 license: %Schema{type: :string},
341 homepage: %Schema{type: :string, format: :uri},
342 description: %Schema{type: :string},
343 "can-download": %Schema{type: :boolean},
344 "share-files": %Schema{type: :boolean},
345 "download-sha256": %Schema{type: :string}
350 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
352 "license" => "Test license",
353 "homepage" => "https://pleroma.social",
354 "description" => "Test description",
355 "can-download" => true,
356 "share-files" => true,
357 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
366 additionalProperties: %Schema{type: :string},
367 description: "Object with emoji names as keys and filenames as values"
371 defp update_request do
377 description: "Metadata to replace the old one",
379 license: %Schema{type: :string},
380 homepage: %Schema{type: :string, format: :uri},
381 description: %Schema{type: :string},
382 "fallback-src": %Schema{
385 description: "Fallback url to download pack from"
387 "fallback-src-sha256": %Schema{
389 description: "SHA256 encoded for fallback pack archive"
391 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
402 license: %Schema{type: :string},
403 homepage: %Schema{type: :string, format: :uri},
404 description: %Schema{type: :string},
405 "fallback-src": %Schema{
408 description: "Fallback url to download pack from"
410 "fallback-src-sha256": %Schema{
412 description: "SHA256 encoded for fallback pack archive"
414 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}