Add spec for AccountController.lists
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 8 Apr 2020 19:51:46 +0000 (23:51 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 13 Apr 2020 14:17:07 +0000 (18:17 +0400)
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/api_spec/schemas/list.ex [new file with mode: 0644]
lib/pleroma/web/api_spec/schemas/lists_response.ex [new file with mode: 0644]
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
test/web/mastodon_api/controllers/account_controller_test.exs

index 456d08a45a504003b3b6e8f525eb22d007d01767..ad10f4ec9dd201646d9f50c444cd427441274505 100644 (file)
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
   alias Pleroma.Web.ApiSpec.Schemas.AccountsResponse
   alias Pleroma.Web.ApiSpec.Schemas.AccountUpdateCredentialsRequest
   alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
+  alias Pleroma.Web.ApiSpec.Schemas.ListsResponse
   alias Pleroma.Web.ApiSpec.Schemas.StatusesResponse
   alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
 
@@ -191,7 +192,22 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
-  def lists_operation, do: :ok
+  def lists_operation do
+    %Operation{
+      tags: ["accounts"],
+      summary: "Lists containing this account",
+      operationId: "AccountController.lists",
+      security: [%{"oAuth" => ["read:lists"]}],
+      description: "User lists that you have added this account to.",
+      parameters: [
+        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"}
+      ],
+      responses: %{
+        200 => Operation.response("Lists", "application/json", ListsResponse)
+      }
+    }
+  end
+
   def follow_operation, do: :ok
   def unfollow_operation, do: :ok
   def mute_operation, do: :ok
diff --git a/lib/pleroma/web/api_spec/schemas/list.ex b/lib/pleroma/web/api_spec/schemas/list.ex
new file mode 100644 (file)
index 0000000..30fa7db
--- /dev/null
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.Schemas.List do
+  alias OpenApiSpex.Schema
+
+  require OpenApiSpex
+
+  OpenApiSpex.schema(%{
+    title: "List",
+    description: "Response schema for a list",
+    type: :object,
+    properties: %{
+      id: %Schema{type: :string},
+      title: %Schema{type: :string}
+    },
+    example: %{
+      "JSON" => %{
+        "id" => "123",
+        "title" => "my list"
+      }
+    }
+  })
+end
diff --git a/lib/pleroma/web/api_spec/schemas/lists_response.ex b/lib/pleroma/web/api_spec/schemas/lists_response.ex
new file mode 100644 (file)
index 0000000..1324545
--- /dev/null
@@ -0,0 +1,16 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ApiSpec.Schemas.ListsResponse do
+  alias Pleroma.Web.ApiSpec.Schemas.List
+
+  require OpenApiSpex
+
+  OpenApiSpex.schema(%{
+    title: "ListsResponse",
+    description: "Response schema for lists",
+    type: :array,
+    items: List
+  })
+end
index e74180662fb495066f0113aa52a8144d94f78664..2c5cd8cdec3a110ee3226cf8f5e20dc2b2f46849 100644 (file)
@@ -91,7 +91,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
            :show,
            :statuses,
            :followers,
-           :following
+           :following,
+           :lists
          ]
   )
 
index 341c9b0155af94909c34e5df342d736c8cb60873..706eea5d93857a4fdfab6a9184ac68d48ac5628a 100644 (file)
@@ -1051,6 +1051,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
         |> json_response(200)
 
       assert res == [%{"id" => to_string(list.id), "title" => "Test List"}]
+      assert_schema(res, "ListsResponse", ApiSpec.spec())
     end
   end