Merge branch 'bugfix/mix.exs-version-dot-git-less' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / admin / config_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.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: ["Admin", "Config"],
20 summary: "Get list of merged default settings with saved in database",
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 ],
30 security: [%{"oAuth" => ["read"]}],
31 responses: %{
32 200 => Operation.response("Config", "application/json", config_response()),
33 400 => Operation.response("Bad Request", "application/json", ApiError)
34 }
35 }
36 end
37
38 def update_operation do
39 %Operation{
40 tags: ["Admin", "Config"],
41 summary: "Update config settings",
42 operationId: "AdminAPI.ConfigController.update",
43 security: [%{"oAuth" => ["write"]}],
44 requestBody:
45 request_body("Parameters", %Schema{
46 type: :object,
47 properties: %{
48 configs: %Schema{
49 type: :array,
50 items: %Schema{
51 type: :object,
52 properties: %{
53 group: %Schema{type: :string},
54 key: %Schema{type: :string},
55 value: any(),
56 delete: %Schema{type: :boolean},
57 subkeys: %Schema{type: :array, items: %Schema{type: :string}}
58 }
59 }
60 }
61 }
62 }),
63 responses: %{
64 200 => Operation.response("Config", "application/json", config_response()),
65 400 => Operation.response("Bad Request", "application/json", ApiError)
66 }
67 }
68 end
69
70 def descriptions_operation do
71 %Operation{
72 tags: ["Admin", "Config"],
73 summary: "Get JSON with config descriptions.",
74 operationId: "AdminAPI.ConfigController.descriptions",
75 security: [%{"oAuth" => ["read"]}],
76 responses: %{
77 200 =>
78 Operation.response("Config Descriptions", "application/json", %Schema{
79 type: :array,
80 items: %Schema{
81 type: :object,
82 properties: %{
83 group: %Schema{type: :string},
84 key: %Schema{type: :string},
85 type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
86 description: %Schema{type: :string},
87 children: %Schema{
88 type: :array,
89 items: %Schema{
90 type: :object,
91 properties: %{
92 key: %Schema{type: :string},
93 type: %Schema{oneOf: [%Schema{type: :string}, %Schema{type: :array}]},
94 description: %Schema{type: :string},
95 suggestions: %Schema{type: :array}
96 }
97 }
98 }
99 }
100 }
101 }),
102 400 => Operation.response("Bad Request", "application/json", ApiError)
103 }
104 }
105 end
106
107 defp any do
108 %Schema{
109 oneOf: [
110 %Schema{type: :array},
111 %Schema{type: :object},
112 %Schema{type: :string},
113 %Schema{type: :integer},
114 %Schema{type: :boolean}
115 ]
116 }
117 end
118
119 defp config_response do
120 %Schema{
121 type: :object,
122 properties: %{
123 configs: %Schema{
124 type: :array,
125 items: %Schema{
126 type: :object,
127 properties: %{
128 group: %Schema{type: :string},
129 key: %Schema{type: :string},
130 value: any()
131 }
132 }
133 },
134 need_reboot: %Schema{
135 type: :boolean,
136 description:
137 "If `need_reboot` is `true`, instance must be restarted, so reboot time settings can take effect"
138 }
139 }
140 }
141 end
142 end