Improve OpenAPI spec and deploy it to api.pleroma.social
[akkoma] / lib / pleroma / web / api_spec / operations / list_operation.ex
index c88ed5dd0ebd51cb29720a07ebc571474e51a5d4..8a6e92b99f0e23294b6e7b67814a6baef12e9845 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ApiSpec.ListOperation do
@@ -20,7 +20,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
   def index_operation do
     %Operation{
       tags: ["Lists"],
-      summary: "Show user's lists",
+      summary: "Retrieve a list of lists",
       description: "Fetch all lists that the user owns",
       security: [%{"oAuth" => ["read:lists"]}],
       operationId: "ListController.index",
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
   def create_operation do
     %Operation{
       tags: ["Lists"],
-      summary: "Create  a list",
+      summary: "Create a list",
       description: "Fetch the list with the given ID. Used for verifying the title of a list.",
       operationId: "ListController.create",
       requestBody: create_update_request(),
@@ -49,7 +49,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
   def show_operation do
     %Operation{
       tags: ["Lists"],
-      summary: "Show a single list",
+      summary: "Retrieve a list",
       description: "Fetch the list with the given ID. Used for verifying the title of a list.",
       operationId: "ListController.show",
       parameters: [id_param()],
@@ -93,7 +93,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
   def list_accounts_operation do
     %Operation{
       tags: ["Lists"],
-      summary: "View accounts in list",
+      summary: "Retrieve accounts in list",
       operationId: "ListController.list_accounts",
       parameters: [id_param()],
       security: [%{"oAuth" => ["read:lists"]}],
@@ -114,7 +114,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
       description: "Add accounts to the given list.",
       operationId: "ListController.add_to_list",
       parameters: [id_param()],
-      requestBody: add_remove_accounts_request(),
+      requestBody: add_remove_accounts_request(true),
       security: [%{"oAuth" => ["write:lists"]}],
       responses: %{
         200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
@@ -127,8 +127,16 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
       tags: ["Lists"],
       summary: "Remove accounts from list",
       operationId: "ListController.remove_from_list",
-      parameters: [id_param()],
-      requestBody: add_remove_accounts_request(),
+      parameters: [
+        id_param(),
+        Operation.parameter(
+          :account_ids,
+          :query,
+          %Schema{type: :array, items: %Schema{type: :string}},
+          "Array of account IDs"
+        )
+      ],
+      requestBody: add_remove_accounts_request(false),
       security: [%{"oAuth" => ["write:lists"]}],
       responses: %{
         200 => Operation.response("Empty object", "application/json", %Schema{type: :object})
@@ -171,7 +179,7 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
     )
   end
 
-  defp add_remove_accounts_request do
+  defp add_remove_accounts_request(required) when is_boolean(required) do
     request_body(
       "Parameters",
       %Schema{
@@ -179,10 +187,9 @@ defmodule Pleroma.Web.ApiSpec.ListOperation do
         type: :object,
         properties: %{
           account_ids: %Schema{type: :array, description: "Array of account IDs", items: FlakeID}
-        },
-        required: [:account_ids]
+        }
       },
-      required: true
+      required: required
     )
   end
 end