pleroma/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex
Mark Felder dc912dc590 Pleroma.Web.PleromaAPI.EmojiFileController: dialyzer errors
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:52:no_return
Function update/2 has no local return.
________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:59:call
The function call will not succeed.

Phoenix.Controller.json(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, %{
  binary() =>
    binary()
    | maybe_improper_list(
        binary() | maybe_improper_list(any(), binary() | []) | char(),
        binary() | []
      )
})

breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:62:call
The function call will not succeed.

Plug.Conn.put_status(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, :conflict)

breaks the contract
(t(), status()) :: t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:70:call
The function call will not succeed.

Plug.Conn.put_status(_conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _}, :unprocessable_entity) ::
  :ok
def a() do
  :ok
end

breaks the contract
(t(), status()) :: t()

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:75:call
The function call will not succeed.

Pleroma.Web.PleromaAPI.EmojiFileController.handle_error(
  _conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _},
  _error :: {:error, atom()},
  %{:code => _, :message => <<_::328>>, :pack_name => binary()}
)

will never return since the 1st arguments differ
from the success typing arguments:

(
  %Plug.Conn{
    :adapter => {atom(), _},
    :assigns => %{atom() => _},
    :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :halted => boolean(),
    :host => binary(),
    :method => binary(),
    :owner => pid(),
    :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :path_info => [binary()],
    :path_params => %{
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :port => char(),
    :private => %{atom() => _},
    :query_params => %Plug.Conn.Unfetched{
      :aspect => atom(),
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :query_string => binary(),
    :remote_ip =>
      {byte(), byte(), byte(), byte()}
      | {char(), char(), char(), char(), char(), char(), char(), char()},
    :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
    :req_headers => [{binary(), binary()}],
    :request_path => binary(),
    :resp_body =>
      nil
      | binary()
      | maybe_improper_list(
          binary() | maybe_improper_list(any(), binary() | []) | byte(),
          binary() | []
        ),
    :resp_cookies => %{binary() => map()},
    :resp_headers => [{binary(), binary()}],
    :scheme => :http | :https,
    :script_name => [binary()],
    :secret_key_base => nil | binary(),
    :state =>
      :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
    :status => nil | non_neg_integer()
  },
  {:error, atom()},
  %{:message => <<_::328, _::size(88)>>, :pack_name => binary(), :code => _}
)

________________________________________________________________________________
lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex:75:call
The function call will not succeed.

Pleroma.Web.PleromaAPI.EmojiFileController.handle_error(
  _conn :: %{:body_params => %{:shortcode => _, _ => _}, _ => _},
  _error :: {:error, atom()},
  %{:code => binary(), :message => <<_::328>>, :pack_name => binary()}
)

will never return since the 1st arguments differ
from the success typing arguments:

(
  %Plug.Conn{
    :adapter => {atom(), _},
    :assigns => %{atom() => _},
    :body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :halted => boolean(),
    :host => binary(),
    :method => binary(),
    :owner => pid(),
    :params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
    :path_info => [binary()],
    :path_params => %{
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :port => char(),
    :private => %{atom() => _},
    :query_params => %Plug.Conn.Unfetched{
      :aspect => atom(),
      binary() =>
        binary() | [binary() | [any()] | map()] | %{binary() => binary() | [any()] | map()}
    },
    :query_string => binary(),
    :remote_ip =>
      {byte(), byte(), byte(), byte()}
      | {char(), char(), char(), char(), char(), char(), char(), char()},
    :req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
    :req_headers => [{binary(), binary()}],
    :request_path => binary(),
    :resp_body =>
      nil
      | binary()
      | maybe_improper_list(
          binary() | maybe_improper_list(any(), binary() | []) | byte(),
          binary() | []
        ),
    :resp_cookies => %{binary() => map()},
    :resp_headers => [{binary(), binary()}],
    :scheme => :http | :https,
    :script_name => [binary()],
    :secret_key_base => nil | binary(),
    :state =>
      :chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
    :status => nil | non_neg_integer()
  },
  {:error, atom()},
  %{:message => <<_::328, _::size(88)>>, :pack_name => binary(), :code => _}
)
2024-01-28 15:52:09 -05:00

145 lines
4.8 KiB
Elixir

# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation 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 create_operation do
%Operation{
tags: ["Emoji pack administration"],
summary: "Add new file to the pack",
operationId: "PleromaAPI.EmojiPackController.add_file",
security: [%{"oAuth" => ["admin:write"]}],
requestBody: request_body("Parameters", create_request(), required: true),
parameters: [name_param()],
responses: %{
200 => Operation.response("Files Object", "application/json", files_object()),
422 => Operation.response("Unprocessable Entity", "application/json", ApiError),
404 => Operation.response("Not Found", "application/json", ApiError),
400 => Operation.response("Bad Request", "application/json", ApiError),
409 => Operation.response("Conflict", "application/json", ApiError),
500 => Operation.response("Error", "application/json", ApiError)
}
}
end
defp create_request do
%Schema{
type: :object,
required: ["file"],
properties: %{
"file" => %Schema{
description:
"File needs to be uploaded with the multipart request or link to remote file",
anyOf: [
%Schema{type: :string, format: :binary},
%Schema{type: :string, format: :uri}
]
},
"shortcode" => %Schema{
type: :string,
description:
"Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
},
"filename" => %Schema{
type: :string,
description:
"New emoji file name. If not specified will be taken from original filename."
}
}
}
end
def update_operation do
%Operation{
tags: ["Emoji pack administration"],
summary: "Add new file to the pack",
operationId: "PleromaAPI.EmojiPackController.update_file",
security: [%{"oAuth" => ["admin:write"]}],
requestBody: request_body("Parameters", update_request(), required: true),
parameters: [name_param()],
responses: %{
200 => Operation.response("Files Object", "application/json", files_object()),
404 => Operation.response("Not Found", "application/json", ApiError),
400 => Operation.response("Bad Request", "application/json", ApiError),
409 => Operation.response("Conflict", "application/json", ApiError),
422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
}
}
end
defp update_request do
%Schema{
type: :object,
required: ["shortcode", "new_shortcode", "new_filename"],
properties: %{
"shortcode" => %Schema{
type: :string,
description: "Emoji file shortcode"
},
"new_shortcode" => %Schema{
type: :string,
description: "New emoji file shortcode"
},
"new_filename" => %Schema{
type: :string,
description: "New filename for emoji file"
},
"force" => %Schema{
type: :boolean,
description: "With true value to overwrite existing emoji with new shortcode",
default: false
}
}
}
end
def delete_operation do
%Operation{
tags: ["Emoji pack administration"],
summary: "Delete emoji file from pack",
operationId: "PleromaAPI.EmojiPackController.delete_file",
security: [%{"oAuth" => ["admin:write"]}],
parameters: [
name_param(),
Operation.parameter(:shortcode, :query, :string, "File shortcode",
example: "cofe",
required: true
)
],
responses: %{
200 => Operation.response("Files Object", "application/json", files_object()),
400 => Operation.response("Bad Request", "application/json", ApiError),
404 => Operation.response("Not Found", "application/json", ApiError),
422 => Operation.response("Unprocessable Entity", "application/json", ApiError)
}
}
end
defp name_param do
Operation.parameter(:name, :query, :string, "Pack Name", example: "cofe", required: true)
end
defp files_object do
%Schema{
type: :object,
additionalProperties: %Schema{
type: :string,
description: "Filename of the emoji",
extensions: %{"x-additionalPropertiesName": "Emoji name"}
},
description: "Object with emoji names as keys and filenames as values"
}
end
end