9d7d017a2300ded18ec37a8f258864f430a26d39
[akkoma] / lib / pleroma / web / api_spec / operations / admin / frontend_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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: ["Admin", "Reports"],
20 summary: "Get a list of available frontends",
21 operationId: "AdminAPI.FrontendController.index",
22 security: [%{"oAuth" => ["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: ["Admin", "Reports"],
33 summary: "Install a frontend",
34 operationId: "AdminAPI.FrontendController.install",
35 security: [%{"oAuth" => ["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 }
41 }
42 end
43
44 defp list_of_frontends do
45 %Schema{
46 type: :array,
47 items: %Schema{
48 type: :object,
49 properties: %{
50 name: %Schema{type: :string},
51 git: %Schema{type: :string, format: :uri, nullable: true},
52 build_url: %Schema{type: :string, format: :uri, nullable: true},
53 ref: %Schema{type: :string},
54 installed: %Schema{type: :boolean}
55 }
56 }
57 }
58 end
59
60 defp install_request do
61 %Schema{
62 title: "FrontendInstallRequest",
63 type: :object,
64 required: [:name],
65 properties: %{
66 name: %Schema{
67 type: :string
68 },
69 ref: %Schema{
70 type: :string
71 },
72 file: %Schema{
73 type: :string
74 },
75 build_url: %Schema{
76 type: :string
77 },
78 build_dir: %Schema{
79 type: :string
80 }
81 }
82 }
83 end
84 end