total rebase
[anni] / lib / pleroma / web / api_spec / operations / pleroma_notification_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaNotificationOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8   alias Pleroma.Web.ApiSpec.NotificationOperation
9   alias Pleroma.Web.ApiSpec.Schemas.ApiError
10
11   import Pleroma.Web.ApiSpec.Helpers
12
13   def open_api_operation(action) do
14     operation = String.to_existing_atom("#{action}_operation")
15     apply(__MODULE__, operation, [])
16   end
17
18   def mark_as_read_operation do
19     %Operation{
20       tags: ["Notifications"],
21       summary: "Mark notifications as read",
22       description: "Query parameters are mutually exclusive.",
23       requestBody:
24         request_body("Parameters", %Schema{
25           type: :object,
26           properties: %{
27             id: %Schema{type: :integer, description: "A single notification ID to read"},
28             max_id: %Schema{type: :integer, description: "Read all notifications up to this ID"}
29           }
30         }),
31       security: [%{"oAuth" => ["write:notifications"]}],
32       operationId: "PleromaAPI.NotificationController.mark_as_read",
33       responses: %{
34         200 =>
35           Operation.response(
36             "A Notification or array of Notifications",
37             "application/json",
38             %Schema{
39               anyOf: [
40                 %Schema{type: :array, items: NotificationOperation.notification()},
41                 NotificationOperation.notification()
42               ]
43             }
44           ),
45         400 => Operation.response("Bad Request", "application/json", ApiError)
46       }
47     }
48   end
49 end