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.PleromaEmojiFileOperation 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 create_operation do
19 tags: ["Emoji Packs"],
20 summary: "Add new file to the pack",
21 operationId: "PleromaAPI.EmojiPackController.add_file",
22 security: [%{"oAuth" => ["write"]}],
23 requestBody: request_body("Parameters", create_request(), required: true),
24 parameters: [name_param()],
26 200 => Operation.response("Files Object", "application/json", files_object()),
27 422 => Operation.response("Unprocessable Entity", "application/json", ApiError),
28 404 => Operation.response("Not Found", "application/json", ApiError),
29 400 => Operation.response("Bad Request", "application/json", ApiError),
30 409 => Operation.response("Conflict", "application/json", ApiError),
31 500 => Operation.response("Error", "application/json", ApiError)
36 defp create_request do
43 "File needs to be uploaded with the multipart request or link to remote file",
45 %Schema{type: :string, format: :binary},
46 %Schema{type: :string, format: :uri}
52 "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
57 "New emoji file name. If not specified will be taken from original filename."
63 def update_operation do
65 tags: ["Emoji Packs"],
66 summary: "Add new file to the pack",
67 operationId: "PleromaAPI.EmojiPackController.update_file",
68 security: [%{"oAuth" => ["write"]}],
69 requestBody: request_body("Parameters", update_request(), required: true),
70 parameters: [name_param()],
72 200 => Operation.response("Files Object", "application/json", files_object()),
73 404 => Operation.response("Not Found", "application/json", ApiError),
74 400 => Operation.response("Bad Request", "application/json", ApiError),
75 409 => Operation.response("Conflict", "application/json", ApiError),
76 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
81 defp update_request do
84 required: [:shortcode, :new_shortcode, :new_filename],
88 description: "Emoji file shortcode"
90 new_shortcode: %Schema{
92 description: "New emoji file shortcode"
94 new_filename: %Schema{
96 description: "New filename for emoji file"
100 description: "With true value to overwrite existing emoji with new shortcode",
107 def delete_operation do
109 tags: ["Emoji Packs"],
110 summary: "Delete emoji file from pack",
111 operationId: "PleromaAPI.EmojiPackController.delete_file",
112 security: [%{"oAuth" => ["write"]}],
115 Operation.parameter(:shortcode, :query, :string, "File shortcode",
121 200 => Operation.response("Files Object", "application/json", files_object()),
122 400 => Operation.response("Bad Request", "application/json", ApiError),
123 404 => Operation.response("Not Found", "application/json", ApiError),
124 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
130 Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
136 additionalProperties: %Schema{type: :string},
137 description: "Object with emoji names as keys and filenames as values"