First
[anni] / lib / pleroma / web / api_spec / operations / admin / frontend_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.Admin.FrontendOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8   alias Pleroma.Web.ApiSpec.Schemas.ApiError
9
10   import Pleroma.Web.ApiSpec.Helpers
11
12   def open_api_operation(action) do
13     operation = String.to_existing_atom("#{action}_operation")
14     apply(__MODULE__, operation, [])
15   end
16
17   def index_operation do
18     %Operation{
19       tags: ["Frontend managment"],
20       summary: "Retrieve a list of available frontends",
21       operationId: "AdminAPI.FrontendController.index",
22       security: [%{"oAuth" => ["admin:read"]}],
23       responses: %{
24         200 => Operation.response("Response", "application/json", list_of_frontends()),
25         403 => Operation.response("Forbidden", "application/json", ApiError)
26       }
27     }
28   end
29
30   def install_operation do
31     %Operation{
32       tags: ["Frontend managment"],
33       summary: "Install a frontend",
34       operationId: "AdminAPI.FrontendController.install",
35       security: [%{"oAuth" => ["admin:read"]}],
36       requestBody: request_body("Parameters", install_request(), required: true),
37       responses: %{
38         200 => Operation.response("Response", "application/json", list_of_frontends()),
39         403 => Operation.response("Forbidden", "application/json", ApiError),
40         400 => Operation.response("Error", "application/json", ApiError)
41       }
42     }
43   end
44
45   defp list_of_frontends do
46     %Schema{
47       type: :array,
48       items: %Schema{
49         type: :object,
50         properties: %{
51           name: %Schema{type: :string},
52           git: %Schema{type: :string, format: :uri, nullable: true},
53           build_url: %Schema{type: :string, format: :uri, nullable: true},
54           ref: %Schema{type: :string},
55           installed: %Schema{type: :boolean}
56         }
57       }
58     }
59   end
60
61   defp install_request do
62     %Schema{
63       title: "FrontendInstallRequest",
64       type: :object,
65       required: [:name],
66       properties: %{
67         name: %Schema{
68           type: :string
69         },
70         ref: %Schema{
71           type: :string
72         },
73         file: %Schema{
74           type: :string
75         },
76         build_url: %Schema{
77           type: :string
78         },
79         build_dir: %Schema{
80           type: :string
81         }
82       }
83     }
84   end
85 end