spc-pleroma/lib/pleroma/web/api_spec/operations/pleroma_backup_operation.ex

84 lines
2.6 KiB
Elixir
Raw Normal View History

2020-09-08 21:04:00 +00:00
# Pleroma: A lightweight social networking server
2022-02-26 06:11:42 +00:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-09-08 21:04:00 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.PleromaBackupOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.ApiError
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
apply(__MODULE__, operation, [])
end
def index_operation do
%Operation{
tags: ["Backups"],
summary: "List backups",
security: [%{"oAuth" => ["read:backups"]}],
2020-09-08 21:04:00 +00:00
operationId: "PleromaAPI.BackupController.index",
responses: %{
200 =>
Operation.response(
"An array of backups",
"application/json",
%Schema{
type: :array,
items: backup()
}
),
400 => Operation.response("Bad Request", "application/json", ApiError)
}
}
end
def create_operation do
%Operation{
tags: ["Backups"],
summary: "Create a backup",
security: [%{"oAuth" => ["read:backups"]}],
2020-09-08 21:04:00 +00:00
operationId: "PleromaAPI.BackupController.create",
responses: %{
200 =>
Operation.response(
"An array of backups",
"application/json",
%Schema{
type: :array,
items: backup()
}
),
400 => Operation.response("Bad Request", "application/json", ApiError)
}
}
end
defp backup do
%Schema{
title: "Backup",
description: "Response schema for a backup",
type: :object,
properties: %{
inserted_at: %Schema{type: :string, format: :"date-time"},
content_type: %Schema{type: :string},
file_name: %Schema{type: :string},
file_size: %Schema{type: :integer},
2022-12-16 19:10:48 +00:00
processed: %Schema{type: :boolean, description: "whether this backup has succeeded"},
state: %Schema{type: :string, description: "the state of the backup", enum: ["pending", "running", "complete", "failed"]},
processed_number: %Schema{type: :integer, description: "the number of records processed"}
2020-09-08 21:04:00 +00:00
},
example: %{
"content_type" => "application/zip",
"file_name" =>
2020-09-09 16:02:20 +00:00
"https://cofe.fe:4000/media/backups/archive-foobar-20200908T164207-Yr7vuT5Wycv-sN3kSN2iJ0k-9pMo60j9qmvRCdDqIew.zip",
"file_size" => 4105,
"inserted_at" => "2020-09-08T16:42:07.000Z",
2022-12-16 19:10:48 +00:00
"processed" => true,
"state" => "complete",
"processed_number": 20
2020-09-08 21:04:00 +00:00
}
}
end
end