[#2497] Specified SHELL in .gitlab-ci.yml as required for `exexec`.
[akkoma] / lib / pleroma / web / api_spec / helpers.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.Helpers do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
9
10 def request_body(description, schema_ref, opts \\ []) do
11 media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
12
13 content =
14 media_types
15 |> Enum.map(fn type ->
16 {type,
17 %OpenApiSpex.MediaType{
18 schema: schema_ref,
19 example: opts[:example],
20 examples: opts[:examples]
21 }}
22 end)
23 |> Enum.into(%{})
24
25 %OpenApiSpex.RequestBody{
26 description: description,
27 content: content,
28 required: opts[:required] || false
29 }
30 end
31
32 def pagination_params do
33 [
34 Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
35 Operation.parameter(:min_id, :query, :string, "Return the oldest items newer than this ID"),
36 Operation.parameter(
37 :since_id,
38 :query,
39 :string,
40 "Return the newest items newer than this ID"
41 ),
42 Operation.parameter(
43 :limit,
44 :query,
45 %Schema{type: :integer, default: 20},
46 "Maximum number of items to return. Will be ignored if it's more than 40"
47 )
48 ]
49 end
50
51 def with_relationships_param do
52 Operation.parameter(
53 :with_relationships,
54 :query,
55 BooleanLike,
56 "Embed relationships into accounts."
57 )
58 end
59
60 def empty_object_response do
61 Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
62 end
63
64 def empty_array_response do
65 Operation.response("Empty array", "application/json", %Schema{type: :array, example: []})
66 end
67
68 def no_content_response do
69 Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})
70 end
71 end