1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.TimelineOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
10 alias Pleroma.Web.ApiSpec.Schemas.Status
11 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
13 import Pleroma.Web.ApiSpec.Helpers
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
23 summary: "Home timeline",
24 description: "View statuses from followed users",
25 security: [%{"oAuth" => ["read:statuses"]}],
31 exclude_visibilities_param(),
32 reply_visibility_param() | pagination_params()
34 operationId: "TimelineController.home",
36 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
41 def direct_operation do
44 summary: "Direct timeline",
46 "View statuses with a “direct” privacy, from your account or in your notifications",
48 parameters: [with_muted_param() | pagination_params()],
49 security: [%{"oAuth" => ["read:statuses"]}],
50 operationId: "TimelineController.direct",
52 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
57 def public_operation do
60 summary: "Public timeline",
61 security: [%{"oAuth" => ["read:statuses"]}],
67 exclude_visibilities_param(),
68 reply_visibility_param() | pagination_params()
70 operationId: "TimelineController.public",
72 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
73 401 => Operation.response("Error", "application/json", ApiError)
78 def hashtag_operation do
81 summary: "Hashtag timeline",
82 description: "View public statuses containing the given hashtag",
83 security: [%{"oAuth" => ["read:statuses"]}],
88 %Schema{type: :string},
89 "Content of a #hashtag, not including # symbol.",
95 %Schema{type: :array, items: %Schema{type: :string}},
96 "Statuses that also includes any of these tags"
101 %Schema{type: :array, items: %Schema{type: :string}},
102 "Statuses that also includes all of these tags"
107 %Schema{type: :array, items: %Schema{type: :string}},
108 "Statuses that do not include these tags"
113 exclude_visibilities_param() | pagination_params()
115 operationId: "TimelineController.hashtag",
117 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
122 def list_operation do
125 summary: "List timeline",
126 description: "View statuses in the given list timeline",
127 security: [%{"oAuth" => ["read:lists"]}],
132 %Schema{type: :string},
133 "Local ID of the list in the database",
137 exclude_visibilities_param() | pagination_params()
139 operationId: "TimelineController.list",
141 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
146 defp array_of_statuses do
148 title: "ArrayOfStatuses",
151 example: [Status.schema().example]
159 %Schema{allOf: [BooleanLike], default: false},
160 "Show only local statuses?"
164 defp instance_param do
168 %Schema{type: :string},
169 "Show only statuses from the given domain"
173 defp with_muted_param do
174 Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
177 defp exclude_visibilities_param do
179 :exclude_visibilities,
181 %Schema{type: :array, items: VisibilityScope},
182 "Exclude the statuses with the given visibilities"
186 defp reply_visibility_param do
190 %Schema{type: :string, enum: ["following", "self"]},
191 "Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you."
195 defp only_media_param do
199 %Schema{allOf: [BooleanLike], default: false},
200 "Show only statuses with media attached?"
208 %Schema{allOf: [BooleanLike], default: false},
209 "Show only remote statuses?"