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.FilterOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
10 def open_api_operation(action) do
11 operation = String.to_existing_atom("#{action}_operation")
12 apply(__MODULE__, operation, [])
15 def index_operation do
18 summary: "View all filters",
19 operationId: "FilterController.index",
20 security: [%{"oAuth" => ["read:filters"]}],
22 200 => Operation.response("Filters", "application/json", array_of_filters())
27 def create_operation do
30 summary: "Create a filter",
31 operationId: "FilterController.create",
32 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
33 security: [%{"oAuth" => ["write:filters"]}],
34 responses: %{200 => Operation.response("Filter", "application/json", filter())}
41 summary: "View all filters",
42 parameters: [id_param()],
43 operationId: "FilterController.show",
44 security: [%{"oAuth" => ["read:filters"]}],
46 200 => Operation.response("Filter", "application/json", filter())
51 def update_operation do
54 summary: "Update a filter",
55 parameters: [id_param()],
56 operationId: "FilterController.update",
57 requestBody: Helpers.request_body("Parameters", update_request(), required: true),
58 security: [%{"oAuth" => ["write:filters"]}],
60 200 => Operation.response("Filter", "application/json", filter())
65 def delete_operation do
68 summary: "Remove a filter",
69 parameters: [id_param()],
70 operationId: "FilterController.delete",
71 security: [%{"oAuth" => ["write:filters"]}],
74 Operation.response("Filter", "application/json", %Schema{
76 description: "Empty object"
83 Operation.parameter(:id, :path, :string, "Filter ID", example: "123", required: true)
91 id: %Schema{type: :string},
92 phrase: %Schema{type: :string, description: "The text to be filtered"},
95 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
96 description: "The contexts in which the filter should be applied."
100 format: :"date-time",
102 "When the filter should no longer be applied. String (ISO 8601 Datetime), or null if the filter does not expire.",
105 irreversible: %Schema{
108 "Should matching entities in home and notifications be dropped by the server?"
112 description: "Should the filter consider word boundaries?"
117 "phrase" => "@twitter.com",
124 "whole_word" => false,
126 "irreversible" => true
131 defp array_of_filters do
133 title: "ArrayOfFilters",
134 description: "Array of Filters",
140 "phrase" => "@twitter.com",
147 "whole_word" => false,
149 "irreversible" => true
153 "phrase" => ":eurovision2019:",
157 "whole_word" => true,
158 "expires_at" => "2019-05-21T13:47:31.333Z",
159 "irreversible" => false
165 defp create_request do
167 title: "FilterCreateRequest",
173 irreversible: %Schema{
176 "Should the server irreversibly drop matching entities from home and notifications?",
183 "phrase" => "knights",
184 "context" => ["home"]
189 defp update_request do
191 title: "FilterUpdateRequest",
194 phrase: %Schema{type: :string, description: "The text to be filtered"},
197 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
199 "Array of enumerable strings `home`, `notifications`, `public`, `thread`. At least one context must be specified."
201 irreversible: %Schema{
204 "Should the server irreversibly drop matching entities from home and notifications?"
208 description: "Consider word boundaries?",
211 # TODO: probably should implement filter expiration
212 # expires_in: %Schema{
214 # format: :"date-time",
216 # "ISO 8601 Datetime for when the filter expires. Otherwise,
217 # null for a filter that doesn't expire."
220 required: [:phrase, :context],
222 "phrase" => "knights",
223 "context" => ["home"]