logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pleroma_mascot_operation.ex (2277B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ApiSpec.PleromaMascotOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. import Pleroma.Web.ApiSpec.Helpers
  9. def open_api_operation(action) do
  10. operation = String.to_existing_atom("#{action}_operation")
  11. apply(__MODULE__, operation, [])
  12. end
  13. def show_operation do
  14. %Operation{
  15. tags: ["Mascot"],
  16. summary: "Retrieve mascot",
  17. security: [%{"oAuth" => ["read:accounts"]}],
  18. operationId: "PleromaAPI.MascotController.show",
  19. responses: %{
  20. 200 => Operation.response("Mascot", "application/json", mascot())
  21. }
  22. }
  23. end
  24. def update_operation do
  25. %Operation{
  26. tags: ["Mascot"],
  27. summary: "Set or clear mascot",
  28. description:
  29. "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`.",
  30. operationId: "PleromaAPI.MascotController.update",
  31. requestBody:
  32. request_body(
  33. "Parameters",
  34. %Schema{
  35. type: :object,
  36. properties: %{
  37. file: %Schema{type: :string, format: :binary}
  38. }
  39. },
  40. required: true
  41. ),
  42. security: [%{"oAuth" => ["write:accounts"]}],
  43. responses: %{
  44. 200 => Operation.response("Mascot", "application/json", mascot()),
  45. 415 => Operation.response("Unsupported Media Type", "application/json", ApiError)
  46. }
  47. }
  48. end
  49. defp mascot do
  50. %Schema{
  51. type: :object,
  52. properties: %{
  53. id: %Schema{type: :string},
  54. url: %Schema{type: :string, format: :uri},
  55. type: %Schema{type: :string},
  56. pleroma: %Schema{
  57. type: :object,
  58. properties: %{
  59. mime_type: %Schema{type: :string}
  60. }
  61. }
  62. },
  63. example: %{
  64. "id" => "abcdefg",
  65. "url" => "https://pleroma.example.org/media/abcdefg.png",
  66. "type" => "image",
  67. "pleroma" => %{
  68. "mime_type" => "image/png"
  69. }
  70. }
  71. }
  72. end
  73. end