Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / lib / pleroma / web / api_spec / operations / chat_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.ChatOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8
9 @spec open_api_operation(atom) :: Operation.t()
10 def open_api_operation(action) do
11 operation = String.to_existing_atom("#{action}_operation")
12 apply(__MODULE__, operation, [])
13 end
14
15 def create_operation do
16 %Operation{
17 tags: ["chat"],
18 summary: "Create a chat",
19 responses: %{
20 200 =>
21 Operation.response("Chat", "application/json", %Schema{
22 type: :object,
23 description: "A created chat is returned",
24 properties: %{
25 id: %Schema{type: :integer}
26 }
27 })
28 }
29 }
30 end
31
32 def index_operation do
33 %Operation{
34 tags: ["chat"],
35 summary: "Get a list of chats that you participated in",
36 responses: %{
37 200 =>
38 Operation.response("Chats", "application/json", %Schema{
39 type: :array,
40 description: "A list of chats",
41 items: %Schema{
42 type: :object,
43 description: "A chat"
44 }
45 })
46 }
47 }
48 end
49
50 def messages_operation do
51 %Operation{
52 tags: ["chat"],
53 summary: "Get the most recent messages of the chat",
54 responses: %{
55 200 =>
56 Operation.response("Messages", "application/json", %Schema{
57 type: :array,
58 description: "A list of chat messages",
59 items: %Schema{
60 type: :object,
61 description: "A chat message"
62 }
63 })
64 }
65 }
66 end
67
68 def post_chat_message_operation do
69 %Operation{
70 tags: ["chat"],
71 summary: "Post a message to the chat",
72 responses: %{
73 200 =>
74 Operation.response("Message", "application/json", %Schema{
75 type: :object,
76 description: "A chat message"
77 })
78 }
79 }
80 end
81 end