Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / lib / pleroma / web / api_spec / operations / admin / config_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Admin.ConfigOperation 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 show_operation do
18 %Operation{
19 tags: ["Instance configuration"],
20 summary: "Retrieve instance configuration",
21 operationId: "AdminAPI.ConfigController.show",
22 parameters: [
23 Operation.parameter(
24 :only_db,
25 :query,
26 %Schema{type: :boolean, default: false},
27 "Get only saved in database settings"
28 )
29 | admin_api_params()
30 ],
31 security: [%{"oAuth" => ["admin:read"]}],
32 responses: %{
33 200 => Operation.response("Config", "application/json", config_response()),
34 400 => Operation.response("Bad Request", "application/json", ApiError)
35 }
36 }
37 end
38
39 def update_operation do
40 %Operation{
41 tags: ["Instance configuration"],
42 summary: "Update instance configuration",
43 operationId: "AdminAPI.ConfigController.update",
44 security: [%{"oAuth" => ["admin:write"]}],
45 parameters: admin_api_params(),
46 requestBody:
47 request_body("Parameters", %Schema{
48 type: :object,
49 properties: %{
50 configs: %Schema{
51 type: :array,
52 items: %Schema{
53 type: :object,
54 properties: %{
55 group: %Schema{type: :string},
56 key: %Schema{type: :string},
57 value: any(),
58 delete: %Schema{type: :boolean},
59 subkeys: %Schema{type: :array, items: %Schema{type: :string}}
60 }
61 }
62 }
63 }
64 }),
65 responses: %{
66 200 => Operation.response("Config", "application/json", config_response()),
67 400 => Operation.response("Bad Request", "application/json", ApiError)
68 }
69 }
70 end
71
72 def descriptions_operation do
73 %Operation{
74 tags: ["Instance configuration"],
75 summary: "Retrieve config description",
76 operationId: "AdminAPI.ConfigController.descriptions",
77 security: [%{"oAuth" => ["admin:read"]}],
78 parameters: admin_api_params(),
79 responses: %{
80 200 =>
81 Operation.response("Config Descriptions", "application/json", %Schema{
82 type: :array,
83 items: %Schema{
84 type: :object,
85 properties: %{
86 group: %Schema{type: :string},
87 key: %Schema{type: :string},
88 type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
89 description: %Schema{type: :string},
90 children: %Schema{
91 type: :array,
92 items: %Schema{
93 type: :object,
94 properties: %{
95 key: %Schema{type: :string},
96 type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
97 description: %Schema{type: :string},
98 suggestions: %Schema{type: :array}
99 }
100 }
101 }
102 }
103 }
104 }),
105 400 => Operation.response("Bad Request", "application/json", ApiError)
106 }
107 }
108 end
109
110 defp any do
111 %Schema{
112 oneOf: [
113 %Schema{type: :array},
114 %Schema{type: :object},
115 %Schema{type: :string},
116 %Schema{type: :integer},
117 %Schema{type: :boolean}
118 ]
119 }
120 end
121
122 defp config_response do
123 %Schema{
124 type: :object,
125 properties: %{
126 configs: %Schema{
127 type: :array,
128 items: %Schema{
129 type: :object,
130 properties: %{
131 group: %Schema{type: :string},
132 key: %Schema{type: :string},
133 value: any()
134 }
135 }
136 },
137 need_reboot: %Schema{
138 type: :boolean,
139 description:
140 "If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect"
141 }
142 }
143 }
144 end
145 end