1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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 search_operation do
65 summary: "Search results",
66 security: [%{"oAuth" => ["read:search"]}],
67 operationId: "SearchController.search",
74 "If provided, statuses returned will be authored only by this account"
79 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
82 Operation.parameter(:q, :query, %Schema{type: :string}, "The search query", required: true),
86 %Schema{allOf: [BooleanLike], default: false},
87 "Attempt WebFinger lookup"
92 %Schema{allOf: [BooleanLike], default: false},
93 "Only include accounts that the user is following"
98 %Schema{type: :integer},
101 with_relationships_param() | pagination_params()
104 200 => Operation.response("Results", "application/json", results())
109 def search2_operation do
112 summary: "Search results",
113 security: [%{"oAuth" => ["read:search"]}],
114 operationId: "SearchController.search2",
120 "If provided, statuses returned will be authored only by this account"
125 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
128 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
134 %Schema{allOf: [BooleanLike], default: false},
135 "Attempt WebFinger lookup"
140 %Schema{allOf: [BooleanLike], default: false},
141 "Only include accounts that the user is following"
143 with_relationships_param() | pagination_params()
146 200 => Operation.response("Results", "application/json", results2())
153 title: "SearchResults",
159 description: "Accounts which match the given query"
164 description: "Statuses which match the given query"
169 description: "Hashtags which match the given query"
173 "accounts" => [Account.schema().example],
174 "statuses" => [Status.schema().example],
175 "hashtags" => [Tag.schema().example]
182 title: "SearchResults",
188 description: "Accounts which match the given query"
193 description: "Statuses which match the given query"
197 items: %Schema{type: :string},
198 description: "Hashtags which match the given query"
202 "accounts" => [Account.schema().example],
203 "statuses" => [Status.schema().example],
204 "hashtags" => ["cofe"]