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
|
|
|
|
def request_body(description, schema_ref, opts \\ []) do
|
2020-04-14 21:49:21 +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
|
|
|
|
end
|