added Pleroma.Web.PleromaAPI.EmojiFileController
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_emoji_file_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9
10 import Pleroma.Web.ApiSpec.Helpers
11
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
15 end
16
17 def create_operation do
18 %Operation{
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()],
25 responses: %{
26 200 => Operation.response("Files Object", "application/json", files_object()),
27 400 => Operation.response("Bad Request", "application/json", ApiError),
28 409 => Operation.response("Conflict", "application/json", ApiError)
29 }
30 }
31 end
32
33 defp create_request do
34 %Schema{
35 type: :object,
36 required: [:file],
37 properties: %{
38 file: %Schema{
39 description:
40 "File needs to be uploaded with the multipart request or link to remote file",
41 anyOf: [
42 %Schema{type: :string, format: :binary},
43 %Schema{type: :string, format: :uri}
44 ]
45 },
46 shortcode: %Schema{
47 type: :string,
48 description:
49 "Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
50 },
51 filename: %Schema{
52 type: :string,
53 description:
54 "New emoji file name. If not specified will be taken from original filename."
55 }
56 }
57 }
58 end
59
60 def update_operation do
61 %Operation{
62 tags: ["Emoji Packs"],
63 summary: "Add new file to the pack",
64 operationId: "PleromaAPI.EmojiPackController.update_file",
65 security: [%{"oAuth" => ["write"]}],
66 requestBody: request_body("Parameters", update_request(), required: true),
67 parameters: [name_param()],
68 responses: %{
69 200 => Operation.response("Files Object", "application/json", files_object()),
70 400 => Operation.response("Bad Request", "application/json", ApiError),
71 409 => Operation.response("Conflict", "application/json", ApiError)
72 }
73 }
74 end
75
76 defp update_request do
77 %Schema{
78 type: :object,
79 required: [:shortcode, :new_shortcode, :new_filename],
80 properties: %{
81 shortcode: %Schema{
82 type: :string,
83 description: "Emoji file shortcode"
84 },
85 new_shortcode: %Schema{
86 type: :string,
87 description: "New emoji file shortcode"
88 },
89 new_filename: %Schema{
90 type: :string,
91 description: "New filename for emoji file"
92 },
93 force: %Schema{
94 type: :boolean,
95 description: "With true value to overwrite existing emoji with new shortcode",
96 default: false
97 }
98 }
99 }
100 end
101
102 def delete_operation do
103 %Operation{
104 tags: ["Emoji Packs"],
105 summary: "Delete emoji file from pack",
106 operationId: "PleromaAPI.EmojiPackController.delete_file",
107 security: [%{"oAuth" => ["write"]}],
108 parameters: [
109 name_param(),
110 Operation.parameter(:shortcode, :query, :string, "File shortcode",
111 example: "cofe",
112 required: true
113 )
114 ],
115 responses: %{
116 200 => Operation.response("Files Object", "application/json", files_object()),
117 400 => Operation.response("Bad Request", "application/json", ApiError)
118 }
119 }
120 end
121
122 defp name_param do
123 Operation.parameter(:name, :path, :string, "Pack Name", example: "cofe", required: true)
124 end
125
126 defp files_object do
127 %Schema{
128 type: :object,
129 additionalProperties: %Schema{type: :string},
130 description: "Object with emoji names as keys and filenames as values"
131 }
132 end
133 end