X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Fapi_spec%2Foperations%2Fmedia_operation.ex;h=451b6510f236cbc8b207e80bc23f95914933c88b;hb=a079ec3a3cdfd42d2cbd51c7698c2c87828e5778;hp=0fe686efa7f4a6ced8f4f269d5bae872bb9b3564;hpb=099e314a1bb823a83d9c1af0cca2363487a07899;p=akkoma
diff --git a/lib/pleroma/web/api_spec/operations/media_operation.ex b/lib/pleroma/web/api_spec/operations/media_operation.ex
index 0fe686efa..451b6510f 100644
--- a/lib/pleroma/web/api_spec/operations/media_operation.ex
+++ b/lib/pleroma/web/api_spec/operations/media_operation.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.MediaOperation do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Helpers
alias Pleroma.Web.ApiSpec.Schemas.ApiError
+ alias Pleroma.Web.ApiSpec.Schemas.Attachment
def open_api_operation(action) do
operation = String.to_existing_atom("#{action}_operation")
@@ -15,31 +16,32 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
def create_operation do
%Operation{
- tags: ["media"],
+ tags: ["Media attachments"],
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: %{
- 200 =>
- Operation.response("Media", "application/json", Pleroma.Web.ApiSpec.Schemas.Attachment),
+ 200 => Operation.response("Media", "application/json", Attachment),
+ 400 => Operation.response("Media", "application/json", ApiError),
401 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError)
}
}
end
- defp create_request() do
+ defp create_request do
%Schema{
title: "MediaCreateRequest",
description: "POST body for creating an attachment",
type: :object,
+ required: [:file],
properties: %{
file: %Schema{
- type: :binary,
- description: "The file to be attached, using multipart form data.",
- required: true
+ type: :string,
+ format: :binary,
+ description: "The file to be attached, using multipart form data."
},
description: %Schema{
type: :string,
@@ -55,34 +57,31 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
def update_operation do
%Operation{
- tags: ["media"],
- summary: "Upload media as attachment",
+ tags: ["Media attachments"],
+ summary: "Update attachment",
description: "Creates an attachment to be used with a new status.",
operationId: "MediaController.update",
security: [%{"oAuth" => ["write:media"]}],
+ parameters: [id_param()],
requestBody: Helpers.request_body("Parameters", update_request()),
responses: %{
- 200 =>
- Operation.response("Media", "application/json", Pleroma.Web.ApiSpec.Schemas.Attachment),
+ 200 => Operation.response("Media", "application/json", Attachment),
+ 400 => Operation.response("Media", "application/json", ApiError),
401 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError)
}
}
end
- defp update_request() do
+ defp update_request do
%Schema{
- title: "MediaCreateRequest",
- description: "POST body for creating an attachment",
+ title: "MediaUpdateRequest",
+ description: "POST body for updating an attachment",
type: :object,
properties: %{
- id: %Schema{
- type: :string,
- description: "The id of the Attachment entity to be updated",
- required: true
- },
file: %Schema{
- type: :binary,
+ type: :string,
+ format: :binary,
description: "The file to be attached, using multipart form data."
},
description: %Schema{
@@ -99,14 +98,15 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
def show_operation do
%Operation{
- tags: ["media"],
- summary: "Show Uploaded media attachment",
+ tags: ["Media attachments"],
+ summary: "Attachment",
operationId: "MediaController.show",
+ parameters: [id_param()],
security: [%{"oAuth" => ["read:media"]}],
responses: %{
- 200 =>
- Operation.response("Media", "application/json", Pleroma.Web.ApiSpec.Schemas.Attachment),
+ 200 => Operation.response("Media", "application/json", Attachment),
401 => Operation.response("Media", "application/json", ApiError),
+ 403 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError)
}
}
@@ -114,18 +114,22 @@ defmodule Pleroma.Web.ApiSpec.MediaOperation do
def create2_operation do
%Operation{
- tags: ["media"],
- summary: "Upload media as attachment",
+ tags: ["Media attachments"],
+ summary: "Upload media as attachment (v2)",
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: %{
- 202 =>
- Operation.response("Media", "application/json", Pleroma.Web.ApiSpec.Schemas.Attachment),
+ 202 => Operation.response("Media", "application/json", Attachment),
+ 400 => Operation.response("Media", "application/json", ApiError),
422 => Operation.response("Media", "application/json", ApiError),
500 => Operation.response("Media", "application/json", ApiError)
}
}
end
+
+ defp id_param do
+ Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")
+ end
end