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
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
11 def open_api_operation(action) do
12 operation = String.to_existing_atom("#{action}_operation")
13 apply(__MODULE__, operation, [])
16 def index_operation do
19 summary: "View all filters",
20 operationId: "FilterController.index",
21 security: [%{"oAuth" => ["read:filters"]}],
23 200 => Operation.response("Filters", "application/json", array_of_filters())
28 def create_operation do
31 summary: "Create a filter",
32 operationId: "FilterController.create",
33 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
34 security: [%{"oAuth" => ["write:filters"]}],
35 responses: %{200 => Operation.response("Filter", "application/json", filter())}
42 summary: "View all filters",
43 parameters: [id_param()],
44 operationId: "FilterController.show",
45 security: [%{"oAuth" => ["read:filters"]}],
47 200 => Operation.response("Filter", "application/json", filter())
52 def update_operation do
55 summary: "Update a filter",
56 parameters: [id_param()],
57 operationId: "FilterController.update",
58 requestBody: Helpers.request_body("Parameters", update_request(), required: true),
59 security: [%{"oAuth" => ["write:filters"]}],
61 200 => Operation.response("Filter", "application/json", filter())
66 def delete_operation do
69 summary: "Remove a filter",
70 parameters: [id_param()],
71 operationId: "FilterController.delete",
72 security: [%{"oAuth" => ["write:filters"]}],
75 Operation.response("Filter", "application/json", %Schema{
77 description: "Empty object"
84 Operation.parameter(:id, :path, :string, "Filter ID", example: "123", required: true)
92 id: %Schema{type: :string},
93 phrase: %Schema{type: :string, description: "The text to be filtered"},
96 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
97 description: "The contexts in which the filter should be applied."
101 format: :"date-time",
103 "When the filter should no longer be applied. String (ISO 8601 Datetime), or null if the filter does not expire.",
106 irreversible: %Schema{
109 "Should matching entities in home and notifications be dropped by the server?"
113 description: "Should the filter consider word boundaries?"
118 "phrase" => "@twitter.com",
125 "whole_word" => false,
127 "irreversible" => true
132 defp array_of_filters do
134 title: "ArrayOfFilters",
135 description: "Array of Filters",
141 "phrase" => "@twitter.com",
148 "whole_word" => false,
150 "irreversible" => true
154 "phrase" => ":eurovision2019:",
158 "whole_word" => true,
159 "expires_at" => "2019-05-21T13:47:31.333Z",
160 "irreversible" => false
166 defp create_request do
168 title: "FilterCreateRequest",
174 irreversible: %Schema{
175 allOf: [BooleanLike],
177 "Should the server irreversibly drop matching entities from home and notifications?",
184 "phrase" => "knights",
185 "context" => ["home"]
190 defp update_request do
192 title: "FilterUpdateRequest",
195 phrase: %Schema{type: :string, description: "The text to be filtered"},
198 items: %Schema{type: :string, enum: ["home", "notifications", "public", "thread"]},
200 "Array of enumerable strings `home`, `notifications`, `public`, `thread`. At least one context must be specified."
202 irreversible: %Schema{
203 allOf: [BooleanLike],
206 "Should the server irreversibly drop matching entities from home and notifications?"
209 allOf: [BooleanLike],
211 description: "Consider word boundaries?",
214 # TODO: probably should implement filter expiration
215 # expires_in: %Schema{
217 # format: :"date-time",
219 # "ISO 8601 Datetime for when the filter expires. Otherwise,
220 # null for a filter that doesn't expire."
223 required: [:phrase, :context],
225 "phrase" => "knights",
226 "context" => ["home"]