spc-pleroma/lib/pleroma/web/api_spec/operations/pleroma_mascot_operation.ex

80 lines
2.2 KiB
Elixir
Raw Normal View History

2020-05-18 18:00:32 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-05-18 18:00:32 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.PleromaMascotOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.ApiError
import Pleroma.Web.ApiSpec.Helpers
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
apply(__MODULE__, operation, [])
end
def show_operation do
%Operation{
tags: ["Mascot"],
summary: "Retrieve mascot",
2020-05-18 18:00:32 +00:00
security: [%{"oAuth" => ["read:accounts"]}],
operationId: "PleromaAPI.MascotController.show",
responses: %{
200 => Operation.response("Mascot", "application/json", mascot())
}
}
end
def update_operation do
%Operation{
tags: ["Mascot"],
summary: "Set or clear mascot",
2020-05-18 18:00:32 +00:00
description:
"Behaves exactly the same as `POST /api/v1/upload`. Can only accept images - any attempt to upload non-image files will be met with `HTTP 415 Unsupported Media Type`.",
operationId: "PleromaAPI.MascotController.update",
requestBody:
request_body(
"Parameters",
%Schema{
type: :object,
properties: %{
Pleroma.Web.PleromaAPI.MascotController: dialyzer errors lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:25:no_return Function update/2 has no local return. lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:27:call The function call will not succeed. Pleroma.Web.ActivityPub.ActivityPub.upload(_file :: atom() | %{:content_type => _, _ => _}, [{:actor, <<_::56, _::size(8)>>}, ...]) :: :ok def a() do :ok end will never return since the 2nd arguments differ from the success typing arguments: (any(), [ {:activity_type | :description | :filters | :size_limit | :type | :uploader, atom() | binary() | [atom()] | non_neg_integer()} ]) lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:31:call The function call will not succeed. Phoenix.Controller.json( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:file => _, _ => _}, _ => _ }, _attachment :: any() ) breaks the contract (Plug.Conn.t(), term()) :: Plug.Conn.t() lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:34:call The function call will not succeed. Plug.Conn.put_status( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:file => _, _ => _}, _ => _ }, :unsupported_media_type ) breaks the contract (t(), status()) :: t() lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:34:call The function call will not succeed. Plug.Conn.put_status( _conn :: %{ :assigns => %{:user => _, _ => _}, :body_params => %{:file => _, _ => _}, _ => _ }, :unsupported_media_type ) breaks the contract (t(), status()) :: t() lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:38:unused_fun Function render_attachment/1 will never be called.
2024-01-28 17:29:12 +00:00
"file" => %Schema{type: :string, format: :binary}
2020-05-18 18:00:32 +00:00
}
},
required: true
),
security: [%{"oAuth" => ["write:accounts"]}],
responses: %{
200 => Operation.response("Mascot", "application/json", mascot()),
415 => Operation.response("Unsupported Media Type", "application/json", ApiError)
}
}
end
defp mascot do
%Schema{
type: :object,
properties: %{
id: %Schema{type: :string},
url: %Schema{type: :string, format: :uri},
type: %Schema{type: :string},
pleroma: %Schema{
type: :object,
properties: %{
mime_type: %Schema{type: :string}
}
}
},
example: %{
"id" => "abcdefg",
"url" => "https://pleroma.example.org/media/abcdefg.png",
"type" => "image",
"pleroma" => %{
"mime_type" => "image/png"
}
}
}
end
end