1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.SearchOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.AccountOperation
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
11 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
12 alias Pleroma.Web.ApiSpec.Schemas.Status
13 alias Pleroma.Web.ApiSpec.Schemas.Tag
15 import Pleroma.Web.ApiSpec.Helpers
17 def open_api_operation(action) do
18 operation = String.to_existing_atom("#{action}_operation")
19 apply(__MODULE__, operation, [])
22 # Note: `with_relationships` param is not supported (PleromaFE uses this op for autocomplete)
23 def account_search_operation do
26 summary: "Search for matching accounts by username or display name",
27 operationId: "SearchController.account_search",
29 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
35 %Schema{type: :integer, default: 40},
36 "Maximum number of results"
41 %Schema{allOf: [BooleanLike], default: false},
42 "Attempt WebFinger lookup. Use this when `q` is an exact address."
47 %Schema{allOf: [BooleanLike], default: false},
48 "Only include accounts that the user is following"
56 AccountOperation.array_of_accounts()
62 def search2_operation do
65 summary: "Search results",
66 security: [%{"oAuth" => ["read:search"]}],
67 operationId: "SearchController.search2",
73 "If provided, statuses returned will be authored only by this account"
78 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
81 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
87 %Schema{allOf: [BooleanLike], default: false},
88 "Attempt WebFinger lookup"
93 %Schema{allOf: [BooleanLike], default: false},
94 "Only include accounts that the user is following"
96 with_relationships_param() | pagination_params()
99 200 => Operation.response("Results", "application/json", results2())
106 title: "SearchResults",
112 description: "Accounts which match the given query"
117 description: "Statuses which match the given query"
122 description: "Hashtags which match the given query"
126 "accounts" => [Account.schema().example],
127 "statuses" => [Status.schema().example],
128 "hashtags" => [Tag.schema().example]