MastoAPI: fix & test giving MRF reject reasons
[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 :offset,
44 :query,
45 %Schema{type: :integer, default: 0},
46 "Return items past this number of items"
47 ),
48 Operation.parameter(
49 :limit,
50 :query,
51 %Schema{type: :integer, default: 20},
52 "Maximum number of items to return. Will be ignored if it's more than 40"
53 )
54 ]
55 end
56
57 def with_relationships_param do
58 Operation.parameter(
59 :with_relationships,
60 :query,
61 BooleanLike,
62 "Embed relationships into accounts."
63 )
64 end
65
66 def empty_object_response do
67 Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
68 end
69
70 def empty_array_response do
71 Operation.response("Empty array", "application/json", %Schema{type: :array, example: []})
72 end
73
74 def no_content_response do
75 Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})
76 end
77 end