1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.Helpers do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
10 def request_body(description, schema_ref, opts \\ []) do
11 media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
15 |> Enum.map(fn type ->
17 %OpenApiSpex.MediaType{
19 example: opts[:example],
20 examples: opts[:examples]
25 %OpenApiSpex.RequestBody{
26 description: description,
28 required: opts[:required] || false
32 def admin_api_params do
33 [Operation.parameter(:admin_token, :query, :string, "Allows authorization via admin token.")]
36 def pagination_params do
38 Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
39 Operation.parameter(:min_id, :query, :string, "Return the oldest items newer than this ID"),
44 "Return the newest items newer than this ID"
49 %Schema{type: :integer, default: 0},
50 "Return items past this number of items"
55 %Schema{type: :integer, default: 20},
56 "Maximum number of items to return. Will be ignored if it's more than 40"
61 def with_relationships_param do
66 "Embed relationships into accounts."
70 def empty_object_response do
71 Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
74 def empty_array_response do
75 Operation.response("Empty array", "application/json", %Schema{
77 items: %Schema{type: :object, example: %{}},
82 def no_content_response do
83 Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})