[#2456] OpenAPI-related tweaks. Removed support for `with_relationships` param in `GET /api/v1/accounts/search`.

This commit is contained in:
Ivan Tashkinov 2020-05-13 18:56:45 +03:00
parent 59b6d5f2aa
commit 8062d590dd
7 changed files with 31 additions and 29 deletions

View File

@ -49,7 +49,12 @@ def pagination_params do
end end
def with_relationships_param do def with_relationships_param do
Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships") Operation.parameter(
:with_relationships,
:query,
BooleanLike,
"Embed relationships into accounts."
)
end end
def empty_object_response do def empty_object_response do

View File

@ -19,6 +19,7 @@ def open_api_operation(action) do
apply(__MODULE__, operation, []) apply(__MODULE__, operation, [])
end end
# Note: `with_relationships` param is not supported (PleromaFE uses this op for autocomplete)
def account_search_operation do def account_search_operation do
%Operation{ %Operation{
tags: ["Search"], tags: ["Search"],
@ -45,8 +46,7 @@ def account_search_operation 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"
), )
with_relationships_param()
], ],
responses: %{ responses: %{
200 => 200 =>
@ -139,8 +139,8 @@ def search2_operation 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"
) ),
| pagination_params() with_relationships_param() | pagination_params()
], ],
responses: %{ responses: %{
200 => Operation.response("Results", "application/json", results2()) 200 => Operation.response("Results", "application/json", results2())

View File

@ -7,7 +7,6 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
alias OpenApiSpex.Schema alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.AccountOperation alias Pleroma.Web.ApiSpec.AccountOperation
alias Pleroma.Web.ApiSpec.Schemas.ApiError alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
alias Pleroma.Web.ApiSpec.Schemas.FlakeID alias Pleroma.Web.ApiSpec.Schemas.FlakeID
alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus alias Pleroma.Web.ApiSpec.Schemas.ScheduledStatus
alias Pleroma.Web.ApiSpec.Schemas.Status alias Pleroma.Web.ApiSpec.Schemas.Status
@ -349,10 +348,7 @@ def bookmarks_operation do
summary: "Bookmarked statuses", summary: "Bookmarked statuses",
description: "Statuses the user has bookmarked", description: "Statuses the user has bookmarked",
operationId: "StatusController.bookmarks", operationId: "StatusController.bookmarks",
parameters: [ parameters: pagination_params(),
Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
| pagination_params()
],
security: [%{"oAuth" => ["read:bookmarks"]}], security: [%{"oAuth" => ["read:bookmarks"]}],
responses: %{ responses: %{
200 => Operation.response("Array of Statuses", "application/json", array_of_statuses()) 200 => Operation.response("Array of Statuses", "application/json", array_of_statuses())

View File

@ -27,8 +27,7 @@ def home_operation do
local_param(), local_param(),
with_muted_param(), with_muted_param(),
exclude_visibilities_param(), exclude_visibilities_param(),
reply_visibility_param(), reply_visibility_param() | pagination_params()
with_relationships_param() | pagination_params()
], ],
operationId: "TimelineController.home", operationId: "TimelineController.home",
responses: %{ responses: %{
@ -63,8 +62,7 @@ def public_operation do
only_media_param(), only_media_param(),
with_muted_param(), with_muted_param(),
exclude_visibilities_param(), exclude_visibilities_param(),
reply_visibility_param(), reply_visibility_param() | pagination_params()
with_relationships_param() | pagination_params()
], ],
operationId: "TimelineController.public", operationId: "TimelineController.public",
responses: %{ responses: %{
@ -109,8 +107,7 @@ def hashtag_operation do
local_param(), local_param(),
only_media_param(), only_media_param(),
with_muted_param(), with_muted_param(),
exclude_visibilities_param(), exclude_visibilities_param() | pagination_params()
with_relationships_param() | pagination_params()
], ],
operationId: "TimelineController.hashtag", operationId: "TimelineController.hashtag",
responses: %{ responses: %{
@ -134,8 +131,7 @@ def list_operation do
required: true required: true
), ),
with_muted_param(), with_muted_param(),
exclude_visibilities_param(), exclude_visibilities_param() | pagination_params()
with_relationships_param() | pagination_params()
], ],
operationId: "TimelineController.list", operationId: "TimelineController.list",
responses: %{ responses: %{

View File

@ -104,8 +104,16 @@ 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 with_relationships?(params) do @doc """
# To do: change to `truthy_param?(params["with_relationships"])` once PleromaFE supports it Returns true if request specifies to include embedded relationships in account objects.
not explicitly_falsy_param?(params["with_relationships"]) 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
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,
with_relationships?: 1, embed_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: with_relationships?(params) embed_relationships: embed_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: with_relationships?(params) embed_relationships: embed_relationships?(params)
) )
end end

View File

@ -33,12 +33,10 @@ def account_search(%{assigns: %{user: user}} = conn, %{q: query} = params) do
conn conn
|> put_view(AccountView) |> put_view(AccountView)
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
|> render("index.json", |> render("index.json",
users: accounts, users: accounts,
for: user, for: user,
as: :user, as: :user
embed_relationships: ControllerHelper.with_relationships?(params)
) )
end end
@ -82,7 +80,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.with_relationships?(params), embed_relationships: ControllerHelper.embed_relationships?(params),
for_user: user for_user: user
] ]
|> Enum.filter(&elem(&1, 1)) |> Enum.filter(&elem(&1, 1))
@ -95,7 +93,6 @@ defp resource_search(_, "accounts", query, options) do
users: accounts, users: accounts,
for: options[:for_user], for: options[:for_user],
as: :user, as: :user,
# https://git.pleroma.social/pleroma/pleroma-fe/-/issues/838#note_59223
embed_relationships: options[:embed_relationships] embed_relationships: options[:embed_relationships]
) )
end end