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"]}],
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 Packs"],
119 summary: "Download pack from another instance",
120 operationId: "PleromaAPI.EmojiPackController.download",
121 security: [%{"oAuth" => ["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 Packs"],
149 summary: "Create an empty pack",
150 operationId: "PleromaAPI.EmojiPackController.create",
151 security: [%{"oAuth" => ["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 Packs"],
165 summary: "Delete a custom emoji pack",
166 operationId: "PleromaAPI.EmojiPackController.delete",
167 security: [%{"oAuth" => ["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)
177 def update_operation do
179 tags: ["Emoji Packs"],
180 summary: "Updates (replaces) pack metadata",
181 operationId: "PleromaAPI.EmojiPackController.update",
182 security: [%{"oAuth" => ["write"]}],
183 requestBody: request_body("Parameters", update_request(), required: true),
184 parameters: [name_param()],
186 200 => Operation.response("Metadata", "application/json", metadata()),
187 400 => Operation.response("Bad Request", "application/json", ApiError)
192 def import_from_filesystem_operation do
194 tags: ["Emoji Packs"],
195 summary: "Imports packs from filesystem",
196 operationId: "PleromaAPI.EmojiPackController.import",
197 security: [%{"oAuth" => ["write"]}],
200 Operation.response("Array of imported pack names", "application/json", %Schema{
202 items: %Schema{type: :string}
209 Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
216 %Schema{type: :string, format: :uri},
217 "URL of the instance",
223 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
226 defp emoji_packs_response do
228 "Object with pack names as keys and pack contents as values",
232 additionalProperties: emoji_pack(),
234 "emojos" => emoji_pack().example
245 files: files_object(),
249 license: %Schema{type: :string},
250 homepage: %Schema{type: :string, format: :uri},
251 description: %Schema{type: :string},
252 "can-download": %Schema{type: :boolean},
253 "share-files": %Schema{type: :boolean},
254 "download-sha256": %Schema{type: :string}
259 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
261 "license" => "Test license",
262 "homepage" => "https://pleroma.social",
263 "description" => "Test description",
264 "can-download" => true,
265 "share-files" => true,
266 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
275 additionalProperties: %Schema{type: :string},
276 description: "Object with emoji names as keys and filenames as values"
280 defp update_request do
286 description: "Metadata to replace the old one",
288 license: %Schema{type: :string},
289 homepage: %Schema{type: :string, format: :uri},
290 description: %Schema{type: :string},
291 "fallback-src": %Schema{
294 description: "Fallback url to download pack from"
296 "fallback-src-sha256": %Schema{
298 description: "SHA256 encoded for fallback pack archive"
300 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
311 license: %Schema{type: :string},
312 homepage: %Schema{type: :string, format: :uri},
313 description: %Schema{type: :string},
314 "fallback-src": %Schema{
317 description: "Fallback url to download pack from"
319 "fallback-src-sha256": %Schema{
321 description: "SHA256 encoded for fallback pack archive"
323 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}