remove all endpoints marked as deprecated (#91)
[akkoma] / lib / pleroma / web / api_spec / operations / search_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
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
14
15 import Pleroma.Web.ApiSpec.Helpers
16
17 def open_api_operation(action) do
18 operation = String.to_existing_atom("#{action}_operation")
19 apply(__MODULE__, operation, [])
20 end
21
22 # Note: `with_relationships` param is not supported (PleromaFE uses this op for autocomplete)
23 def account_search_operation do
24 %Operation{
25 tags: ["Search"],
26 summary: "Search for matching accounts by username or display name",
27 operationId: "SearchController.account_search",
28 parameters: [
29 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
30 required: true
31 ),
32 Operation.parameter(
33 :limit,
34 :query,
35 %Schema{type: :integer, default: 40},
36 "Maximum number of results"
37 ),
38 Operation.parameter(
39 :resolve,
40 :query,
41 %Schema{allOf: [BooleanLike], default: false},
42 "Attempt WebFinger lookup. Use this when `q` is an exact address."
43 ),
44 Operation.parameter(
45 :following,
46 :query,
47 %Schema{allOf: [BooleanLike], default: false},
48 "Only include accounts that the user is following"
49 )
50 ],
51 responses: %{
52 200 =>
53 Operation.response(
54 "Array of Account",
55 "application/json",
56 AccountOperation.array_of_accounts()
57 )
58 }
59 }
60 end
61
62 def search2_operation do
63 %Operation{
64 tags: ["Search"],
65 summary: "Search results",
66 security: [%{"oAuth" => ["read:search"]}],
67 operationId: "SearchController.search2",
68 parameters: [
69 Operation.parameter(
70 :account_id,
71 :query,
72 FlakeID,
73 "If provided, statuses returned will be authored only by this account"
74 ),
75 Operation.parameter(
76 :type,
77 :query,
78 %Schema{type: :string, enum: ["accounts", "hashtags", "statuses"]},
79 "Search type"
80 ),
81 Operation.parameter(:q, :query, %Schema{type: :string}, "What to search for",
82 required: true
83 ),
84 Operation.parameter(
85 :resolve,
86 :query,
87 %Schema{allOf: [BooleanLike], default: false},
88 "Attempt WebFinger lookup"
89 ),
90 Operation.parameter(
91 :following,
92 :query,
93 %Schema{allOf: [BooleanLike], default: false},
94 "Only include accounts that the user is following"
95 ),
96 with_relationships_param() | pagination_params()
97 ],
98 responses: %{
99 200 => Operation.response("Results", "application/json", results2())
100 }
101 }
102 end
103
104 defp results2 do
105 %Schema{
106 title: "SearchResults",
107 type: :object,
108 properties: %{
109 accounts: %Schema{
110 type: :array,
111 items: Account,
112 description: "Accounts which match the given query"
113 },
114 statuses: %Schema{
115 type: :array,
116 items: Status,
117 description: "Statuses which match the given query"
118 },
119 hashtags: %Schema{
120 type: :array,
121 items: Tag,
122 description: "Hashtags which match the given query"
123 }
124 },
125 example: %{
126 "accounts" => [Account.schema().example],
127 "statuses" => [Status.schema().example],
128 "hashtags" => [Tag.schema().example]
129 }
130 }
131 end
132 end