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.ListOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Account
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
11 alias Pleroma.Web.ApiSpec.Schemas.List
13 import Pleroma.Web.ApiSpec.Helpers
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
20 def index_operation do
23 summary: "Show user's lists",
24 description: "Fetch all lists that the user owns",
25 security: [%{"oAuth" => ["read:lists"]}],
26 operationId: "ListController.index",
28 200 => Operation.response("Array of List", "application/json", array_of_lists())
33 def create_operation do
36 summary: "Create a list",
37 description: "Fetch the list with the given ID. Used for verifying the title of a list.",
38 operationId: "ListController.create",
39 requestBody: create_update_request(),
40 security: [%{"oAuth" => ["write:lists"]}],
42 200 => Operation.response("List", "application/json", List),
43 400 => Operation.response("Error", "application/json", ApiError),
44 404 => Operation.response("Error", "application/json", ApiError)
52 summary: "Show a single list",
53 description: "Fetch the list with the given ID. Used for verifying the title of a list.",
54 operationId: "ListController.show",
55 parameters: [id_param()],
56 security: [%{"oAuth" => ["read:lists"]}],
58 200 => Operation.response("List", "application/json", List),
59 404 => Operation.response("Error", "application/json", ApiError)
64 def update_operation do
67 summary: "Update a list",
68 description: "Change the title of a list",
69 operationId: "ListController.update",
70 parameters: [id_param()],
71 requestBody: create_update_request(),
72 security: [%{"oAuth" => ["write:lists"]}],
74 200 => Operation.response("List", "application/json", List),
75 422 => Operation.response("Error", "application/json", ApiError)
80 def delete_operation do
83 summary: "Delete a list",
84 operationId: "ListController.delete",
85 parameters: [id_param()],
86 security: [%{"oAuth" => ["write:lists"]}],
88 200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
93 def list_accounts_operation do
96 summary: "View accounts in list",
97 operationId: "ListController.list_accounts",
98 parameters: [id_param()],
99 security: [%{"oAuth" => ["read:lists"]}],
102 Operation.response("Array of Account", "application/json", %Schema{
110 def add_to_list_operation do
113 summary: "Add accounts to list",
114 description: "Add accounts to the given list.",
115 operationId: "ListController.add_to_list",
116 parameters: [id_param()],
117 requestBody: add_remove_accounts_request(true),
118 security: [%{"oAuth" => ["write:lists"]}],
120 200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
125 def remove_from_list_operation do
128 summary: "Remove accounts from list",
129 operationId: "ListController.remove_from_list",
135 %Schema{type: :array, items: %Schema{type: :string}},
136 "Array of account IDs"
139 requestBody: add_remove_accounts_request(false),
140 security: [%{"oAuth" => ["write:lists"]}],
142 200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
147 defp array_of_lists do
149 title: "ArrayOfLists",
150 description: "Response schema for lists",
154 %{"id" => "123", "title" => "my list"},
155 %{"id" => "1337", "title" => "another list"}
161 Operation.parameter(:id, :path, :string, "List ID",
167 defp create_update_request do
171 description: "POST body for creating or updating a List",
174 title: %Schema{type: :string, description: "List title"}
182 defp add_remove_accounts_request(required) when is_boolean(required) do
186 description: "POST body for adding/removing accounts to/from a List",
189 account_ids: %Schema{type: :array, description: "Array of account IDs", items: FlakeID}
191 required: required && [:account_ids]