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 pagination_params do
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"),
40 "Return the newest items newer than this ID"
45 %Schema{type: :integer, default: 0},
46 "Return items past this number of items"
51 %Schema{type: :integer, default: 20},
52 "Maximum number of items to return. Will be ignored if it's more than 40"
57 def with_relationships_param do
62 "Embed relationships into accounts."
66 def empty_object_response do
67 Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
70 def empty_array_response do
71 Operation.response("Empty array", "application/json", %Schema{type: :array, example: []})
74 def no_content_response do
75 Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})