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.ChatOperation do
6 alias OpenApiSpex.Operation
7 alias Pleroma.Web.ApiSpec.Helpers
8 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageCreateRequest
9 alias Pleroma.Web.ApiSpec.Schemas.ChatMessageResponse
10 alias Pleroma.Web.ApiSpec.Schemas.ChatMessagesResponse
11 alias Pleroma.Web.ApiSpec.Schemas.ChatResponse
12 alias Pleroma.Web.ApiSpec.Schemas.ChatsResponse
14 @spec open_api_operation(atom) :: Operation.t()
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
20 def create_operation do
23 summary: "Create a chat",
24 operationId: "ChatController.create",
30 "The ActivityPub id of the recipient of this chat.",
32 example: "https://lain.com/users/lain"
37 Operation.response("The created or existing chat", "application/json", ChatResponse)
47 def index_operation do
50 summary: "Get a list of chats that you participated in",
51 operationId: "ChatController.index",
53 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
54 Operation.parameter(:min_id, :query, :string, "Return only chats after this id"),
55 Operation.parameter(:max_id, :query, :string, "Return only chats before this id")
58 200 => Operation.response("The chats of the user", "application/json", ChatsResponse)
68 def messages_operation do
71 summary: "Get the most recent messages of the chat",
72 operationId: "ChatController.messages",
74 Operation.parameter(:id, :path, :string, "The ID of the Chat"),
75 Operation.parameter(:limit, :query, :integer, "How many results to return", example: 20),
76 Operation.parameter(:min_id, :query, :string, "Return only messages after this id"),
77 Operation.parameter(:max_id, :query, :string, "Return only messages before this id")
81 Operation.response("The messages in the chat", "application/json", ChatMessagesResponse)
91 def post_chat_message_operation do
94 summary: "Post a message to the chat",
95 operationId: "ChatController.post_chat_message",
97 Operation.parameter(:id, :path, :string, "The ID of the Chat")
99 requestBody: Helpers.request_body("Parameters", ChatMessageCreateRequest, required: true),
103 "The newly created ChatMessage",