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",
28 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
34 %Schema{type: :integer, default: 40},
35 "Maximum number of results"
40 %Schema{allOf: [BooleanLike], default: false},
41 "Attempt WebFinger lookup. Use this when `q` is an exact address."
46 %Schema{allOf: [BooleanLike], default: false},
47 "Only include accounts that the user is following"
55 AccountOperation.array_of_accounts()
61 def search_operation do
64 summary: "Search results",
65 security: [%{"oAuth" => ["read:search"]}],
66 operationId: "SearchController.search",
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}, "The search query", required: true),
85 %Schema{allOf: [BooleanLike], default: false},
86 "Attempt WebFinger lookup"
91 %Schema{allOf: [BooleanLike], default: false},
92 "Only include accounts that the user is following"
97 %Schema{type: :integer},
100 | pagination_params()
103 200 => Operation.response("Results", "application/json", results())
108 def search2_operation do
111 summary: "Search results",
112 security: [%{"oAuth" => ["read:search"]}],
113 operationId: "SearchController.search2",
119 "If provided, statuses returned will be authored only by this account"
124 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
127 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
133 %Schema{allOf: [BooleanLike], default: false},
134 "Attempt WebFinger lookup"
139 %Schema{allOf: [BooleanLike], default: false},
140 "Only include accounts that the user is following"
142 | pagination_params()
145 200 => Operation.response("Results", "application/json", results2())
152 title: "SearchResults",
158 description: "Accounts which match the given query"
163 description: "Statuses which match the given query"
168 description: "Hashtags which match the given query"
172 "accounts" => [Account.schema().example],
173 "statuses" => [Status.schema().example],
174 "hashtags" => [Tag.schema().example]
181 title: "SearchResults",
187 description: "Accounts which match the given query"
192 description: "Statuses which match the given query"
196 items: %Schema{type: :string},
197 description: "Hashtags which match the given query"
201 "accounts" => [Account.schema().example],
202 "statuses" => [Status.schema().example],
203 "hashtags" => ["cofe"]