move to 2.5.5
[anni] / lib / pleroma / web / api_spec / operations / custom_emoji_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.CustomEmojiOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8   alias Pleroma.Web.ApiSpec.Schemas.Emoji
9
10   def open_api_operation(action) do
11     operation = String.to_existing_atom("#{action}_operation")
12     apply(__MODULE__, operation, [])
13   end
14
15   def index_operation do
16     %Operation{
17       tags: ["Custom emojis"],
18       summary: "Retrieve a list of custom emojis",
19       description: "Returns custom emojis that are available on the server.",
20       operationId: "CustomEmojiController.index",
21       responses: %{
22         200 => Operation.response("Custom Emojis", "application/json", resposnse())
23       }
24     }
25   end
26
27   defp resposnse do
28     %Schema{
29       title: "CustomEmojisResponse",
30       description: "Response schema for custom emojis",
31       type: :array,
32       items: custom_emoji(),
33       example: [
34         %{
35           "category" => "Fun",
36           "shortcode" => "blank",
37           "static_url" => "https://lain.com/emoji/blank.png",
38           "tags" => ["Fun"],
39           "url" => "https://lain.com/emoji/blank.png",
40           "visible_in_picker" => false
41         },
42         %{
43           "category" => "Gif,Fun",
44           "shortcode" => "firefox",
45           "static_url" => "https://lain.com/emoji/Firefox.gif",
46           "tags" => ["Gif", "Fun"],
47           "url" => "https://lain.com/emoji/Firefox.gif",
48           "visible_in_picker" => true
49         },
50         %{
51           "category" => "pack:mixed",
52           "shortcode" => "sadcat",
53           "static_url" => "https://lain.com/emoji/mixed/sadcat.png",
54           "tags" => ["pack:mixed"],
55           "url" => "https://lain.com/emoji/mixed/sadcat.png",
56           "visible_in_picker" => true
57         }
58       ]
59     }
60   end
61
62   defp custom_emoji do
63     %Schema{
64       title: "CustomEmoji",
65       description: "Schema for a CustomEmoji",
66       allOf: [
67         Emoji,
68         %Schema{
69           type: :object,
70           properties: %{
71             category: %Schema{type: :string},
72             tags: %Schema{type: :array, items: %Schema{type: :string}}
73           }
74         }
75       ],
76       example: %{
77         "category" => "Fun",
78         "shortcode" => "aaaa",
79         "url" =>
80           "https://files.mastodon.social/custom_emojis/images/000/007/118/original/aaaa.png",
81         "static_url" =>
82           "https://files.mastodon.social/custom_emojis/images/000/007/118/static/aaaa.png",
83         "visible_in_picker" => true,
84         "tags" => ["Gif", "Fun"]
85       }
86     }
87   end
88 end