akkoma/lib/pleroma/web/api_spec/operations/media_operation.ex

136 lines
4.6 KiB
Elixir
Raw Normal View History

2020-05-14 02:50:12 -06:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-05-14 02:50:12 -06:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.MediaOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Helpers
alias Pleroma.Web.ApiSpec.Schemas.ApiError
2020-05-14 06:18:30 -06:00
alias Pleroma.Web.ApiSpec.Schemas.Attachment
2020-05-14 02:50:12 -06:00
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
apply(__MODULE__, operation, [])
end
def create_operation do
%Operation{
tags: ["Media attachments"],
2020-05-14 02:50:12 -06:00
summary: "Upload media as attachment",
description: "Creates an attachment to be used with a new status.",
operationId: "MediaController.create",
security: [%{"oAuth" => ["write:media"]}],
requestBody: Helpers.request_body("Parameters", create_request()),
responses: %{
2020-05-14 06:18:30 -06:00
200 => Operation.response("Media", "application/json", Attachment),
400 => Operation.response("Media", "application/json", ApiError),
2020-05-14 02:50:12 -06:00
401 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError)
}
}
end
2020-05-14 06:18:30 -06:00
defp create_request do
2020-05-14 02:50:12 -06:00
%Schema{
title: "MediaCreateRequest",
description: "POST body for creating an attachment",
type: :object,
2020-05-14 06:18:30 -06:00
required: [:file],
2020-05-14 02:50:12 -06:00
properties: %{
file: %Schema{
2020-05-14 06:18:30 -06:00
type: :string,
format: :binary,
description: "The file to be attached, using multipart form data."
2020-05-14 02:50:12 -06:00
},
description: %Schema{
type: :string,
description: "A plain-text description of the media, for accessibility purposes."
},
focus: %Schema{
type: :string,
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
}
}
}
end
def update_operation do
%Operation{
tags: ["Media attachments"],
summary: "Update attachment",
2020-05-14 02:50:12 -06:00
description: "Creates an attachment to be used with a new status.",
operationId: "MediaController.update",
security: [%{"oAuth" => ["write:media"]}],
2020-05-14 06:18:30 -06:00
parameters: [id_param()],
2020-05-14 02:50:12 -06:00
requestBody: Helpers.request_body("Parameters", update_request()),
responses: %{
2020-05-14 06:18:30 -06:00
200 => Operation.response("Media", "application/json", Attachment),
400 => Operation.response("Media", "application/json", ApiError),
2020-05-14 02:50:12 -06:00
401 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError)
}
}
end
2020-05-14 06:18:30 -06:00
defp update_request do
2020-05-14 02:50:12 -06:00
%Schema{
2020-05-14 06:18:30 -06:00
title: "MediaUpdateRequest",
description: "POST body for updating an attachment",
2020-05-14 02:50:12 -06:00
type: :object,
properties: %{
file: %Schema{
2020-05-14 06:18:30 -06:00
type: :string,
format: :binary,
2020-05-14 02:50:12 -06:00
description: "The file to be attached, using multipart form data."
},
description: %Schema{
type: :string,
description: "A plain-text description of the media, for accessibility purposes."
},
focus: %Schema{
type: :string,
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
}
}
}
end
def show_operation do
%Operation{
tags: ["Media attachments"],
summary: "Attachment",
2020-05-14 02:50:12 -06:00
operationId: "MediaController.show",
2020-05-14 06:18:30 -06:00
parameters: [id_param()],
2020-05-14 02:50:12 -06:00
security: [%{"oAuth" => ["read:media"]}],
responses: %{
2020-05-14 06:18:30 -06:00
200 => Operation.response("Media", "application/json", Attachment),
2020-05-14 02:50:12 -06:00
401 => Operation.response("Media", "application/json", ApiError),
2021-02-16 15:37:16 -07:00
403 => Operation.response("Media", "application/json", ApiError),
2020-05-14 02:50:12 -06:00
422 => Operation.response("Media", "application/json", ApiError)
}
}
end
def create2_operation do
%Operation{
tags: ["Media attachments"],
summary: "Upload media as attachment (v2)",
2020-05-14 02:50:12 -06:00
description: "Creates an attachment to be used with a new status.",
operationId: "MediaController.create2",
security: [%{"oAuth" => ["write:media"]}],
requestBody: Helpers.request_body("Parameters", create_request()),
responses: %{
2020-05-14 06:18:30 -06:00
202 => Operation.response("Media", "application/json", Attachment),
400 => Operation.response("Media", "application/json", ApiError),
2020-05-14 02:50:12 -06:00
422 => Operation.response("Media", "application/json", ApiError),
500 => Operation.response("Media", "application/json", ApiError)
}
}
end
2020-05-14 06:18:30 -06:00
defp id_param do
Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")
end
2020-05-14 02:50:12 -06:00
end