1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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.BooleanLike
11 alias Pleroma.Web.ApiSpec.Schemas.PushSubscription
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
18 def create_operation do
20 tags: ["Push subscriptions"],
21 summary: "Subscribe to push notifications",
23 "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.",
24 operationId: "SubscriptionController.create",
25 security: [%{"oAuth" => ["push"]}],
26 requestBody: Helpers.request_body("Parameters", create_request(), required: true),
28 200 => Operation.response("Push subscription", "application/json", PushSubscription),
29 400 => Operation.response("Error", "application/json", ApiError),
30 403 => Operation.response("Error", "application/json", ApiError)
37 tags: ["Push subscriptions"],
38 summary: "Get current subscription",
39 description: "View the PushSubscription currently associated with this access token.",
40 operationId: "SubscriptionController.show",
41 security: [%{"oAuth" => ["push"]}],
43 200 => Operation.response("Push subscription", "application/json", PushSubscription),
44 403 => Operation.response("Error", "application/json", ApiError),
45 404 => Operation.response("Error", "application/json", ApiError)
50 def update_operation do
52 tags: ["Push subscriptions"],
53 summary: "Change types of notifications",
55 "Updates the current push subscription. Only the data part can be updated. To change fundamentals, a new subscription must be created instead.",
56 operationId: "SubscriptionController.update",
57 security: [%{"oAuth" => ["push"]}],
58 requestBody: Helpers.request_body("Parameters", update_request(), required: true),
60 200 => Operation.response("Push subscription", "application/json", PushSubscription),
61 403 => Operation.response("Error", "application/json", ApiError)
66 def delete_operation do
68 tags: ["Push subscriptions"],
69 summary: "Remove current subscription",
70 description: "Removes the current Web Push API subscription.",
71 operationId: "SubscriptionController.delete",
72 security: [%{"oAuth" => ["push"]}],
74 200 => Operation.response("Empty object", "application/json", %Schema{type: :object}),
75 403 => Operation.response("Error", "application/json", ApiError),
76 404 => Operation.response("Error", "application/json", ApiError)
81 defp create_request do
83 title: "SubscriptionCreateRequest",
84 description: "POST body for creating a push subscription",
87 subscription: %Schema{
92 description: "Endpoint URL that is called when a notification event occurs."
100 "User agent public key. Base64 encoded string of public key of ECDH key using `prime256v1` curve."
104 description: "Auth secret. Base64 encoded string of 16 bytes of random data."
107 required: [:p256dh, :auth]
110 required: [:endpoint, :keys]
121 allOf: [BooleanLike],
123 description: "Receive follow notifications?"
126 allOf: [BooleanLike],
128 description: "Receive favourite notifications?"
131 allOf: [BooleanLike],
133 description: "Receive reblog notifications?"
136 allOf: [BooleanLike],
138 description: "Receive mention notifications?"
141 allOf: [BooleanLike],
143 description: "Receive poll notifications?"
145 "pleroma:chat_mention": %Schema{
146 allOf: [BooleanLike],
148 description: "Receive chat notifications?"
150 "pleroma:emoji_reaction": %Schema{
151 allOf: [BooleanLike],
153 description: "Receive emoji reaction notifications?"
160 required: [:subscription],
163 "endpoint" => "https://example.com/example/1234",
165 "auth" => "8eDyX_uCN0XRhSbY5hs7Hg==",
167 "BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA="
181 defp update_request do
183 title: "SubscriptionUpdateRequest",
195 allOf: [BooleanLike],
197 description: "Receive follow notifications?"
200 allOf: [BooleanLike],
202 description: "Receive favourite notifications?"
205 allOf: [BooleanLike],
207 description: "Receive reblog notifications?"
210 allOf: [BooleanLike],
212 description: "Receive mention notifications?"
215 allOf: [BooleanLike],
217 description: "Receive poll notifications?"
219 "pleroma:chat_mention": %Schema{
220 allOf: [BooleanLike],
222 description: "Receive chat notifications?"
224 "pleroma:emoji_reaction": %Schema{
225 allOf: [BooleanLike],
227 description: "Receive emoji reaction notifications?"