2020-04-03 12:52:25 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 04:11:47 -07:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2020-04-03 12:52:25 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Helpers do
|
2020-04-15 06:45:45 -06:00
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
2020-05-13 06:08:07 -06:00
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
2020-04-15 06:45:45 -06:00
|
|
|
|
2020-04-03 12:52:25 -06:00
|
|
|
def request_body(description, schema_ref, opts \\ []) do
|
2020-04-07 04:53:12 -06:00
|
|
|
media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
|
2020-04-03 12:52:25 -06:00
|
|
|
|
|
|
|
content =
|
|
|
|
media_types
|
|
|
|
|> Enum.map(fn type ->
|
|
|
|
{type,
|
|
|
|
%OpenApiSpex.MediaType{
|
|
|
|
schema: schema_ref,
|
|
|
|
example: opts[:example],
|
|
|
|
examples: opts[:examples]
|
|
|
|
}}
|
|
|
|
end)
|
|
|
|
|> Enum.into(%{})
|
|
|
|
|
|
|
|
%OpenApiSpex.RequestBody{
|
|
|
|
description: description,
|
|
|
|
content: content,
|
|
|
|
required: opts[:required] || false
|
|
|
|
}
|
|
|
|
end
|
2020-04-15 06:45:45 -06:00
|
|
|
|
2020-07-14 10:31:05 -06:00
|
|
|
def admin_api_params do
|
|
|
|
[Operation.parameter(:admin_token, :query, :string, "Allows authorization via admin token.")]
|
|
|
|
end
|
|
|
|
|
2020-04-15 06:45:45 -06:00
|
|
|
def pagination_params do
|
|
|
|
[
|
|
|
|
Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
|
|
|
|
Operation.parameter(:min_id, :query, :string, "Return the oldest items newer than this ID"),
|
|
|
|
Operation.parameter(
|
|
|
|
:since_id,
|
|
|
|
:query,
|
|
|
|
:string,
|
|
|
|
"Return the newest items newer than this ID"
|
|
|
|
),
|
2020-06-19 07:14:06 -06:00
|
|
|
Operation.parameter(
|
|
|
|
:offset,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :integer, default: 0},
|
|
|
|
"Return items past this number of items"
|
|
|
|
),
|
2020-04-15 06:45:45 -06:00
|
|
|
Operation.parameter(
|
|
|
|
:limit,
|
|
|
|
:query,
|
2020-05-01 12:33:34 -06:00
|
|
|
%Schema{type: :integer, default: 20},
|
|
|
|
"Maximum number of items to return. Will be ignored if it's more than 40"
|
2020-04-15 06:45:45 -06:00
|
|
|
)
|
|
|
|
]
|
|
|
|
end
|
2020-04-28 11:27:54 -06:00
|
|
|
|
2020-05-13 06:08:07 -06:00
|
|
|
def with_relationships_param do
|
2020-05-13 09:56:45 -06:00
|
|
|
Operation.parameter(
|
|
|
|
:with_relationships,
|
|
|
|
:query,
|
|
|
|
BooleanLike,
|
2021-02-03 08:10:43 -07:00
|
|
|
"Embed relationships into accounts. **If this parameter is not set account's `pleroma.relationship` is going to be `null`.**"
|
2020-05-13 09:56:45 -06:00
|
|
|
)
|
2020-05-12 11:55:01 -06:00
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:54 -06:00
|
|
|
def empty_object_response do
|
|
|
|
Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty_array_response do
|
2020-09-18 15:50:00 -06:00
|
|
|
Operation.response("Empty array", "application/json", %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: %Schema{type: :object, example: %{}},
|
|
|
|
example: []
|
|
|
|
})
|
2020-04-28 11:27:54 -06:00
|
|
|
end
|
2020-05-13 09:06:25 -06:00
|
|
|
|
|
|
|
def no_content_response do
|
|
|
|
Operation.response("No Content", "application/json", %Schema{type: :string, example: ""})
|
|
|
|
end
|
2020-04-03 12:52:25 -06:00
|
|
|
end
|