1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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 def account_search_operation do
25 summary: "Search for matching accounts by username or display name",
26 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"
50 ] ++ [embed_relationships_param()],
56 AccountOperation.array_of_accounts()
62 def search_operation do
65 summary: "Search results",
66 security: [%{"oAuth" => ["read:search"]}],
67 operationId: "SearchController.search",
75 "If provided, statuses returned will be authored only by this account"
80 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
83 Operation.parameter(:q, :query, %Schema{type: :string}, "The search query",
89 %Schema{allOf: [BooleanLike], default: false},
90 "Attempt WebFinger lookup"
95 %Schema{allOf: [BooleanLike], default: false},
96 "Only include accounts that the user is following"
101 %Schema{type: :integer},
104 ] ++ pagination_params() ++ [embed_relationships_param()],
106 200 => Operation.response("Results", "application/json", results())
111 def search2_operation do
114 summary: "Search results",
115 security: [%{"oAuth" => ["read:search"]}],
116 operationId: "SearchController.search2",
122 "If provided, statuses returned will be authored only by this account"
127 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
130 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
136 %Schema{allOf: [BooleanLike], default: false},
137 "Attempt WebFinger lookup"
142 %Schema{allOf: [BooleanLike], default: false},
143 "Only include accounts that the user is following"
145 | pagination_params()
148 200 => Operation.response("Results", "application/json", results2())
155 title: "SearchResults",
161 description: "Accounts which match the given query"
166 description: "Statuses which match the given query"
171 description: "Hashtags which match the given query"
175 "accounts" => [Account.schema().example],
176 "statuses" => [Status.schema().example],
177 "hashtags" => [Tag.schema().example]
184 title: "SearchResults",
190 description: "Accounts which match the given query"
195 description: "Statuses which match the given query"
199 items: %Schema{type: :string},
200 description: "Hashtags which match the given query"
204 "accounts" => [Account.schema().example],
205 "statuses" => [Status.schema().example],
206 "hashtags" => ["cofe"]