Merge branch '2317-old-reset-tokens' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_mascot_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaMascotOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9
10 import Pleroma.Web.ApiSpec.Helpers
11
12 def open_api_operation(action) do
13 operation = String.to_existing_atom("#{action}_operation")
14 apply(__MODULE__, operation, [])
15 end
16
17 def show_operation do
18 %Operation{
19 tags: ["Mascot"],
20 summary: "Gets user mascot image",
21 security: [%{"oAuth" => ["read:accounts"]}],
22 operationId: "PleromaAPI.MascotController.show",
23 responses: %{
24 200 => Operation.response("Mascot", "application/json", mascot())
25 }
26 }
27 end
28
29 def update_operation do
30 %Operation{
31 tags: ["Mascot"],
32 summary: "Set/clear user avatar image",
33 description:
34 "Behaves exactly the same as `POST /api/v1/upload`. Can only accept images - any attempt to upload non-image files will be met with `HTTP 415 Unsupported Media Type`.",
35 operationId: "PleromaAPI.MascotController.update",
36 requestBody:
37 request_body(
38 "Parameters",
39 %Schema{
40 type: :object,
41 properties: %{
42 file: %Schema{type: :string, format: :binary}
43 }
44 },
45 required: true
46 ),
47 security: [%{"oAuth" => ["write:accounts"]}],
48 responses: %{
49 200 => Operation.response("Mascot", "application/json", mascot()),
50 415 => Operation.response("Unsupported Media Type", "application/json", ApiError)
51 }
52 }
53 end
54
55 defp mascot do
56 %Schema{
57 type: :object,
58 properties: %{
59 id: %Schema{type: :string},
60 url: %Schema{type: :string, format: :uri},
61 type: %Schema{type: :string},
62 pleroma: %Schema{
63 type: :object,
64 properties: %{
65 mime_type: %Schema{type: :string}
66 }
67 }
68 },
69 example: %{
70 "id" => "abcdefg",
71 "url" => "https://pleroma.example.org/media/abcdefg.png",
72 "type" => "image",
73 "pleroma" => %{
74 "mime_type" => "image/png"
75 }
76 }
77 }
78 end
79 end