First
[anni] / lib / pleroma / web / api_spec / operations / pleroma_settings_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.PleromaSettingsOperation do
6   alias OpenApiSpex.Operation
7   alias OpenApiSpex.Schema
8
9   import Pleroma.Web.ApiSpec.Helpers
10
11   def open_api_operation(action) do
12     operation = String.to_existing_atom("#{action}_operation")
13     apply(__MODULE__, operation, [])
14   end
15
16   def show_operation do
17     %Operation{
18       tags: ["Settings"],
19       summary: "Get settings for an application",
20       description: "Get synchronized settings for an application",
21       operationId: "SettingsController.show",
22       parameters: [app_name_param()],
23       security: [%{"oAuth" => ["read:accounts"]}],
24       responses: %{
25         200 => Operation.response("object", "application/json", object())
26       }
27     }
28   end
29
30   def update_operation do
31     %Operation{
32       tags: ["Settings"],
33       summary: "Update settings for an application",
34       description: "Update synchronized settings for an application",
35       operationId: "SettingsController.update",
36       parameters: [app_name_param()],
37       security: [%{"oAuth" => ["write:accounts"]}],
38       requestBody: request_body("Parameters", update_request(), required: true),
39       responses: %{
40         200 => Operation.response("object", "application/json", object())
41       }
42     }
43   end
44
45   def app_name_param do
46     Operation.parameter(:app, :path, %Schema{type: :string}, "Application name",
47       example: "pleroma-fe",
48       required: true
49     )
50   end
51
52   def object do
53     %Schema{
54       title: "Settings object",
55       description: "The object that contains settings for the application.",
56       type: :object
57     }
58   end
59
60   def update_request do
61     %Schema{
62       title: "SettingsUpdateRequest",
63       type: :object,
64       description:
65         "The settings object to be merged with the current settings. To remove a field, set it to null.",
66       example: %{
67         "config1" => true,
68         "config2_to_unset" => nil
69       }
70     }
71   end
72 end