OpenAPI: PleromaAPI UserImport Controller
[akkoma] / lib / pleroma / web / api_spec / operations / user_import_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.UserImportOperation 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 @spec open_api_operation(atom) :: Operation.t()
13 def open_api_operation(action) do
14 operation = String.to_existing_atom("#{action}_operation")
15 apply(__MODULE__, operation, [])
16 end
17
18 def follow_operation do
19 %Operation{
20 tags: ["Data import"],
21 summary: "Import follows",
22 operationId: "UserImportController.follow",
23 requestBody: request_body("Parameters", import_request(), required: true),
24 responses: %{
25 200 => ok_response(),
26 403 => Operation.response("Error", "application/json", ApiError),
27 500 => Operation.response("Error", "application/json", ApiError)
28 },
29 security: [%{"oAuth" => ["write:follow"]}]
30 }
31 end
32
33 def blocks_operation do
34 %Operation{
35 tags: ["Data import"],
36 summary: "Import blocks",
37 operationId: "UserImportController.blocks",
38 requestBody: request_body("Parameters", import_request(), required: true),
39 responses: %{
40 200 => ok_response(),
41 500 => Operation.response("Error", "application/json", ApiError)
42 },
43 security: [%{"oAuth" => ["write:blocks"]}]
44 }
45 end
46
47 def mutes_operation do
48 %Operation{
49 tags: ["Data import"],
50 summary: "Import mutes",
51 operationId: "UserImportController.mutes",
52 requestBody: request_body("Parameters", import_request(), required: true),
53 responses: %{
54 200 => ok_response(),
55 500 => Operation.response("Error", "application/json", ApiError)
56 },
57 security: [%{"oAuth" => ["write:mutes"]}]
58 }
59 end
60
61 defp import_request do
62 %Schema{
63 type: :object,
64 required: [:list],
65 properties: %{
66 list: %Schema{
67 description:
68 "STRING or FILE containing a whitespace-separated list of accounts to import.",
69 anyOf: [
70 %Schema{type: :string, format: :binary},
71 %Schema{type: :string}
72 ]
73 }
74 }
75 }
76 end
77
78 defp ok_response do
79 Operation.response("Ok", "application/json", %Schema{type: :string, example: "ok"})
80 end
81 end