total rebase
[anni] / lib / pleroma / web / api_spec / operations / pleroma_backup_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.PleromaBackupOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8   alias Pleroma.Web.ApiSpec.Schemas.ApiError
9
10   def open_api_operation(action) do
11     operation = String.to_existing_atom("#{action}_operation")
12     apply(__MODULE__, operation, [])
13   end
14
15   def index_operation do
16     %Operation{
17       tags: ["Backups"],
18       summary: "List backups",
19       security: [%{"oAuth" => ["read:backups"]}],
20       operationId: "PleromaAPI.BackupController.index",
21       responses: %{
22         200 =>
23           Operation.response(
24             "An array of backups",
25             "application/json",
26             %Schema{
27               type: :array,
28               items: backup()
29             }
30           ),
31         400 => Operation.response("Bad Request", "application/json", ApiError)
32       }
33     }
34   end
35
36   def create_operation do
37     %Operation{
38       tags: ["Backups"],
39       summary: "Create a backup",
40       security: [%{"oAuth" => ["read:backups"]}],
41       operationId: "PleromaAPI.BackupController.create",
42       responses: %{
43         200 =>
44           Operation.response(
45             "An array of backups",
46             "application/json",
47             %Schema{
48               type: :array,
49               items: backup()
50             }
51           ),
52         400 => Operation.response("Bad Request", "application/json", ApiError)
53       }
54     }
55   end
56
57   defp backup do
58     %Schema{
59       title: "Backup",
60       description: "Response schema for a backup",
61       type: :object,
62       properties: %{
63         inserted_at: %Schema{type: :string, format: :"date-time"},
64         content_type: %Schema{type: :string},
65         file_name: %Schema{type: :string},
66         file_size: %Schema{type: :integer},
67         processed: %Schema{type: :boolean, description: "whether this backup has succeeded"},
68         state: %Schema{
69           type: :string,
70           description: "the state of the backup",
71           enum: ["pending", "running", "complete", "failed"]
72         },
73         processed_number: %Schema{type: :integer, description: "the number of records processed"}
74       },
75       example: %{
76         "content_type" => "application/zip",
77         "file_name" =>
78           "https://cofe.fe:4000/media/backups/archive-foobar-20200908T164207-Yr7vuT5Wycv-sN3kSN2iJ0k-9pMo60j9qmvRCdDqIew.zip",
79         "file_size" => 4105,
80         "inserted_at" => "2020-09-08T16:42:07.000Z",
81         "processed" => true,
82         "state" => "complete",
83         "processed_number" => 20
84       }
85     }
86   end
87 end