2020-04-03 18:52:25 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.Helpers do
|
2020-04-15 12:45:45 +00:00
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
2020-05-13 12:08:07 +00:00
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
2020-04-15 12:45:45 +00:00
|
|
|
|
2020-04-03 18:52:25 +00:00
|
|
|
def request_body(description, schema_ref, opts \\ []) do
|
2020-04-07 10:53:12 +00:00
|
|
|
media_types = ["application/json", "multipart/form-data", "application/x-www-form-urlencoded"]
|
2020-04-03 18:52:25 +00: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 12:45:45 +00: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"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:limit,
|
|
|
|
:query,
|
2020-05-01 18:33:34 +00:00
|
|
|
%Schema{type: :integer, default: 20},
|
|
|
|
"Maximum number of items to return. Will be ignored if it's more than 40"
|
2020-04-15 12:45:45 +00:00
|
|
|
)
|
|
|
|
]
|
|
|
|
end
|
2020-04-28 17:27:54 +00:00
|
|
|
|
2020-05-13 12:08:07 +00:00
|
|
|
def with_relationships_param do
|
|
|
|
Operation.parameter(:with_relationships, :query, BooleanLike, "Include relationships")
|
2020-05-12 17:55:01 +00:00
|
|
|
end
|
|
|
|
|
2020-04-28 17:27:54 +00:00
|
|
|
def empty_object_response do
|
|
|
|
Operation.response("Empty object", "application/json", %Schema{type: :object, example: %{}})
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty_array_response do
|
|
|
|
Operation.response("Empty array", "application/json", %Schema{type: :array, example: []})
|
|
|
|
end
|
2020-04-03 18:52:25 +00:00
|
|
|
end
|