1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def index_operation do
20 summary: "All filters",
21 operationId: "FilterController.index",
22 security: [%{"oAuth" => ["read:filters"]}],
24 200 => Operation.response("Filters", "application/json", array_of_filters()),
25 403 => Operation.response("Error", "application/json", ApiError)
30 def create_operation do
33 summary: "Create a filter",
34 operationId: "FilterController.create",
35 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
36 security: [%{"oAuth" => ["write:filters"]}],
38 200 => Operation.response("Filter", "application/json", filter()),
39 403 => Operation.response("Error", "application/json", ApiError)
48 parameters: [id_param()],
49 operationId: "FilterController.show",
50 security: [%{"oAuth" => ["read:filters"]}],
52 200 => Operation.response("Filter", "application/json", filter()),
53 403 => Operation.response("Error", "application/json", ApiError),
54 404 => Operation.response("Error", "application/json", ApiError)
59 def update_operation do
62 summary: "Update a filter",
63 parameters: [id_param()],
64 operationId: "FilterController.update",
65 requestBody: Helpers.request_body("Parameters", update_request(), required: true),
66 security: [%{"oAuth" => ["write:filters"]}],
68 200 => Operation.response("Filter", "application/json", filter()),
69 403 => Operation.response("Error", "application/json", ApiError)
74 def delete_operation do
77 summary: "Remove a filter",
78 parameters: [id_param()],
79 operationId: "FilterController.delete",
80 security: [%{"oAuth" => ["write:filters"]}],
83 Operation.response("Filter", "application/json", %Schema{
85 description: "Empty object"
87 403 => Operation.response("Error", "application/json", ApiError)
93 Operation.parameter(:id, :path, :string, "Filter ID", example: "123", required: true)
101 id: %Schema{type: :string},
102 phrase: %Schema{type: :string, description: "The text to be filtered"},
105 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
106 description: "The contexts in which the filter should be applied."
110 format: :"date-time",
112 "When the filter should no longer be applied. String (ISO 8601 Datetime), or null if the filter does not expire.",
115 irreversible: %Schema{
118 "Should matching entities in home and notifications be dropped by the server?"
122 description: "Should the filter consider word boundaries?"
127 "phrase" => "@twitter.com",
134 "whole_word" => false,
136 "irreversible" => true
141 defp array_of_filters do
143 title: "ArrayOfFilters",
144 description: "Array of Filters",
150 "phrase" => "@twitter.com",
157 "whole_word" => false,
159 "irreversible" => true
163 "phrase" => ":eurovision2019:",
167 "whole_word" => true,
168 "expires_at" => "2019-05-21T13:47:31.333Z",
169 "irreversible" => false
175 defp create_request do
177 title: "FilterCreateRequest",
183 irreversible: %Schema{
184 allOf: [BooleanLike],
186 "Should the server irreversibly drop matching entities from home and notifications?",
193 "phrase" => "knights",
194 "context" => ["home"]
199 defp update_request do
201 title: "FilterUpdateRequest",
204 phrase: %Schema{type: :string, description: "The text to be filtered"},
207 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
209 "Array of enumerable strings `home`, `notifications`, `public`, `thread`. At least one context must be specified."
211 irreversible: %Schema{
212 allOf: [BooleanLike],
215 "Should the server irreversibly drop matching entities from home and notifications?"
218 allOf: [BooleanLike],
220 description: "Consider word boundaries?",
227 "Number of seconds from now the filter should expire. Otherwise, null for a filter that doesn't expire."
230 required: [:phrase, :context],
232 "phrase" => "knights",
233 "context" => ["home"]