[#2456] OpenAPI-related tweaks. Removed support for `with_relationships` param in...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 13 May 2020 15:56:45 +0000 (18:56 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 13 May 2020 15:56:45 +0000 (18:56 +0300)
lib/pleroma/web/api_spec/helpers.ex
lib/pleroma/web/api_spec/operations/search_operation.ex
lib/pleroma/web/api_spec/operations/status_operation.ex
lib/pleroma/web/api_spec/operations/timeline_operation.ex
lib/pleroma/web/controller_helper.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
lib/pleroma/web/mastodon_api/controllers/search_controller.ex

index 859e45b57ed67fc2069e82788e863f230ebbd4c8..16e7ed124fc48df1c6fcde0f572b4acd2beef5e2 100644 (file)
@@ -49,7 +49,12 @@ defmodule Pleroma.Web.ApiSpec.Helpers do
   end
 
   def with_relationships_param do
-    Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
+    Operation.parameter(
+      :with_relationships,
+      :query,
+      BooleanLike,
+      "Embed relationships into accounts."
+    )
   end
 
   def empty_object_response do
index 475848ff5418ca912a711c9e887049b527389543..169c36d879c1351d1338057ffe9ff291f73e67c8 100644 (file)
@@ -19,6 +19,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
     apply(__MODULE__, operation, [])
   end
 
+  # Note: `with_relationships` param is not supported (PleromaFE uses this op for autocomplete)
   def account_search_operation do
     %Operation{
       tags: ["Search"],
@@ -45,8 +46,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
           :query,
           %Schema{allOf: [BooleanLike], default: false},
           "Only include accounts that the user is following"
-        ),
-        with_relationships_param()
+        )
       ],
       responses: %{
         200 =>
@@ -139,8 +139,8 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
           :query,
           %Schema{allOf: [BooleanLike], default: false},
           "Only include accounts that the user is following"
-        )
-        | pagination_params()
+        ),
+        with_relationships_param() | pagination_params()
       ],
       responses: %{
         200 => Operation.response("Results", "application/json", results2())
index a6bb87560c749187f05ce6290db43ae2e6004e16..f74ea664c4e6ae7a888aab7a4008742489ce1575 100644 (file)
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
   alias OpenApiSpex.Schema
   alias Pleroma.Web.ApiSpec.AccountOperation
   alias Pleroma.Web.ApiSpec.Schemas.ApiError
-  alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
   alias Pleroma.Web.ApiSpec.Schemas.FlakeID
   alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus
   alias Pleroma.Web.ApiSpec.Schemas.Status
@@ -349,10 +348,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
       summary: "Bookmarked statuses",
       description: "Statuses the user has bookmarked",
       operationId: "StatusController.bookmarks",
-      parameters: [
-        Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
-        | pagination_params()
-      ],
+      parameters: pagination_params(),
       security: [%{"oAuth" => ["read:bookmarks"]}],
       responses: %{
         200 => Operation.response("Array of Statuses", "application/json", array_of_statuses())
index 6cbc7f747806126ab12357bf7b12697540a1429b..cb9d75841088de66da1fc192b1978a65d1cdb57d 100644 (file)
@@ -27,8 +27,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
         local_param(),
         with_muted_param(),
         exclude_visibilities_param(),
-        reply_visibility_param(),
-        with_relationships_param() | pagination_params()
+        reply_visibility_param() | pagination_params()
       ],
       operationId: "TimelineController.home",
       responses: %{
@@ -63,8 +62,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
         only_media_param(),
         with_muted_param(),
         exclude_visibilities_param(),
-        reply_visibility_param(),
-        with_relationships_param() | pagination_params()
+        reply_visibility_param() | pagination_params()
       ],
       operationId: "TimelineController.public",
       responses: %{
@@ -109,8 +107,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
         local_param(),
         only_media_param(),
         with_muted_param(),
-        exclude_visibilities_param(),
-        with_relationships_param() | pagination_params()
+        exclude_visibilities_param() | pagination_params()
       ],
       operationId: "TimelineController.hashtag",
       responses: %{
@@ -134,8 +131,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
           required: true
         ),
         with_muted_param(),
-        exclude_visibilities_param(),
-        with_relationships_param() | pagination_params()
+        exclude_visibilities_param() | pagination_params()
       ],
       operationId: "TimelineController.list",
       responses: %{
index ff94c6be0a524db62fd990b17b08e00660365e1f..5a1316a5f166f5871be0cb75e059de9299f96735 100644 (file)
@@ -104,8 +104,16 @@ defmodule Pleroma.Web.ControllerHelper do
 
   def put_if_exist(map, key, value), do: Map.put(map, key, value)
 
-  def with_relationships?(params) do
-    # To do: change to `truthy_param?(params["with_relationships"])` once PleromaFE supports it
-    not explicitly_falsy_param?(params["with_relationships"])
+  @doc """
+  Returns true if request specifies to include embedded relationships in account objects.
+  May only be used in selected account-related endpoints; has no effect for status- or
+    notification-related endpoints.
+  """
+  # Intended for PleromaFE: https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838
+  def embed_relationships?(params) do
+    # To do once OpenAPI transition mess is over: just `truthy_param?(params[:with_relationships])`
+    params
+    |> Map.get(:with_relationships, params["with_relationships"])
+    |> truthy_param?()
   end
 end
index 2dd0252ccb9c77ddf1c2a6f25962dbfba9e349f0..ef41f9e96db2ba3c7564b81200db473f54c26eae 100644 (file)
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       add_link_headers: 2,
       truthy_param?: 1,
       assign_account_by_id: 2,
-      with_relationships?: 1,
+      embed_relationships?: 1,
       json_response: 3
     ]
 
@@ -275,7 +275,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       for: for_user,
       users: followers,
       as: :user,
-      embed_relationships: with_relationships?(params)
+      embed_relationships: embed_relationships?(params)
     )
   end
 
@@ -300,7 +300,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       for: for_user,
       users: followers,
       as: :user,
-      embed_relationships: with_relationships?(params)
+      embed_relationships: embed_relationships?(params)
     )
   end
 
index 1c2860cc719bf9b594f8c669863faec4cb284283..77e2224e43ec3477a02a22390dfbb5e89a5ef5bc 100644 (file)
@@ -33,12 +33,10 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
 
     conn
     |> put_view(AccountView)
-    # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
     |> render("index.json",
       users: accounts,
       for: user,
-      as: :user,
-      embed_relationships: ControllerHelper.with_relationships?(params)
+      as: :user
     )
   end
 
@@ -82,7 +80,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
       offset: params[:offset],
       type: params[:type],
       author: get_author(params),
-      embed_relationships: ControllerHelper.with_relationships?(params),
+      embed_relationships: ControllerHelper.embed_relationships?(params),
       for_user: user
     ]
     |> Enum.filter(&elem(&1, 1))
@@ -95,7 +93,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
       users: accounts,
       for: options[:for_user],
       as: :user,
-      # https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
       embed_relationships: options[:embed_relationships]
     )
   end