1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.MediaOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Helpers
9 alias Pleroma.Web.ApiSpec.Schemas.ApiError
10 alias Pleroma.Web.ApiSpec.Schemas.Attachment
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
17 def create_operation do
19 tags: ["Media attachments"],
20 summary: "Upload media as attachment",
21 description: "Creates an attachment to be used with a new status.",
22 operationId: "MediaController.create",
23 security: [%{"oAuth" => ["write:media"]}],
24 requestBody: Helpers.request_body("Parameters", create_request()),
26 200 => Operation.response("Media", "application/json", Attachment),
27 401 => Operation.response("Media", "application/json", ApiError),
28 422 => Operation.response("Media", "application/json", ApiError)
33 defp create_request do
35 title: "MediaCreateRequest",
36 description: "POST body for creating an attachment",
43 description: "The file to be attached, using multipart form data."
47 description: "A plain-text description of the media, for accessibility purposes."
51 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
57 def update_operation do
59 tags: ["Media attachments"],
60 summary: "Update attachment",
61 description: "Creates an attachment to be used with a new status.",
62 operationId: "MediaController.update",
63 security: [%{"oAuth" => ["write:media"]}],
64 parameters: [id_param()],
65 requestBody: Helpers.request_body("Parameters", update_request()),
67 200 => Operation.response("Media", "application/json", Attachment),
68 400 => Operation.response("Media", "application/json", ApiError),
69 401 => Operation.response("Media", "application/json", ApiError),
70 422 => Operation.response("Media", "application/json", ApiError)
75 defp update_request do
77 title: "MediaUpdateRequest",
78 description: "POST body for updating an attachment",
84 description: "The file to be attached, using multipart form data."
88 description: "A plain-text description of the media, for accessibility purposes."
92 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
100 tags: ["Media attachments"],
101 summary: "Attachment",
102 operationId: "MediaController.show",
103 parameters: [id_param()],
104 security: [%{"oAuth" => ["read:media"]}],
106 200 => Operation.response("Media", "application/json", Attachment),
107 401 => Operation.response("Media", "application/json", ApiError),
108 422 => Operation.response("Media", "application/json", ApiError)
113 def create2_operation do
115 tags: ["Media attachments"],
116 summary: "Upload media as attachment (v2)",
117 description: "Creates an attachment to be used with a new status.",
118 operationId: "MediaController.create2",
119 security: [%{"oAuth" => ["write:media"]}],
120 requestBody: Helpers.request_body("Parameters", create_request()),
122 202 => Operation.response("Media", "application/json", Attachment),
123 422 => Operation.response("Media", "application/json", ApiError),
124 500 => Operation.response("Media", "application/json", ApiError)
130 Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")