Apply 2 suggestion(s) to 2 file(s)
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_report_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.PleromaReportOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Admin.ReportOperation
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
12 alias Pleroma.Web.ApiSpec.Schemas.Status
13
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
17 end
18
19 def index_operation do
20 %Operation{
21 tags: ["Reports"],
22 summary: "Get a list of your own reports",
23 operationId: "PleromaAPI.ReportController.index",
24 security: [%{"oAuth" => ["read:reports"]}],
25 parameters: [
26 Operation.parameter(
27 :state,
28 :query,
29 ReportOperation.report_state(),
30 "Filter by report state"
31 ),
32 Operation.parameter(
33 :limit,
34 :query,
35 %Schema{type: :integer},
36 "The number of records to retrieve"
37 ),
38 Operation.parameter(
39 :page,
40 :query,
41 %Schema{type: :integer, default: 1},
42 "Page number"
43 ),
44 Operation.parameter(
45 :page_size,
46 :query,
47 %Schema{type: :integer, default: 50},
48 "Number number of log entries per page"
49 )
50 ],
51 responses: %{
52 200 =>
53 Operation.response("Response", "application/json", %Schema{
54 type: :object,
55 properties: %{
56 total: %Schema{type: :integer},
57 reports: %Schema{
58 type: :array,
59 items: report()
60 }
61 }
62 }),
63 404 => Operation.response("Not Found", "application/json", ApiError)
64 }
65 }
66 end
67
68 def show_operation do
69 %Operation{
70 tags: ["Reports"],
71 summary: "Get an individual report",
72 operationId: "PleromaAPI.ReportController.show",
73 parameters: [ReportOperation.id_param()],
74 security: [%{"oAuth" => ["read:reports"]}],
75 responses: %{
76 200 => Operation.response("Report", "application/json", report()),
77 404 => Operation.response("Not Found", "application/json", ApiError)
78 }
79 }
80 end
81
82 # Copied from ReportOperation.report with removing notes
83 defp report do
84 %Schema{
85 type: :object,
86 properties: %{
87 id: FlakeID,
88 state: ReportOperation.report_state(),
89 account: Account,
90 actor: Account,
91 content: %Schema{type: :string},
92 created_at: %Schema{type: :string, format: :"date-time"},
93 statuses: %Schema{type: :array, items: Status}
94 }
95 }
96 end
97 end