Change follow_operation schema to use type BooleanLike (#301)
[akkoma] / lib / pleroma / web / api_spec / operations / account_operation.ex
index 3d451cd5af5e23d5cc3b76912fc176f54d0ae8e8..359a73ac06e3ddcd45914d61f3835e902d67a077 100644 (file)
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
   @spec create_operation() :: Operation.t()
   def create_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account credentials"],
       summary: "Register an account",
       description:
         "Creates a user and account records. Returns an account access token for the app that initiated the request. The app should save this token for later, and should wait for the user to confirm their account by clicking a link in their email inbox.",
@@ -43,7 +43,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def verify_credentials_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account credentials"],
       description: "Test to make sure that the user token works.",
       summary: "Verify account credentials",
       operationId: "AccountController.verify_credentials",
@@ -56,7 +56,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def update_credentials_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account credentials"],
       summary: "Update account credentials",
       description: "Update the user's display and preferences.",
       operationId: "AccountController.update_credentials",
@@ -71,8 +71,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def relationships_operation do
     %Operation{
-      tags: ["accounts"],
-      summary: "Check relationships to other accounts",
+      tags: ["Retrieve account information"],
+      summary: "Relationship with current account",
       operationId: "AccountController.relationships",
       description: "Find out whether a given account is followed, blocked, muted, etc.",
       security: [%{"oAuth" => ["read:follows"]}],
@@ -95,7 +95,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def show_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Account",
       operationId: "AccountController.show",
       description: "View information about a profile.",
@@ -113,8 +113,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def statuses_operation do
     %Operation{
-      tags: ["accounts"],
       summary: "Statuses",
+      tags: ["Retrieve account information"],
       operationId: "AccountController.statuses",
       description:
         "Statuses posted to the given account. Public (for public statuses only), or user token + `read:statuses` (for private statuses the user is authorized to see)",
@@ -160,7 +160,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def followers_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Followers",
       operationId: "AccountController.followers",
       security: [%{"oAuth" => ["read:accounts"]}],
@@ -179,7 +179,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def following_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Following",
       operationId: "AccountController.following",
       security: [%{"oAuth" => ["read:accounts"]}],
@@ -196,7 +196,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def lists_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Lists containing this account",
       operationId: "AccountController.lists",
       security: [%{"oAuth" => ["read:lists"]}],
@@ -208,7 +208,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def follow_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Follow",
       operationId: "AccountController.follow",
       security: [%{"oAuth" => ["follow", "write:follows"]}],
@@ -223,9 +223,15 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
             type: :object,
             properties: %{
               reblogs: %Schema{
-                type: :boolean,
+                allOf: [BooleanLike],
                 description: "Receive this account's reblogs in home timeline? Defaults to true.",
                 default: true
+              },
+              notify: %Schema{
+                allOf: [BooleanLike],
+                description:
+                  "Receive notifications for all statuses posted by the account? Defaults to false.",
+                default: false
               }
             }
           },
@@ -241,7 +247,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def unfollow_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Unfollow",
       operationId: "AccountController.unfollow",
       security: [%{"oAuth" => ["follow", "write:follows"]}],
@@ -257,7 +263,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def mute_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Mute",
       operationId: "AccountController.mute",
       security: [%{"oAuth" => ["follow", "write:mutes"]}],
@@ -287,7 +293,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def unmute_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Unmute",
       operationId: "AccountController.unmute",
       security: [%{"oAuth" => ["follow", "write:mutes"]}],
@@ -301,7 +307,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def block_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Block",
       operationId: "AccountController.block",
       security: [%{"oAuth" => ["follow", "write:blocks"]}],
@@ -316,7 +322,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def unblock_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Unblock",
       operationId: "AccountController.unblock",
       security: [%{"oAuth" => ["follow", "write:blocks"]}],
@@ -328,9 +334,48 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
+  def remove_from_followers_operation do
+    %Operation{
+      tags: ["Account actions"],
+      summary: "Remove from followers",
+      operationId: "AccountController.remove_from_followers",
+      security: [%{"oAuth" => ["follow", "write:follows"]}],
+      description: "Remove the given account from followers",
+      parameters: [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}],
+      responses: %{
+        200 => Operation.response("Relationship", "application/json", AccountRelationship),
+        400 => Operation.response("Error", "application/json", ApiError),
+        404 => Operation.response("Error", "application/json", ApiError)
+      }
+    }
+  end
+
+  def note_operation do
+    %Operation{
+      tags: ["Account actions"],
+      summary: "Set a private note about a user.",
+      operationId: "AccountController.note",
+      security: [%{"oAuth" => ["follow", "write:accounts"]}],
+      requestBody: request_body("Parameters", note_request()),
+      description: "Create a note for the given account.",
+      parameters: [
+        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        Operation.parameter(
+          :comment,
+          :query,
+          %Schema{type: :string},
+          "Account note body"
+        )
+      ],
+      responses: %{
+        200 => Operation.response("Relationship", "application/json", AccountRelationship)
+      }
+    }
+  end
+
   def follow_by_uri_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Account actions"],
       summary: "Follow by URI",
       operationId: "AccountController.follows",
       security: [%{"oAuth" => ["follow", "write:follows"]}],
@@ -345,8 +390,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def mutes_operation do
     %Operation{
-      tags: ["accounts"],
-      summary: "Muted accounts",
+      tags: ["Blocks and mutes"],
+      summary: "Retrieve list of mutes",
       operationId: "AccountController.mutes",
       description: "Accounts the user has muted.",
       security: [%{"oAuth" => ["follow", "read:mutes"]}],
@@ -359,8 +404,8 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def blocks_operation do
     %Operation{
-      tags: ["accounts"],
-      summary: "Blocked users",
+      tags: ["Blocks and mutes"],
+      summary: "Retrieve list of blocks",
       operationId: "AccountController.blocks",
       description: "View your blocks. See also accounts/:id/{block,unblock}",
       security: [%{"oAuth" => ["read:blocks"]}],
@@ -371,9 +416,29 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
+  def lookup_operation do
+    %Operation{
+      tags: ["Account lookup"],
+      summary: "Find a user by nickname",
+      operationId: "AccountController.lookup",
+      parameters: [
+        Operation.parameter(
+          :acct,
+          :query,
+          :string,
+          "User nickname"
+        )
+      ],
+      responses: %{
+        200 => Operation.response("Account", "application/json", Account),
+        404 => Operation.response("Error", "application/json", ApiError)
+      }
+    }
+  end
+
   def endorsements_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Endorsements",
       operationId: "AccountController.endorsements",
       description: "Not implemented",
@@ -386,7 +451,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
 
   def identity_proofs_operation do
     %Operation{
-      tags: ["accounts"],
+      tags: ["Retrieve account information"],
       summary: "Identity proofs",
       operationId: "AccountController.identity_proofs",
       # Validators complains about unused path params otherwise
@@ -458,6 +523,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           type: :string,
           nullable: true,
           description: "Invite token required when the registrations aren't public"
+        },
+        language: %Schema{
+          type: :string,
+          nullable: true,
+          description: "User's preferred language for emails"
         }
       },
       example: %{
@@ -541,11 +611,6 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           nullable: true,
           description: "Whether manual approval of follow requests is required."
         },
-        accepts_chat_messages: %Schema{
-          allOf: [BooleanLike],
-          nullable: true,
-          description: "Whether the user accepts receiving chat messages."
-        },
         fields_attributes: %Schema{
           nullable: true,
           oneOf: [
@@ -685,9 +750,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "blocked_by" => true,
           "muting" => false,
           "muting_notifications" => false,
+          "note" => "",
           "requested" => false,
           "domain_blocking" => false,
           "subscribing" => false,
+          "notifying" => false,
           "endorsed" => true
         },
         %{
@@ -699,9 +766,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "blocked_by" => true,
           "muting" => true,
           "muting_notifications" => false,
+          "note" => "",
           "requested" => true,
           "domain_blocking" => false,
           "subscribing" => false,
+          "notifying" => false,
           "endorsed" => false
         },
         %{
@@ -713,9 +782,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "blocked_by" => false,
           "muting" => true,
           "muting_notifications" => false,
+          "note" => "",
           "requested" => false,
           "domain_blocking" => true,
           "subscribing" => true,
+          "notifying" => true,
           "endorsed" => false
         }
       ]
@@ -760,6 +831,23 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
+  defp note_request do
+    %Schema{
+      title: "AccountNoteRequest",
+      description: "POST body for adding a note for an account",
+      type: :object,
+      properties: %{
+        comment: %Schema{
+          type: :string,
+          description: "Account note body"
+        }
+      },
+      example: %{
+        "comment" => "Example note"
+      }
+    }
+  end
+
   defp array_of_lists do
     %Schema{
       title: "ArrayOfLists",