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.SubscriptionOperation 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.PushSubscription
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def create_operation do
19 tags: ["Push Subscriptions"],
20 summary: "Subscribe to push notifications",
22 "Add a Web Push API subscription to receive notifications. Each access token can have one push subscription. If you create a new subscription, the old subscription is deleted.",
23 operationId: "SubscriptionController.create",
24 security: [%{"oAuth" => ["push"]}],
25 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
27 200 => Operation.response("Push Subscription", "application/json", PushSubscription),
28 400 => Operation.response("Error", "application/json", ApiError),
29 403 => Operation.response("Error", "application/json", ApiError)
36 tags: ["Push Subscriptions"],
37 summary: "Get current subscription",
38 description: "View the PushSubscription currently associated with this access token.",
39 operationId: "SubscriptionController.show",
40 security: [%{"oAuth" => ["push"]}],
42 200 => Operation.response("Push Subscription", "application/json", PushSubscription),
43 403 => Operation.response("Error", "application/json", ApiError),
44 404 => Operation.response("Error", "application/json", ApiError)
49 def update_operation do
51 tags: ["Push Subscriptions"],
52 summary: "Change types of notifications",
54 "Updates the current push subscription. Only the data part can be updated. To change fundamentals, a new subscription must be created instead.",
55 operationId: "SubscriptionController.update",
56 security: [%{"oAuth" => ["push"]}],
57 requestBody: Helpers.request_body("Parameters", update_request(), required: true),
59 200 => Operation.response("Push Subscription", "application/json", PushSubscription),
60 403 => Operation.response("Error", "application/json", ApiError)
65 def delete_operation do
67 tags: ["Push Subscriptions"],
68 summary: "Remove current subscription",
69 description: "Removes the current Web Push API subscription.",
70 operationId: "SubscriptionController.delete",
71 security: [%{"oAuth" => ["push"]}],
73 200 => Operation.response("Empty object", "application/json", %Schema{type: :object}),
74 403 => Operation.response("Error", "application/json", ApiError),
75 404 => Operation.response("Error", "application/json", ApiError)
80 defp create_request do
82 title: "SubscriptionCreateRequest",
83 description: "POST body for creating a push subscription",
86 subscription: %Schema{
91 description: "Endpoint URL that is called when a notification event occurs."
99 "User agent public key. Base64 encoded string of public key of ECDH key using `prime256v1` curve."
103 description: "Auth secret. Base64 encoded string of 16 bytes of random data."
106 required: [:p256dh, :auth]
109 required: [:endpoint, :keys]
117 follow: %Schema{type: :boolean, description: "Receive follow notifications?"},
120 description: "Receive favourite notifications?"
122 reblog: %Schema{type: :boolean, description: "Receive reblog notifications?"},
123 mention: %Schema{type: :boolean, description: "Receive mention notifications?"},
124 poll: %Schema{type: :boolean, description: "Receive poll notifications?"}
130 required: [:subscription],
133 "endpoint" => "https://example.com/example/1234",
135 "auth" => "8eDyX_uCN0XRhSbY5hs7Hg==",
137 "BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA="
151 defp update_request do
153 title: "SubscriptionUpdateRequest",
162 follow: %Schema{type: :boolean, description: "Receive follow notifications?"},
165 description: "Receive favourite notifications?"
167 reblog: %Schema{type: :boolean, description: "Receive reblog notifications?"},
168 mention: %Schema{type: :boolean, description: "Receive mention notifications?"},
169 poll: %Schema{type: :boolean, description: "Receive poll notifications?"}