Add specs for AccountController.mutes, AccountController.blocks, AccountController...
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 9 Apr 2020 16:34:21 +0000 (20:34 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 13 Apr 2020 14:17:09 +0000 (18:17 +0400)
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
test/web/mastodon_api/controllers/account_controller_test.exs

index 9fef7ece19b8936e642d89d4c73244d82b23a2fa..9749c3b60afa1bd0ffc8400468cfd4a82bcfade2 100644 (file)
@@ -321,7 +321,42 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
-  def mutes_operation, do: :ok
-  def blocks_operation, do: :ok
-  def endorsements_operation, do: :ok
+  def mutes_operation do
+    %Operation{
+      tags: ["accounts"],
+      summary: "Muted accounts",
+      operationId: "AccountController.mutes",
+      description: "Accounts the user has muted.",
+      security: [%{"oAuth" => ["follow", "read:mutes"]}],
+      responses: %{
+        200 => Operation.response("Accounts", "application/json", AccountsResponse)
+      }
+    }
+  end
+
+  def blocks_operation do
+    %Operation{
+      tags: ["accounts"],
+      summary: "Blocked users",
+      operationId: "AccountController.blocks",
+      description: "View your blocks. See also accounts/:id/{block,unblock}",
+      security: [%{"oAuth" => ["read:blocks"]}],
+      responses: %{
+        200 => Operation.response("Accounts", "application/json", AccountsResponse)
+      }
+    }
+  end
+
+  def endorsements_operation do
+    %Operation{
+      tags: ["accounts"],
+      summary: "Endorsements",
+      operationId: "AccountController.endorsements",
+      description: "Not implemented",
+      security: [%{"oAuth" => ["read:accounts"]}],
+      responses: %{
+        200 => Operation.response("Empry array", "application/json", %Schema{type: :array})
+      }
+    }
+  end
 end
index 4340b9c8426e59bfd71416efed072240915a30e4..f72c91c51259f578af4ef5c0f1df26c4b5cd935c 100644 (file)
@@ -80,28 +80,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
   plug(RateLimiter, [name: :app_account_creation] when action == :create)
   plug(:assign_account_by_id when action in @needs_account)
 
-  plug(
-    OpenApiSpex.Plug.CastAndValidate,
-    [render_error: Pleroma.Web.ApiSpec.RenderError]
-    when action in [
-           :create,
-           :verify_credentials,
-           :update_credentials,
-           :relationships,
-           :show,
-           :statuses,
-           :followers,
-           :following,
-           :lists,
-           :follow,
-           :unfollow,
-           :mute,
-           :unmute,
-           :block,
-           :unblock,
-           :follows
-         ]
-  )
+  plug(OpenApiSpex.Plug.CastAndValidate, render_error: Pleroma.Web.ApiSpec.RenderError)
 
   action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
 
index fa2091c5e26c185f48e770da8f7e44dd37f87ffb..86136f7e444690e5a7373d84c42474e334993d2e 100644 (file)
@@ -1155,6 +1155,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     other_user_id = to_string(other_user.id)
     assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
+    assert_schema(json_response(conn, 200), "AccountsResponse", ApiSpec.spec())
   end
 
   test "getting a list of blocks" do
@@ -1170,5 +1171,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
 
     other_user_id = to_string(other_user.id)
     assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
+    assert_schema(json_response(conn, 200), "AccountsResponse", ApiSpec.spec())
   end
 end