Add OpenAPI spec for SuggestionController
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 13 May 2020 10:15:24 +0000 (14:15 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 13 May 2020 10:15:24 +0000 (14:15 +0400)
lib/pleroma/web/mastodon_api/controllers/suggestion_controller.ex
test/web/mastodon_api/controllers/suggestion_controller_test.exs

index c93a439696223e619263c03a94260988f4fd36c6..f91df9ab709034e74ff1cafe7c9d7bdfa8486f68 100644 (file)
@@ -5,11 +5,26 @@
 defmodule Pleroma.Web.MastodonAPI.SuggestionController do
   use Pleroma.Web, :controller
 
-  alias Pleroma.Plugs.OAuthScopesPlug
-
   require Logger
 
-  plug(OAuthScopesPlug, %{scopes: ["read"]} when action == :index)
+  plug(Pleroma.Web.ApiSpec.CastAndValidate)
+  plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["read"]} when action == :index)
+
+  def open_api_operation(action) do
+    operation = String.to_existing_atom("#{action}_operation")
+    apply(__MODULE__, operation, [])
+  end
+
+  def index_operation do
+    %OpenApiSpex.Operation{
+      tags: ["Suggestions"],
+      summary: "Follow suggestions (Not implemented)",
+      operationId: "SuggestionController.index",
+      responses: %{
+        200 => Pleroma.Web.ApiSpec.Helpers.empty_array_response()
+      }
+    }
+  end
 
   @doc "GET /api/v1/suggestions"
   def index(conn, params),
index f120bd0cd17828d5f0da7fdfcd67935b226bfd88..7f08e187cfcfe650abae8c5b554d0a63b6a2f00c 100644 (file)
@@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
     res =
       conn
       |> get("/api/v1/suggestions")
-      |> json_response(200)
+      |> json_response_and_validate_schema(200)
 
     assert res == []
   end