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.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)
35 defp create_request do
42 "File needs to be uploaded with the multipart request or link to remote file",
44 %Schema{type: :string, format: :binary},
45 %Schema{type: :string, format: :uri}
51 "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
56 "New emoji file name. If not specified will be taken from original filename."
62 def update_operation do
64 tags: ["Emoji Packs"],
65 summary: "Add new file to the pack",
66 operationId: "PleromaAPI.EmojiPackController.update_file",
67 security: [%{"oAuth" => ["write"]}],
68 requestBody: request_body("Parameters", update_request(), required: true),
69 parameters: [name_param()],
71 200 => Operation.response("Files Object", "application/json", files_object()),
72 404 => Operation.response("Not Found", "application/json", ApiError),
73 400 => Operation.response("Bad Request", "application/json", ApiError),
74 409 => Operation.response("Conflict", "application/json", ApiError),
75 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
80 defp update_request do
83 required: [:shortcode, :new_shortcode, :new_filename],
87 description: "Emoji file shortcode"
89 new_shortcode: %Schema{
91 description: "New emoji file shortcode"
93 new_filename: %Schema{
95 description: "New filename for emoji file"
99 description: "With true value to overwrite existing emoji with new shortcode",
106 def delete_operation do
108 tags: ["Emoji Packs"],
109 summary: "Delete emoji file from pack",
110 operationId: "PleromaAPI.EmojiPackController.delete_file",
111 security: [%{"oAuth" => ["write"]}],
114 Operation.parameter(:shortcode, :query, :string, "File shortcode",
120 200 => Operation.response("Files Object", "application/json", files_object()),
121 400 => Operation.response("Bad Request", "application/json", ApiError),
122 404 => Operation.response("Not Found", "application/json", ApiError),
123 422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
129 Operation.parameter(:name, :path, :string, "Pack Name", example: "cofe", required: true)
135 additionalProperties: %Schema{type: :string},
136 description: "Object with emoji names as keys and filenames as values"