[#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
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

View 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

View 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())
}

View 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,

View 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

View 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

View 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))