[#2456] Changed `embed_relationships` param to `with_relationships`.

This commit is contained in:
Ivan Tashkinov 2020-05-13 15:08:07 +03:00
parent 33b798425f
commit 59b6d5f2aa
7 changed files with 77 additions and 85 deletions

View File

@ -5,6 +5,7 @@
defmodule Pleroma.Web.ApiSpec.Helpers do defmodule Pleroma.Web.ApiSpec.Helpers do
alias OpenApiSpex.Operation alias OpenApiSpex.Operation
alias OpenApiSpex.Schema alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
def request_body(description, schema_ref, opts \\ []) do def request_body(description, schema_ref, opts \\ []) do
media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"] media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
@ -47,13 +48,8 @@ def pagination_params do
] ]
end end
def embed_relationships_param do def with_relationships_param do
Operation.parameter( Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
:embed_relationships,
:query,
:boolean,
"Embed relationships into accounts (Pleroma extension)"
)
end end
def empty_object_response do def empty_object_response do

View File

@ -155,9 +155,10 @@ def followers_operation do
security: [%{"oAuth" => ["read:accounts"]}], security: [%{"oAuth" => ["read:accounts"]}],
description: description:
"Accounts which follow the given account, if network is not hidden by the account owner.", "Accounts which follow the given account, if network is not hidden by the account owner.",
parameters: parameters: [
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
pagination_params() ++ [embed_relationships_param()], with_relationships_param() | pagination_params()
],
responses: %{ responses: %{
200 => Operation.response("Accounts", "application/json", array_of_accounts()) 200 => Operation.response("Accounts", "application/json", array_of_accounts())
} }
@ -172,9 +173,10 @@ def following_operation do
security: [%{"oAuth" => ["read:accounts"]}], security: [%{"oAuth" => ["read:accounts"]}],
description: description:
"Accounts which the given account is following, if network is not hidden by the account owner.", "Accounts which the given account is following, if network is not hidden by the account owner.",
parameters: parameters: [
[%Reference{"$ref": "#/components/parameters/accountIdOrNickname"}] ++ %Reference{"$ref": "#/components/parameters/accountIdOrNickname"},
pagination_params() ++ [embed_relationships_param()], with_relationships_param() | pagination_params()
],
responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())} responses: %{200 => Operation.response("Accounts", "application/json", array_of_accounts())}
} }
end end

View File

@ -24,30 +24,30 @@ def account_search_operation do
tags: ["Search"], tags: ["Search"],
summary: "Search for matching accounts by username or display name", summary: "Search for matching accounts by username or display name",
operationId: "SearchController.account_search", operationId: "SearchController.account_search",
parameters: parameters: [
[ Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for", required: true
required: true ),
), Operation.parameter(
Operation.parameter( :limit,
:limit, :query,
:query, %Schema{type: :integer, default: 40},
%Schema{type: :integer, default: 40}, "Maximum number of results"
"Maximum number of results" ),
), Operation.parameter(
Operation.parameter( :resolve,
:resolve, :query,
:query, %Schema{allOf: [BooleanLike], default: false},
%Schema{allOf: [BooleanLike], default: false}, "Attempt WebFinger lookup. Use this when `q` is an exact address."
"Attempt WebFinger lookup. Use this when `q` is an exact address." ),
), Operation.parameter(
Operation.parameter( :following,
:following, :query,
:query, %Schema{allOf: [BooleanLike], default: false},
%Schema{allOf: [BooleanLike], default: false}, "Only include accounts that the user is following"
"Only include accounts that the user is following" ),
) with_relationships_param()
] ++ [embed_relationships_param()], ],
responses: %{ responses: %{
200 => 200 =>
Operation.response( Operation.response(
@ -66,42 +66,40 @@ def search_operation do
security: [%{"oAuth" => ["read:search"]}], security: [%{"oAuth" => ["read:search"]}],
operationId: "SearchController.search", operationId: "SearchController.search",
deprecated: true, deprecated: true,
parameters: parameters: [
[ Operation.parameter(
Operation.parameter( :account_id,
:account_id, :query,
:query, FlakeID,
FlakeID, "If provided, statuses returned will be authored only by this account"
"If provided, statuses returned will be authored only by this account" ),
), Operation.parameter(
Operation.parameter( :type,
:type, :query,
:query, %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
%Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]}, "Search type"
"Search type" ),
), Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true),
Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", Operation.parameter(
required: true :resolve,
), :query,
Operation.parameter( %Schema{allOf: [BooleanLike], default: false},
:resolve, "Attempt WebFinger lookup"
:query, ),
%Schema{allOf: [BooleanLike], default: false}, Operation.parameter(
"Attempt WebFinger lookup" :following,
), :query,
Operation.parameter( %Schema{allOf: [BooleanLike], default: false},
:following, "Only include accounts that the user is following"
:query, ),
%Schema{allOf: [BooleanLike], default: false}, Operation.parameter(
"Only include accounts that the user is following" :offset,
), :query,
Operation.parameter( %Schema{type: :integer},
:offset, "Offset"
:query, ),
%Schema{type: :integer}, with_relationships_param() | pagination_params()
"Offset" ],
)
] ++ pagination_params() ++ [embed_relationships_param()],
responses: %{ responses: %{
200 => Operation.response("Results", "application/json", results()) 200 => Operation.response("Results", "application/json", results())
} }

View File

@ -153,10 +153,6 @@ defp array_of_statuses do
} }
end end
defp with_relationships_param do
Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
end
defp local_param do defp local_param do
Operation.parameter( Operation.parameter(
:local, :local,

View File

@ -104,8 +104,8 @@ def put_if_exist(map, _key, nil), do: map
def put_if_exist(map, key, value), do: Map.put(map, key, value) def put_if_exist(map, key, value), do: Map.put(map, key, value)
def embed_relationships?(params) do def with_relationships?(params) do
# To do: change to `truthy_param?(params["embed_relationships"])` once PleromaFE supports it # To do: change to `truthy_param?(params["with_relationships"])` once PleromaFE supports it
not explicitly_falsy_param?(params["embed_relationships"]) not explicitly_falsy_param?(params["with_relationships"])
end end
end end

View File

@ -10,7 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
add_link_headers: 2, add_link_headers: 2,
truthy_param?: 1, truthy_param?: 1,
assign_account_by_id: 2, assign_account_by_id: 2,
embed_relationships?: 1, with_relationships?: 1,
json_response: 3 json_response: 3
] ]
@ -275,7 +275,7 @@ def followers(%{assigns: %{user: for_user, account: user}} = conn, params) do
for: for_user, for: for_user,
users: followers, users: followers,
as: :user, as: :user,
embed_relationships: embed_relationships?(params) embed_relationships: with_relationships?(params)
) )
end end
@ -300,7 +300,7 @@ def following(%{assigns: %{user: for_user, account: user}} = conn, params) do
for: for_user, for: for_user,
users: followers, users: followers,
as: :user, as: :user,
embed_relationships: embed_relationships?(params) embed_relationships: with_relationships?(params)
) )
end end

View File

@ -38,7 +38,7 @@ def account_search(%{assigns: %{user: user}} = conn, %{q: query} = params) do
users: accounts, users: accounts,
for: user, for: user,
as: :user, as: :user,
embed_relationships: ControllerHelper.embed_relationships?(params) embed_relationships: ControllerHelper.with_relationships?(params)
) )
end end
@ -82,7 +82,7 @@ defp search_options(params, user) do
offset: params[:offset], offset: params[:offset],
type: params[:type], type: params[:type],
author: get_author(params), author: get_author(params),
embed_relationships: ControllerHelper.embed_relationships?(params), embed_relationships: ControllerHelper.with_relationships?(params),
for_user: user for_user: user
] ]
|> Enum.filter(&elem(&1, 1)) |> Enum.filter(&elem(&1, 1))