[#2456] Changed `embed_relationships` param to `with_relationships`.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 13 May 2020 12:08:07 +0000 (15:08 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Wed, 13 May 2020 12:08:07 +0000 (15:08 +0300)
lib/pleroma/web/api_spec/helpers.ex
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/api_spec/operations/search_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 ee077a3f9e79b103ed2225f8a847bedb4639ca21..859e45b57ed67fc2069e82788e863f230ebbd4c8 100644 (file)
@@ -5,6 +5,7 @@
 defmodule Pleroma.Web.ApiSpec.Helpers do
   alias OpenApiSpex.Operation
   alias OpenApiSpex.Schema
+  alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
 
   def request_body(description, schema_ref, opts \\ []) do
     media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
@@ -47,13 +48,8 @@ defmodule Pleroma.Web.ApiSpec.Helpers do
     ]
   end
 
-  def embed_relationships_param do
-    Operation.parameter(
-      :embed_relationships,
-      :query,
-      :boolean,
-      "Embed relationships into accounts (Pleroma extension)"
-    )
+  def with_relationships_param do
+    Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
   end
 
   def empty_object_response do
index c2a56b7867543edc0e30fc4ed49776eab85fd265..7056f739bf3f8e27cbb67c7410619da8528bc308 100644 (file)
@@ -155,9 +155,10 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
       security: [%{"oAuth" => ["read:accounts"]}],
       description:
         "Accounts which follow the given account, if network is not hidden by the account owner.",
-      parameters:
-        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++
-          pagination_params() ++ [embed_relationships_param()],
+      parameters: [
+        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        with_relationships_param() | pagination_params()
+      ],
       responses: %{
         200 => Operation.response("Accounts", "application/json", array_of_accounts())
       }
@@ -172,9 +173,10 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
       security: [%{"oAuth" => ["read:accounts"]}],
       description:
         "Accounts which the given account is following, if network is not hidden by the account owner.",
-      parameters:
-        [%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++
-          pagination_params() ++ [embed_relationships_param()],
+      parameters: [
+        %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
+        with_relationships_param() | pagination_params()
+      ],
       responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
     }
   end
index 0dd908d7fade1ea66f9f92df6e437093723076a6..475848ff5418ca912a711c9e887049b527389543 100644 (file)
@@ -24,30 +24,30 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
       tags: ["Search"],
       summary: "Search for matching accounts by username or display name",
       operationId: "SearchController.account_search",
-      parameters:
-        [
-          Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
-            required: true
-          ),
-          Operation.parameter(
-            :limit,
-            :query,
-            %Schema{type: :integer, default: 40},
-            "Maximum number of results"
-          ),
-          Operation.parameter(
-            :resolve,
-            :query,
-            %Schema{allOf: [BooleanLike], default: false},
-            "Attempt WebFinger lookup. Use this when `q` is an exact address."
-          ),
-          Operation.parameter(
-            :following,
-            :query,
-            %Schema{allOf: [BooleanLike], default: false},
-            "Only include accounts that the user is following"
-          )
-        ] ++ [embed_relationships_param()],
+      parameters: [
+        Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
+          required: true
+        ),
+        Operation.parameter(
+          :limit,
+          :query,
+          %Schema{type: :integer, default: 40},
+          "Maximum number of results"
+        ),
+        Operation.parameter(
+          :resolve,
+          :query,
+          %Schema{allOf: [BooleanLike], default: false},
+          "Attempt WebFinger lookup. Use this when `q` is an exact address."
+        ),
+        Operation.parameter(
+          :following,
+          :query,
+          %Schema{allOf: [BooleanLike], default: false},
+          "Only include accounts that the user is following"
+        ),
+        with_relationships_param()
+      ],
       responses: %{
         200 =>
           Operation.response(
@@ -66,42 +66,40 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
       security: [%{"oAuth" => ["read:search"]}],
       operationId: "SearchController.search",
       deprecated: true,
-      parameters:
-        [
-          Operation.parameter(
-            :account_id,
-            :query,
-            FlakeID,
-            "If provided, statuses returned will be authored only by this account"
-          ),
-          Operation.parameter(
-            :type,
-            :query,
-            %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
-            "Search type"
-          ),
-          Operation.parameter(:q, :query, %Schema{type: :string}, "The search query",
-            required: true
-          ),
-          Operation.parameter(
-            :resolve,
-            :query,
-            %Schema{allOf: [BooleanLike], default: false},
-            "Attempt WebFinger lookup"
-          ),
-          Operation.parameter(
-            :following,
-            :query,
-            %Schema{allOf: [BooleanLike], default: false},
-            "Only include accounts that the user is following"
-          ),
-          Operation.parameter(
-            :offset,
-            :query,
-            %Schema{type: :integer},
-            "Offset"
-          )
-        ] ++ pagination_params() ++ [embed_relationships_param()],
+      parameters: [
+        Operation.parameter(
+          :account_id,
+          :query,
+          FlakeID,
+          "If provided, statuses returned will be authored only by this account"
+        ),
+        Operation.parameter(
+          :type,
+          :query,
+          %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
+          "Search type"
+        ),
+        Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true),
+        Operation.parameter(
+          :resolve,
+          :query,
+          %Schema{allOf: [BooleanLike], default: false},
+          "Attempt WebFinger lookup"
+        ),
+        Operation.parameter(
+          :following,
+          :query,
+          %Schema{allOf: [BooleanLike], default: false},
+          "Only include accounts that the user is following"
+        ),
+        Operation.parameter(
+          :offset,
+          :query,
+          %Schema{type: :integer},
+          "Offset"
+        ),
+        with_relationships_param() | pagination_params()
+      ],
       responses: %{
         200 => Operation.response("Results", "application/json", results())
       }
index 1b89035d47c05d64e46f2dd924c252d0144dc0e9..6cbc7f747806126ab12357bf7b12697540a1429b 100644 (file)
@@ -153,10 +153,6 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
     }
   end
 
-  defp with_relationships_param do
-    Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
-  end
-
   defp local_param do
     Operation.parameter(
       :local,
index ae9b265b11850dba433582546cb21231ddf57878..ff94c6be0a524db62fd990b17b08e00660365e1f 100644 (file)
@@ -104,8 +104,8 @@ defmodule Pleroma.Web.ControllerHelper do
 
   def put_if_exist(map, key, value), do: Map.put(map, key, value)
 
-  def embed_relationships?(params) do
-    # To do: change to `truthy_param?(params["embed_relationships"])` once PleromaFE supports it
-    not explicitly_falsy_param?(params["embed_relationships"])
+  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"])
   end
 end
index ef41f9e96db2ba3c7564b81200db473f54c26eae..2dd0252ccb9c77ddf1c2a6f25962dbfba9e349f0 100644 (file)
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       add_link_headers: 2,
       truthy_param?: 1,
       assign_account_by_id: 2,
-      embed_relationships?: 1,
+      with_relationships?: 1,
       json_response: 3
     ]
 
@@ -275,7 +275,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       for: for_user,
       users: followers,
       as: :user,
-      embed_relationships: embed_relationships?(params)
+      embed_relationships: with_relationships?(params)
     )
   end
 
@@ -300,7 +300,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       for: for_user,
       users: followers,
       as: :user,
-      embed_relationships: embed_relationships?(params)
+      embed_relationships: with_relationships?(params)
     )
   end
 
index 632c4590f7da8c7bc592fa0c85b35daaa196e0ed..1c2860cc719bf9b594f8c669863faec4cb284283 100644 (file)
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
       users: accounts,
       for: user,
       as: :user,
-      embed_relationships: ControllerHelper.embed_relationships?(params)
+      embed_relationships: ControllerHelper.with_relationships?(params)
     )
   end
 
@@ -82,7 +82,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
       offset: params[:offset],
       type: params[:type],
       author: get_author(params),
-      embed_relationships: ControllerHelper.embed_relationships?(params),
+      embed_relationships: ControllerHelper.with_relationships?(params),
       for_user: user
     ]
     |> Enum.filter(&elem(&1, 1))