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 400 => Operation.response("Media", "application/json", ApiError),
28 401 => Operation.response("Media", "application/json", ApiError),
29 422 => Operation.response("Media", "application/json", ApiError)
34 defp create_request do
36 title: "MediaCreateRequest",
37 description: "POST body for creating an attachment",
44 description: "The file to be attached, using multipart form data."
48 description: "A plain-text description of the media, for accessibility purposes."
52 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
58 def update_operation do
60 tags: ["Media attachments"],
61 summary: "Update attachment",
62 description: "Creates an attachment to be used with a new status.",
63 operationId: "MediaController.update",
64 security: [%{"oAuth" => ["write:media"]}],
65 parameters: [id_param()],
66 requestBody: Helpers.request_body("Parameters", update_request()),
68 200 => Operation.response("Media", "application/json", Attachment),
69 400 => Operation.response("Media", "application/json", ApiError),
70 401 => Operation.response("Media", "application/json", ApiError),
71 422 => Operation.response("Media", "application/json", ApiError)
76 defp update_request do
78 title: "MediaUpdateRequest",
79 description: "POST body for updating an attachment",
85 description: "The file to be attached, using multipart form data."
89 description: "A plain-text description of the media, for accessibility purposes."
93 description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
101 tags: ["Media attachments"],
102 summary: "Attachment",
103 operationId: "MediaController.show",
104 parameters: [id_param()],
105 security: [%{"oAuth" => ["read:media"]}],
107 200 => Operation.response("Media", "application/json", Attachment),
108 401 => Operation.response("Media", "application/json", ApiError),
109 403 => Operation.response("Media", "application/json", ApiError),
110 422 => Operation.response("Media", "application/json", ApiError)
115 def create2_operation do
117 tags: ["Media attachments"],
118 summary: "Upload media as attachment (v2)",
119 description: "Creates an attachment to be used with a new status.",
120 operationId: "MediaController.create2",
121 security: [%{"oAuth" => ["write:media"]}],
122 requestBody: Helpers.request_body("Parameters", create_request()),
124 202 => Operation.response("Media", "application/json", Attachment),
125 400 => Operation.response("Media", "application/json", ApiError),
126 422 => Operation.response("Media", "application/json", ApiError),
127 500 => Operation.response("Media", "application/json", ApiError)
133 Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")