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 import_from_filesystem_operation do
180 tags: ["Emoji Packs"],
181 summary: "Imports packs from filesystem",
182 operationId: "PleromaAPI.EmojiPackController.import",
183 security: [%{"oAuth" => ["write"]}],
186 Operation.response("Array of imported pack names", "application/json", %Schema{
188 items: %Schema{type: :string}
195 Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
202 %Schema{type: :string, format: :uri},
203 "URL of the instance",
209 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
212 defp emoji_packs_response do
214 "Object with pack names as keys and pack contents as values",
218 additionalProperties: emoji_pack(),
220 "emojos" => emoji_pack().example
231 files: files_object(),
235 license: %Schema{type: :string},
236 homepage: %Schema{type: :string, format: :uri},
237 description: %Schema{type: :string},
238 "can-download": %Schema{type: :boolean},
239 "share-files": %Schema{type: :boolean},
240 "download-sha256": %Schema{type: :string}
245 "files" => %{"emacs" => "emacs.png", "guix" => "guix.png"},
247 "license" => "Test license",
248 "homepage" => "https://pleroma.social",
249 "description" => "Test description",
250 "can-download" => true,
251 "share-files" => true,
252 "download-sha256" => "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
261 additionalProperties: %Schema{type: :string},
262 description: "Object with emoji names as keys and filenames as values"
266 defp update_request do
272 description: "Metadata to replace the old one",
274 license: %Schema{type: :string},
275 homepage: %Schema{type: :string, format: :uri},
276 description: %Schema{type: :string},
277 "fallback-src": %Schema{
280 description: "Fallback url to download pack from"
282 "fallback-src-sha256": %Schema{
284 description: "SHA256 encoded for fallback pack archive"
286 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}
297 license: %Schema{type: :string},
298 homepage: %Schema{type: :string, format: :uri},
299 description: %Schema{type: :string},
300 "fallback-src": %Schema{
303 description: "Fallback url to download pack from"
305 "fallback-src-sha256": %Schema{
307 description: "SHA256 encoded for fallback pack archive"
309 "share-files": %Schema{type: :boolean, description: "Is pack allowed for sharing?"}