[#2456] Changed embed_relationships
param to with_relationships
.
This commit is contained in:
parent
33b798425f
commit
59b6d5f2aa
@ -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 @@ defmodule Pleroma.Web.ApiSpec.Helpers 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
|
||||||
|
@ -155,9 +155,10 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation 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 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation 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
|
||||||
|
@ -24,8 +24,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation 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
|
||||||
),
|
),
|
||||||
@ -46,8 +45,9 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
|
|||||||
: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"
|
||||||
)
|
),
|
||||||
] ++ [embed_relationships_param()],
|
with_relationships_param()
|
||||||
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 =>
|
200 =>
|
||||||
Operation.response(
|
Operation.response(
|
||||||
@ -66,8 +66,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation 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,
|
||||||
@ -80,9 +79,7 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
|
|||||||
%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",
|
Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true),
|
||||||
required: true
|
|
||||||
),
|
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:resolve,
|
:resolve,
|
||||||
:query,
|
:query,
|
||||||
@ -100,8 +97,9 @@ defmodule Pleroma.Web.ApiSpec.SearchOperation do
|
|||||||
:query,
|
:query,
|
||||||
%Schema{type: :integer},
|
%Schema{type: :integer},
|
||||||
"Offset"
|
"Offset"
|
||||||
)
|
),
|
||||||
] ++ pagination_params() ++ [embed_relationships_param()],
|
with_relationships_param() | pagination_params()
|
||||||
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Results", "application/json", results())
|
200 => Operation.response("Results", "application/json", results())
|
||||||
}
|
}
|
||||||
|
@ -153,10 +153,6 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation 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,
|
||||||
|
@ -104,8 +104,8 @@ defmodule Pleroma.Web.ControllerHelper do
|
|||||||
|
|
||||||
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
|
||||||
|
@ -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 @@ defmodule Pleroma.Web.MastodonAPI.AccountController 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 @@ defmodule Pleroma.Web.MastodonAPI.AccountController 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
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController 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 @@ defmodule Pleroma.Web.MastodonAPI.SearchController 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))
|
||||||
|
Loading…
Reference in New Issue
Block a user