40e81ad55b4568db9db08fe54854275c266dfb21
[akkoma] / lib / pleroma / web / api_spec / operations / frontend_settings_operation.ex
1 defmodule Pleroma.Web.ApiSpec.FrontendSettingsOperation do
2 alias OpenApiSpex.Operation
3 alias OpenApiSpex.Schema
4 import Pleroma.Web.ApiSpec.Helpers
5
6 @spec open_api_operation(atom) :: Operation.t()
7 def open_api_operation(action) do
8 operation = String.to_existing_atom("#{action}_operation")
9 apply(__MODULE__, operation, [])
10 end
11
12 @spec list_profiles_operation() :: Operation.t()
13 def list_profiles_operation() do
14 %Operation{
15 tags: ["Retrieve frontend setting profiles"],
16 summary: "Frontend Settings Profiles",
17 description: "List frontend setting profiles",
18 operationId: "AkkomaAPI.FrontendSettingsController.list_profiles",
19 parameters: [frontend_name_param()],
20 security: [%{"oAuth" => ["read:accounts"]}],
21 responses: %{
22 200 =>
23 Operation.response("Profiles", "application/json", %Schema{
24 type: :array,
25 items: %Schema{
26 type: :object,
27 properties: %{
28 name: %Schema{type: :string},
29 version: %Schema{type: :integer}
30 }
31 }
32 })
33 }
34 }
35 end
36
37 @spec get_profile_operation() :: Operation.t()
38 def get_profile_operation() do
39 %Operation{
40 tags: ["Retrieve frontend setting profile"],
41 summary: "Frontend Settings Profile",
42 description: "Get frontend setting profile",
43 operationId: "AkkomaAPI.FrontendSettingsController.get_profile",
44 security: [%{"oAuth" => ["read:accounts"]}],
45 parameters: [frontend_name_param(), profile_name_param()],
46 responses: %{
47 200 =>
48 Operation.response("Profile", "application/json", %Schema{
49 type: :object,
50 properties: %{
51 "version" => %Schema{type: :integer},
52 "settings" => %Schema{type: :object, additionalProperties: true}
53 }
54 }),
55 404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
56 }
57 }
58 end
59
60 @spec delete_profile_operation() :: Operation.t()
61 def delete_profile_operation() do
62 %Operation{
63 tags: ["Delete frontend setting profile"],
64 summary: "Delete frontend Settings Profile",
65 description: "Delete frontend setting profile",
66 operationId: "AkkomaAPI.FrontendSettingsController.delete_profile",
67 security: [%{"oAuth" => ["write:accounts"]}],
68 parameters: [frontend_name_param(), profile_name_param()],
69 responses: %{
70 200 => Operation.response("Empty", "application/json", %Schema{type: :object}),
71 404 => Operation.response("Not Found", "application/json", %Schema{type: :object})
72 }
73 }
74 end
75
76 @spec update_profile_operation() :: Operation.t()
77 def update_profile_operation() do
78 %Operation{
79 tags: ["Update frontend setting profile"],
80 summary: "Frontend Settings Profile",
81 description: "Update frontend setting profile",
82 operationId: "AkkomaAPI.FrontendSettingsController.update_profile_operation",
83 security: [%{"oAuth" => ["write:accounts"]}],
84 parameters: [frontend_name_param(), profile_name_param()],
85 requestBody: profile_body_param(),
86 responses: %{
87 200 => Operation.response("Settings", "application/json", %Schema{type: :object}),
88 422 => Operation.response("Invalid", "application/json", %Schema{type: :object})
89 }
90 }
91 end
92
93 def frontend_name_param do
94 Operation.parameter(:frontend_name, :path, :string, "Frontend name",
95 example: "pleroma-fe",
96 required: true
97 )
98 end
99
100 def profile_name_param do
101 Operation.parameter(:profile_name, :path, :string, "Profile name",
102 example: "mobile",
103 required: true
104 )
105 end
106
107 def profile_body_param do
108 request_body(
109 "Settings",
110 %Schema{
111 title: "Frontend Setting Profile",
112 type: :object,
113 required: [:version, :settings],
114 properties: %{
115 version: %Schema{
116 type: :integer,
117 description: "Version of the profile, must increment by 1 each time",
118 example: 1
119 },
120 settings: %Schema{
121 type: :object,
122 description: "Settings of the profile",
123 example: %{
124 theme: "dark",
125 locale: "en"
126 }
127 }
128 }
129 },
130 required: true
131 )
132 end
133 end